|
Boost Users : |
Subject: Re: [Boost-users] Serializing of object with map and multimap. Questions.
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-11-05 08:12:16
B Hart wrote:
> I've been having some problems storing and loading a class with a map
> and a multimap. The map contains values that are simple objects of
> another class. My questions are below. Here is also a link to the same
> question posted on stackoverflow.
> Thanks.
>
> http://stackoverflow.com/questions/1676781/boost-serializing-of-object-containing-map-with-object-values-and-multimap-wit
>
> See below a main() and two very simple classes. Then per Boost
> serialization (and what is shown) my questions are:
>
> 1) Does class B need the normal overloaded stream insertion operators
> '<<' and '>>' to be defined? Currently in my real code it doesn't have
> these.
As stated in:
http://www.boost.org/doc/libs/1_40_0/libs/serialization/doc/tutorial.html#simplecase
you provide a template member function:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
or non-intrusively:
http://www.boost.org/doc/libs/1_40_0/libs/serialization/doc/tutorial.html#nonintrusiveversion
namespace boost {
namespace serialization {
template<class Archive>
void serialize(Archive & ar, gps_B& b, const unsigned int version)
> 2) Does class A in the store() and load() methods need to iterate
> through the map and multimap containers explicitly, storing/loading
> their key:value pairs explicitely? e.g. something like:
>
> I assume that I don't need to do this, but am not certain.
As in:
http://www.boost.org/doc/libs/1_40_0/libs/serialization/doc/tutorial.html#stl
#include <boost/serialization/list.hpp>
std::list<bus_stop> stops;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & stops;
}
Just replace list above with map/multimap.
> 3) Assuming class B has only the two data members shown, does it need a
> default constructor included explicitly? (as opposed to the implicit
> default constructor)
Not a serialization issues, but what if you ever default construct a B
and use it, what state do you want it in?
> 4) Does B need to have an overide for the comparison operator '>'? I
> assume that it doesn't since this is a very simple class.
Not sure what this has to do with serialization.
Jeff
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