c++ - Serializing a map of objects to xml using boost::serialization -


Here is an example of the serialization that is what I would like to do. However, I have changed the archive so that it can serialize XML. If I serialize the binary, then the compilation is not unsuccessful, but when XML is required to serial, it fails, the compilation in basic_xml_oarchive.hpp fails in the following method:

  // Promotion code where the compilation template fails & lt; Class T & gt; Void save_override (T & amp; t, BOOST_PFTO int) {// If your program fails to compile here, then it is most likely that do not specify the NVP wrapper around the // // variable, BOOST_MPL_ASSERT ((serialization :: is_wrapper & lt; t & gt;);) This- & gt; Expand_am_orchiva :: save_operradide (t, 0); }  

It looks like I did std :: map & lt; Int, CSomeData & gt; Is not enough to allow the object to be serialized, is it?


My serial execution implementation:

  #include & lt; Boost / archive / xml_oarchive.hpp & gt; # Include & lt; Boost / archive / xml_iarchive.hpp & gt; #include & lt; Boost / serialization / map.hpp & gt; # Include & lt; Fstream & gt; #include & lt; String & gt; # Include & lt; Map & gt; using namespace std; // This is a test class to use as map data class classodata {public: CSOmData () {}; CSOmData (float F 0, string straight) {m_f0 = f0; M_str0 = str0; } Float M_F 0; String m_str0; Private: Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; M_f0; R & A M_str0; }}; // This is the same class that we really want to serialize. Class Seat {public: CTEEST () {}; Cteist (Int NNumber) {m_nNumber = nNumber; // fill some dummy data with M_mTst.insert (make-pair (0, CSOm data (0.23F, "Hi hi")); M_mTst.insert (make-pair (1, CSOmeadata (7.65F, "second one"))); M_mTst.insert (make-pair (2, CSOM data (9.23F, "third one"))); M_mTst.insert (make_pair (3, CSOm data (5.6766, "selected one"))); } ~ Cteist () {}; Save () {std :: ofstream ofs ("filename"); // Write an archive to Class Instance. Writing seems to work fine Boost :: archive :: xml_oarchive oa (ofs); O & lt; & Lt; BOOST_SERIALIZATION_NVP (* this); } Int m_nNumber; Private: Maps & lt; Int, CSomeData & gt; M_mTst; Friend class promotion :: Serialization :: Access; Template & lt; Classic Collections & gt; Zero serial (archive and AR, consigned unsigned bunch version) {R & amp; M_nNumber; R & A M_mTst; }};  

I believe you need to tag members for XML serialization It specifies the name of the element to be used in XML. To wit. Use something like:

  AR & amp; BOOST_SERIALIZATION_NVP (m_f0);  

or (better in this case):

  AR & amp; Make_nvp ("field0", my_f0);  


Comments