at forum wrote:
On 10/5/07, Robert Ramey 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
&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 & 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 cmd(&pos,&gps_position::SetMinutes,25);
CASetMemberCommand
cmd4(&pos,&gps_position::SetDegrees,25);
cmd.Execute();
SaveCommand(cmd,"D:/test.xml");
Save("D:/Test2.xml", cmd);
CASetMemberCommand 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
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 cmd2;
{
std::ifstream ifs("D:/test.xml");
assert(ifs.good());
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(cmd2);
}
return 0;
}