Boost logo

Boost Users :

From: Markus Schwarzenberg (schwarzb_at_[hidden])
Date: 2008-08-12 05:06:01


Hi,

i just recently startet to dip into boost::serialization. In the examples
directory, there is demo.cpp, in which text_archive is used.

From my understanding of the tutorial ("In addition to text archives, the
library includes archive class for native binary data and xml formatted data
Interfaces to all archive classes are all identical.") it should be possible
to switch from text_archive to xml_archive by just replacing text_[io]archive
by xml_[io]archive and include the required header files.

However, when I do this, I'm getting lots of compiler error messages like
(Linux, gcc-4.1.2, boost-1.35.0)

  /usr/include/boost-1_35/boost/archive/basic_xml_oarchive.hpp: In member function 'void boost::archive::basic_xml_oarchive<Archive>::save_override(T&, int) [with T = const bus_schedule, Archive = boost::archive::xml_oarchive]':
  /usr/include/boost-1_35/boost/archive/detail/interface_oarchive.hpp:64: instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const bus_schedule, Archive = boost::archive::xml_oarchive]'
  demo-using-xml.cpp:286: instantiated from here
  /usr/include/boost-1_35/boost/archive/basic_xml_oarchive.hpp:88: error: no matching function for call to 'assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<const bus_schedule>::************)'
  /usr/include/boost-1_35/boost/archive/basic_xml_iarchive.hpp: In member function 'void boost::archive::basic_xml_iarchive<Archive>::load_override(T&, int) [with T = bus_schedule, Archive = boost::archive::xml_iarchive]':
  /usr/include/boost-1_35/boost/archive/xml_iarchive.hpp:74: instantiated from 'void boost::archive::xml_iarchive_impl<Archive>::load_override(T&, int) [with T = bus_schedule, Archive = boost::archive::xml_iarchive]'
  /usr/include/boost-1_35/boost/archive/detail/interface_iarchive.hpp:63: instantiated from 'Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = bus_schedule, Archive = boost::archive::xml_iarchive]'
  demo-using-xml.cpp:297: instantiated from here
  
The original demo.cpp however compiles fine.

The difference to the version using xml_archive is just:

--- demo.cpp 2008-08-11 18:06:45.394403000 +0200
+++ demo-using-xml.cpp 2008-08-12 07:33:33.147259000 +0200
@@ -14,8 +14,8 @@
 
 #include <boost/archive/tmpdir.hpp>
 
-#include <boost/archive/text_iarchive.hpp>
-#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
 
 #include <boost/serialization/base_object.hpp>
 #include <boost/serialization/utility.hpp>
@@ -282,7 +282,7 @@
 void save_schedule(const bus_schedule &s, const char * filename){
     // make an archive
     std::ofstream ofs(filename);
- boost::archive::text_oarchive oa(ofs);
+ boost::archive::xml_oarchive oa(ofs);
     oa << s;
 }
 
@@ -291,7 +291,7 @@
 {
     // open the archive
     std::ifstream ifs(filename);
- boost::archive::text_iarchive ia(ifs);
+ boost::archive::xml_iarchive ia(ifs);
 
     // restore the schedule from the archive
     ia >> s;
@@ -352,7 +352,7 @@
     std::cout << original_schedule;
     
     std::string filename(boost::archive::tmpdir());
- filename += "/demofile.txt";
+ filename += "/demofile.xml";
 
     // save the schedule
     save_schedule(original_schedule, filename.c_str());

What am I doing wrong?

Thanks,

Markus Schwarzenberg


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