Robert,
Here is the relevant code:
===========================================
from the header file for the class being serialized...
#include "boost/serialization/shared_ptr.hpp"
#include "boost/serialization/nvp.hpp"
#include "boost/date_time/posix_time/ptime.hpp"
#include "boost/date_time/posix_time/time_serialize.hpp"
. . .
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(WkFlo::RetractionMixin);
ar & BOOST_SERIALIZATION_NVP(mNode);
ar & BOOST_SERIALIZATION_NVP(mExportId);
ar & BOOST_SERIALIZATION_NVP(mExportStart);
}//serialize()
where mNode is a shared_ptr<>, mExportedId is a string, and mExportStart
is a ptime.
===========================================
from the test source file...
#include "boost/archive/xml_iarchive.hpp"
#include "boost/archive/xml_oarchive.hpp"
#include "boost/serialization/shared_ptr.hpp"
#include "boost/serialization/nvp.hpp"
. . .
void ExportedNode_Test::serializationTest() {
const char* archiveFile = "temp/Exported_Node_archive.xml";
remove(archiveFile); // remove any file with that name
MockNode_ptr BasicNodeObj1(new MockNode(2312));
ExportedNode_ptr testObj_out(new ExportedNode(BasicNodeObj1, "abcd"));
{
// save data to archive
ofstream outStream(archiveFile);
boost::archive::xml_oarchive outArchive(outStream);
// write class instance to archive
try {
outArchive << BOOST_SERIALIZATION_NVP(testObj_out);
} catch (exception& ex) { cerr << "write: " << ex.what() << endl;}
} // archive and stream closed when destructors are called
. . .
}
where the outArchive << is what wrote:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>