boost::serialization - track_never, load and save in cpp file?
Hi.
To support the serialization of a class I don't want to change anything,
I have added free save and load function. (See the test code below.)
It compiles and appears to work.
I have the following questions:
* Is it OK to put the save & load definitions in a separate
implementation file?
* Is it OK to specify track_never in a cpp file? Will this cause
problems if someone else tries to serialize a map
Martin Trappel wrote:
Hi.
To support the serialization of a class I don't want to change anything, I have added free save and load function. (See the test code below.) It compiles and appears to work.
I have the following questions: * Is it OK to put the save & load definitions in a separate implementation file?
Personally I think this is good practice. It shortens compile times and permits all of the code for class "X" to be in a *.lib file.
* Is it OK to specify track_never in a cpp file?
I don't think this is a good idea. A lot of serialization magic occurs in templates at compile time. Doing this will short-circuit this and break things.
Will this cause problems if someone else tries to serialize a map
?
not that I know of. Robert Ramey
thanks! - Martin
- global_serialization.h - // ... class MyComplexClass; // ... namespace boost { namespace serialization { // Declare save and load for MyComplexClass template<class Archive> void save(Archive & ar, const MyComplexClass& t, unsigned int version); template<class Archive> void load(Archive & ar, MyComplexClass& t, unsigned int version); } } // Split: BOOST_SERIALIZATION_SPLIT_FREE(MyComplexClass);
*****
- complex_class_serialization.cpp - // ... #include "ComplexClass.h" // ... typedef std::map
namespace boost { namespace serialization { template<class Archive> void save(Archive & ar, const MyComplexClass& t, unsigned int version) { // the relevant information to be serialized for // instances of MyComplexClass can be represented // by a map
ser_map_t m; // ... fill m object from t object
ar << m; // Serialize }
template<class Archive> void load(Archive & ar, CBoxHandler & t, unsigned int version) { ser_map_t m; ar >> m;
// ... init t object from m }
} // namespace serialization } // namespace boost
participants (2)
-
Martin Trappel
-
Robert Ramey