
at forum wrote:
On 10/5/07, Robert Ramey <ramey@rrsd.com> wrote:
a) I don't see a serialize function for Action. Until this exists, it's not a serializble type. Hence it will not compile.
Ok thank you.
b) The following is not symetrical and this is almost always a programmer error
oa << BOOST_SERIALIZATION_NVP(this); ... ia >> BOOST_SERIALIZATION_NVP(*this);
I know that, but if I put oa << BOOST_SERIALIZATION_NVP(*this); I get a run time error, and when I put ia >> BOOST_SERIALIZATION_NVP(this) I get a run time error.
If I do my save and load fucntion output my class, its ok and I can have symetrical Serialize.
any Idea?
BOOST_SERIALIZATION_NVP(this) is not suitable for "this" I believe you want something like: void Save(const char * filename, const CASetMemberCommand<gps_position,int> &c) { std::ofstream ofs(filename); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(c); } void Load( const char * filename, CASetMemberCommand<gps_position,int> & c) { std::ifstream ifs(filename); assert(ifs.good()); boost::archive::xml_iarchive ia(ifs); ia >> BOOST_SERIALIZATION_NVP(c); } int main(int argc, char *argv[]) { gps_position pos(32,52,25.0f); CASetMemberCommand<gps_position,int> cmd(&pos,&gps_position::SetMinutes,25); CASetMemberCommand<gps_position,int> cmd4(&pos,&gps_position::SetDegrees,25); cmd.Execute(); SaveCommand(cmd,"D:/test.xml"); Save("D:/Test2.xml", cmd); CASetMemberCommand<gps_position,int> cmd2; Load("D:/Test2.xml", cmd); return 0; } or maybe something simpler like: int main(int argc, char *argv[]) { gps_position pos(32,52,25.0f); const CASetMemberCommand<gps_position,int> cmd(&pos,&gps_position::SetMinutes,25); cmd.Execute(); { std::ofstream ofs("D:/test.xml");); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(cmd); } CASetMemberCommand<gps_position,int> cmd2; { std::ifstream ifs("D:/test.xml"); assert(ifs.good()); boost::archive::xml_iarchive ia(ifs); ia >> BOOST_SERIALIZATION_NVP(cmd2); } return 0; }