Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] [units] class_id and class_name to describe quantity dimension in serilization archive
From: Bob Dean (bob.dean_at_[hidden])
Date: 2011-09-23 22:10:48


The BOOST_SERIALIZATION_NVP macro is shorthand for the boost::serialization::make_nvp(string name,object) template function. Easiest thing would be to call it directly:

oa << boost::serialization::make_nvp("quantity_si_length",q);

Sent from my iPhone

On Sep 23, 2011, at 8:50 PM, alfC <alfredo.correa_at_[hidden]> wrote:

> Hi,
> I am serializing a bunch of object that contains boost.units quantities. Boost.Units provides serialization for quantities already.
> By default, the output file looks ok but I would like to add a class name to the object description.
>
> Current, serializing quantity<si::length> q produces:
>
> <q class_id="0" tracking_level="1" version="0" object_id="_0">
> <value>5</value>
> </q>
>
> Which doesn't give any information about the quantity at hand, not even for the human reading it. So, I tried to use BOOST_CLASS_EXPORT_GUID to register a name for the serialized class, but it is ignored. Ideally I would like to have something like this, with a class_name description for example:
>
> <q class_id="0" class_name = "quantity_si_length" tracking_level="1" version="0" object_id="_0">
> <value>5</value>
> </q>
>
> Is something like this possible? Below is the working code:
>
> #include <fstream>
> #include <boost/serialization/export.hpp>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/archive/xml_oarchive.hpp>
> #include <boost/units/systems/si/io.hpp>
> using namespace boost::units;
> BOOST_CLASS_EXPORT_GUID(quantity<si::length>, "quantity_si_length") //ignored
>
> int main(int argc, char *argv[]) {
> std::ofstream ofs("filename.xml");
> boost::archive::xml_oarchive oa(ofs);
>
> quantity<si::length> q = 5.*si::meter;
>
> oa << BOOST_SERIALIZATION_NVP(q);
>
> return 0;
> }
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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