Boost logo

Boost :

From: Craigp (craigp_at_[hidden])
Date: 2003-10-05 21:13:58


For XML serialization, container element names seem to be hardcoded to
'item'. Is it possible to override this? Partial specialization worked, but
I had to make save_collection a class (I renamed it to archive_output_seq to
mirror archive_input_seq), and, well, I used partial specialization. :-) Is
there a better way of overriding container element names? If not, can you
make save_collection a class, so we can partially specialize it?

Thanks for the great library!

FWIW, these are the macros I came up with:

#define CONTAINER_ELEMENT_NAME(T, name) \
namespace boost{ \
namespace serialization { \
namespace stl { \
template<class Archive> \
struct archive_input_seq<Archive, typename T> \
{ \
    inline void operator()(Archive &ar, T &s) \
    { \
        BOOST_DEDUCED_TYPENAME T::value_type t; \
        ar >> make_nvp(name, t); \
        s.push_back(t); \
    } \
}; \
template<class Archive> \
struct archive_output_seq<Archive, typename T> \
{ \
    inline void operator()(Archive &ar, const T &s) \
    { \
      T::size_type count = s.size(); \
      ar << BOOST_SERIALIZATION_NVP(count); \
      BOOST_DEDUCED_TYPENAME T::const_iterator it = s.begin(); \
      while( count-- > 0 ) { \
          ar << make_nvp(name, *it++); \
      } \
    } \
}; \
}}}

CONTAINER_ELEMENT_NAME(MR_Map::MapTiles, "Tile");
CONTAINER_ELEMENT_NAME(MR_MapTile::Clearings, "Clearing");
CONTAINER_ELEMENT_NAME(MR_MapTile::Paths, "Path");


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk