|
Boost Users : |
Subject: [Boost-users] boost::serialization - track_never, load and save in cpp file?
From: Martin Trappel (0xCDCDCDCD_at_[hidden])
Date: 2009-02-24 04:21:39
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<int, string> ?
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<int, std::string ser_map_t;
BOOST_CLASS_TRACKING(ser_map_t, boost::serialization::track_never);
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<int, string>
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
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