/////////////////////////////////////////////////////////////////////////////////////////////////// // File fem_base_obj.h #pragma once #include namespace fem { class FEM_DLL_DECL CTCBaseObj : public CObject, public boost::enable_shared_from_this { //the serialize function is simple, concise, and guarantees that class members are saved and loaded in the same sequence ... friend class boost::serialization::access; //template void serialize(Archive & ar, const unsigned int /*version*/) //{ // ar & BOOST_SERIALIZATION_NVP(m_strProps); //} //however, there are cases where the load and save operations are not as similar as the examples used here. //For example, this could occur with a class that has evolved through multiple versions ... //so split save/load into two different functions ... template void save(Archive & ar, const unsigned int /*version*/) const { static std::string sn; static std::string sc; sn = Name (); ar & boost::serialization::make_nvp("name" , sn); sc = Comment(); ar & boost::serialization::make_nvp("comment", sc); } template void load(Archive & ar, const unsigned int /*version*/) { static std::string sn; static std::string sc; ar & boost::serialization::make_nvp("name" , sn); m_strProps.set_without_undo(0, sc.c_str()); ar & boost::serialization::make_nvp("comment", sc); m_strProps.set_without_undo(1, sn.c_str()); } //The macro BOOST_SERIALIZATION_SPLIT_MEMBER() generates code which invokes the save or load //depending on whether the archive is used for saving or loading. BOOST_SERIALIZATION_SPLIT_MEMBER(); public: DECLARE_SERIAL(CTCBaseObj) CTCBaseObj() : CObject() { m_strProps.set_without_undo(0, _T("")); m_strProps.set_without_undo(1, _T("")); } CTCBaseObj(const CString& strName, const CString& strComment) : CObject() { m_strProps.set_without_undo(0, strName); m_strProps.set_without_undo(1, strComment); } virtual ~CTCBaseObj() { } virtual void Serialize(CArchive& ar); virtual void SerializeDB(bool bWriting, CTOLRecordset& rs); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif const CString& Name () const { return m_strProps.get(0); } const CString& Comment () const { return m_strProps.get(1); } void SetName (const CString& s, undo::eCmdType ctCmd = undo::cmdDo) { m_strProps.set(0, s, ctCmd); } void SetComment(const CString& s, undo::eCmdType ctCmd = undo::cmdDo) { m_strProps.set(1, s, ctCmd); } private: fem::CPropRepository m_strProps; static const long m_nVersion; }; } // namespace fem BOOST_CLASS_VERSION(fem::CTCBaseObj, 1);