Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-12-23 20:23:29


Make the changes below and I think you'll be in business.

In spite of efforts on my part, I've still got a couple of cases
where header sequence can create a problem. One of these
shows up when nvp is used. Moving all boost/serializaiton...
headers below all boost/archive/... headers will workaround this problem

RObert Ramey

Merrill Cornish wrote:
> Robert,
>
> I just now got home to try adding the two NVP wrappers you suggested.
> The old problems went away, but there's a new set:
>
> Merrill
>
> Succ.h===========================================
> #include "boost/serialization/nvp.hpp"
> //#include "boost/test/test_tools.hpp" *** remove this
>
>
> namespace MyNS {
> class Succ {
> friend class Succ_Test;
>
> private:
> size_t mInputIndex;
> bool mIsInbound;
>
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive& ar, const unsigned int version) {
> ar & BOOST_SERIALIZATION_NVP(mInputIndex);
> ar & BOOST_SERIALIZATION_NVP(mIsInbound);
> }//serialize()
>
> public:
> Succ() {} // needed by serialization
> Succ(size_t inputIndex, bool isInbound);
> virtual ~Succ();
> size_t inputIndex() const;
> bool isInbound() const;
> };//Succ
> }//MyNS
>
>
> Succ_Test.cc===================================
> #include <fstream>
> #include "boost/archive/xml_iarchive.hpp"
> #include "boost/archive/xml_oarchive.hpp"
> #include "boost/test/test_tools.hpp"

> #include "Succ.h" // * move this below the archive headers
>
>
> using namespace std;
>
> namespace MyNS {
>
> class Succ_Test {
> public:
> void run();
> };//Succ_Test
> //=============================================================================
>
>
> void Succ_Test::run() {
> const char* archiveFile = "temp/Succ_archive.xml";
> size_t inputIndex = 65;
> bool isInbound = true;
>
> Succ* testObj_out = new Succ(inputIndex, isInbound);
> {
> // save data to archive
> ofstream outStream(archiveFile);
> boost::archive::xml_oarchive outArchive(outStream);
>
> // write class instance to archive
> outArchive << BOOST_SERIALIZATION_NVP(testObj_out);
> } // archive and stream closed when destructors are called
>
> Succ* testObj_in;// = new Succ();
> {
> // create and open an archive for input
> ifstream inStream(archiveFile);
> boost::archive::xml_iarchive inArchive(inStream);
>
> // read class state from archive
> inArchive >> BOOST_SERIALIZATION_NVP(testObj_in);
> } // archive and stream closed when destructors are called
> return;
> }//run()
> }//MyNS
>
>


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