Boost logo

Boost Users :

From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2006-10-17 10:44:41


Hi!

I cannot figure out how to make some class behave like a primitive
and let boost::serialization rely on ostream/istream operators
for xml input. This makes sense to me for e.g. String representations
other than std::string.
It seems it does not suffice to define the iostream operators.

As an example here is my try to get things right for an MFC/ATL CString:

std::istream & operator>>(std::istream &is, CString & S)
{
        std::string s;
         is >> s;
         S = s.c_str();
        return is;
}

#ifndef BOOST_NO_STD_WSTREAMBUF

std::wistream & operator>>(std::wistream &is, CString & S)
{
        std::wstring s;
         is >> s;
         S = s.c_str();
        return is;
}
#endif

BOOST_CLASS_IMPLEMENTATION(CString, boost::serialization::primitive_type)

Output works fine due to automatic conversion of CString to char*
but input fails. Debugging shows the end tag is "eaten" and
appended to the value. This means that in

struct C
{
   CString SomeString;
};

template<class Archive>
inline void serialize(Archive & ar,
                C & c,
                const unsigned int version)
{
        using boost::serialization::make_nvp;

        ar & make_nvp("SomeTag", c.SomeString);
};

C c;
c.SomeString = Test;

reading the archive yields
SomeString == "Test</SomeTag>"
and an exception ("stream error") is thrown by basic_xml_archive.

Any hint how to get things fixed here?
This would be nice in cases a string represenation is already
defined. Or should I work around this with binary_object? And how?

regards,

Markus


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