[serialization] empty xml output
Hi all,
I am trying to introduce XML serialization in my project, but even with the
simplest test, I cannot get something to work. Here is what I did:
#define PARAMETERS_HPP
#include
Hi Olivier,
Your code looks ok.
On my system (Linux Ubuntu 9.10,gcc 4.4.1, Boost 1.44) I can check
that the following files 'parameters.hpp' and 'p1.cpp' compile, link and
execute properly:
{{{
#ifndef PARAMETERS_HPP
#define PARAMETERS_HPP
//no need to include archives here:
#include
Olivier Tournaire a écrit : Hi all,
I am trying to introduce XML serialization in my project, but even with the simplest test, I cannot get something to work. Here is what I did:
#define PARAMETERS_HPP #include
#include #include <iostream> class rss_feeds_to_parse { public: bool all; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(all); } }; class parameters { public: rss_feeds_to_parse feeds; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(feeds); } }; #endif // PARAMETERS_HPP Later, in my main, I have:
parameters p; p.feeds.all = true; std::ofstream ofs("test_parameters.xml"); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(p);
It compiles, links and executes well, the file test_parameters.xml is created ... but empty !
What am I doing wrong?
Hope you could help.
Best regards,
Olivier ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger@lpccaen.in2p3.fr Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
Hi,
2011/3/27 François Mauger
Hi Olivier,
Your code looks ok. On my system (Linux Ubuntu 9.10,gcc 4.4.1, Boost 1.44) I can check that the following files 'parameters.hpp' and 'p1.cpp' compile, link and execute properly: {{{ #ifndef PARAMETERS_HPP #define PARAMETERS_HPP
//no need to include archives here: #include
class rss_feeds_to_parse { public:
bool all; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(all); } };
class parameters { public: rss_feeds_to_parse feeds; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(feeds); } };
#endif // PARAMETERS_HPP }}} and {{{ #include <fstream> #include
#include // archive is included here #include #include "parameters.hpp"
int main (void)
{ parameters p; p.feeds.all = true; std::ofstream ofs ("test_parameters.xml"); assert (ofs.good ()); boost::archive::xml_oarchive oa (ofs); oa << BOOST_SERIALIZATION_NVP (p); return 0; } }}}
the output is: {{{ shell> cat test_parameters.xml <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<p class_id="0" tracking_level="0" version="0"> <feeds class_id="1" tracking_level="0" version="0"> <all>1</all> </feeds> </p> }}} which is correct.I suspect you have some other bits in your main that blanks the test_parameters.xml file...
Yes, probably. I tried my code removing all the other code in the main, and it works. What can cause this? Regards, Olivier
regards frc --
Olivier Tournaire a écrit :
Hi all,
I am trying to introduce XML serialization in my project, but even with the simplest test, I cannot get something to work. Here is what I did:
#define PARAMETERS_HPP #include
#include #include <iostream> class rss_feeds_to_parse { public: bool all; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(all); } }; class parameters { public: rss_feeds_to_parse feeds; template<class Archive> void serialize(Archive & ar, const unsigned int file_version) { ar & BOOST_SERIALIZATION_NVP(feeds); } }; #endif // PARAMETERS_HPP Later, in my main, I have:
parameters p; p.feeds.all = true; std::ofstream ofs("test_parameters.xml"); assert(ofs.good()); boost::archive::xml_oarchive oa(ofs); oa << BOOST_SERIALIZATION_NVP(p);
It compiles, links and executes well, the file test_parameters.xml is created ... but empty !
What am I doing wrong?
Hope you could help.
Best regards,
Olivier ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger@lpccaen.in2p3.fr Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Olivier Tournaire a écrit :
I suspect you have some other bits in your main that blanks the test_parameters.xml file...
Yes, probably. I tried my code removing all the other code in the main, and it works. What can cause this?
Typically a second call to {{{std::ofstream ofs ("test_parameters.xml");}}} from a independant code block invoked after your serialization bits. frc -- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger@lpccaen.in2p3.fr Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
Thx François,
2011/3/27 François Mauger
Olivier Tournaire a écrit :
I suspect you have some other bits in your main that blanks the test_parameters.xml file...
Yes, probably. I tried my code removing all the other code in the main, and it works. What can cause this?
Typically a second call to {{{std::ofstream ofs
("test_parameters.xml");}}} from a independant code block invoked after your serialization bits.
I never seen that. I somewhere else in my code creates ofstream but why that it clear my test_parameters.xml ofs? Putting the serialization code in the main but in a dedicated scope does the trick ... Really do not understand. Can someone explain? Regards, Olivier
frc
-- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger@lpccaen.in2p3.fr Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
François Mauger
-
Olivier Tournaire