// -*- C++ -*- #ifndef _datastore_xml_cdata_h_ #define _datastore_xml_cdata_h_ #include #include #include #include #include #include namespace datastore { struct XML_CDATA { const std::string* _xml; XML_CDATA(const std::string& xml) : _xml(&xml) {} template void serialize (Archive& ar, const unsigned int) const { ar & boost::serialization::make_nvp("xmldata", const_cast(*_xml)); } }; // This is a total hack to get around mysterious and intertwined // complexities of boost::serialization. Since I can't get the XML_CDATA // wrapper to work in the same way as the binary_object wrapper (see // below), I kludge it here by actually using a static to which this // method returns a non-const reference, which can then be passed into // make_nvp. The hope is that the rest of the code can use this form // until a way can be found to do this correctly. inline XML_CDATA& make_xml_cdata(std::string& xml) { static XML_CDATA xd(xml); xd = XML_CDATA(xml); return xd; } } BOOST_CLASS_IMPLEMENTATION(datastore::XML_CDATA, boost::serialization::object_serializable); BOOST_CLASS_TRACKING(datastore::XML_CDATA, boost::serialization::track_never); namespace boost { namespace archive { // This is how wrappers like binary_object, as created by // make_binary_object get past the const checking in the // boost::archive::load() functions, but I can't get it to work for // XML_CDATA. I thought maybe if this method were defined before the // ones in iserializer.hpp, then it might work, like maybe it doesn't // take affect being defined after the others. However, that // introduces header ordering problems that I also can't figure out. // The boost::serialization docs suggest that this header file should // work fine if it includes only headers from boost/serialization // first. However that then causes the export of ConfigNode at the end // of ConfigNode.cc to fail. template inline void load(Archive &ar, const datastore::XML_CDATA &t) { boost::archive::load(ar, const_cast(t)); } } } #endif // _datastore_xml_cdata_h_