$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [serialization] empty xml output
From: François Mauger (mauger_at_[hidden])
Date: 2011-03-27 07:08:46
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 <boost/serialization/nvp.hpp>
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 <assert.h>
#include <boost/archive/xml_oarchive.hpp> // archive is included here
#include <boost/serialization/nvp.hpp>
#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>
<boost_serialization signature="serialization::archive" version="7">
<p class_id="0" tracking_level="0" version="0">
<feeds class_id="1" tracking_level="0" version="0">
<all>1</all>
</feeds>
</p>
</boost_serialization>
}}}
which is correct.
I suspect you have some other bits in your main that blanks the
test_parameters.xml file...
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 <boost/archive/xml_iarchive.hpp>
> #include <boost/archive/xml_oarchive.hpp>
> #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_at_[hidden]
> http://listarchives.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_at_[hidden]
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