Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-10-19 12:06:26


Markus Werle wrote:

> I still cannot see how to avoid this extra <value> tag.
> Did it become clear now?

OK - I think I see the problem now.

There is a solution - but it's slightly tricky.

a) study the document and example on inheriting
from an existing archive.

b) derive your new archive extended_xml_oarchive
from xml_oarchive_impl

c) This will look something like:

class extended_xml_oarchive :
public xml_oarchive_impl<extended_xml_oarchive>
{
public:
    // pass on most types to normal handling in the base class xml_oarchive
    template<class T>
    void save(const T & t){
        xml_oarchive_impl<std::ostream>::save(t);
    }
    // special handling for an MFC CString - treat as if primitive
    void save(const CString &s){
        // just output the string using the output stream from base class
        // basic_text_oprimitive
        os << s; // assuming this is defined for CString
    );

    extended_xml_oarchive(std::ostream & os, unsigned int flags = 0) :
    extended_xml_oarchive_impl<extended_xml_oarchive>(os, flags){}
    ~extended_xml_oarchive(){}
};

and similarly for extended_xml_iarchive.

This will handle CString similar to the way that std::string is handled.
Note that the implementation of the function save(const CString ...
isn't too robust in that it doesn't handle special characters like
"<" which will muck up the xml. If you want to make this more
robust - look to the definition for the serialization of std::string
in xml_oarchive_impl.hpp for inspiration.

Robert Ramey


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