|
Boost Users : |
From: at forum (at1forum_at_[hidden])
Date: 2007-10-05 04:33:22
Hi to all
I am new to the boost library, I downloaded it and I am doing some tests.
I was using MFC serialization.
I want to do something like this :
template<class _CReceiver, class _CMemberType>
class CASetMemberCommand
{
friend class boost::serialization::access;
public:
typedef void (_CReceiver::* Action)(_CMemberType) ;
protected:
_CReceiver *m_pReceiver;
_CMemberType m_Property;
Action m_fnAction;
public:
CASetMemberCommand()
{
m_pReceiver = NULL;
}
CASetMemberCommand(_CReceiver *pReceiver,
Action fnAction,
_CMemberType memberProperty)
{
m_pReceiver = pReceiver;
m_fnAction = fnAction;
m_Property = memberProperty;
}
~CASetMemberCommand()
{
}
virtual void Execute()
{
if(m_pReceiver)
(m_pReceiver->*m_fnAction)(m_Property);
}
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */){
ar & BOOST_SERIALIZATION_NVP(m_pReceiver)
//& BOOST_SERIALIZATION_NVP(m_fnAction)
& BOOST_SERIALIZATION_NVP(m_Property);
}
void Save(const char * filename)
{
std::ofstream ofs(filename);
assert(ofs.good());
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(this);
}
void Load( const char * filename)
{
std::ifstream ifs(filename);
assert(ifs.good());
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(*this);
}
};
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");
cmd.Save("D:/Test2.xml");
CASetMemberCommand<gps_position,int> cmd2;
cmd2.Load("D:/Test2.xml");
return 0;
}
the problem is that BOOST_SERIALIZATION_NVP(m_fnAction) is not working
(compile errors);
Is there any way to save a methode of w class, so it can be loaded and
used later?
Thank you
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net