Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-10-12 17:07:42


The name of collection items is hard coded as "item"
I'm not sure that every XML data item needs a name attribute but
I'm sure everyone expects to see one - as I do. In any case I wasn't
concerned as the the following example shows:

class A
{
        vector<int> ivector;
        vector<float> ffector
        template<class Archive>
        void serialize(Archive &ar, unsigned int file_version){
                ar << BOOST_SERIALIZATION_NVP(ivector);
                ar << BOOST_SERIALIZATION_NVP(fvector);
        }
}

would be rendered as:

...
<ivector>
        <count>2</count>
        <item>32</item>
        <item>47></item>
</ivector>
<fvector>
        <count>24.8768</count>
        <item>32.23</item>
        <item>478.97></item>
</fvector>

OK. There's never any possibilty of confusion. In fact serializaiton doesn't use
the names at all.

If you still don't like the word "item" the best is to override the appropriat
aspect of the collection serialization

Craigp wrote:

> I was thinking about customizing some of the serialization logic (eg:
> removing the 'count' element), but then I wound up just writing an xslt
> script to transform the XML file into something the boost xml
> serialization library liked (except I still wanted a way to keep the
> element names the same).

> > 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?
>

"Brian McNamara" <lorgon_at_[hidden]> wrote in message
news:<20031006051501.GB13144_at_[hidden]>...

> If all you want to specialize is the name, then it seems to me the
> right thing to do is
>
> (1) create
>
> namespace boost{
> namespace serialization {
> namespace stl {
> template <class T> struct container_element_name {
> static const char* name = "item";
> // I forget if it's legal to initialize that inline or not
> };
> }}}
>
> (2) replace the hardcoded "item" in the library with
>
> container_element_name<T>::name
>

Craigp wrote:

>Robert, as per my last post, would you mind adding something like the
>following to allow for overriding XML container element names?

>template <class T> struct container_element_name
>{
> static const char* name;
>};

>//default name
>template <class T>
>const char* container_element_name<T>::name = "item";

>Replace "item" with container_element_name<Container>::name in
>collections_load_imp.hpp and collections_save_imp.hpp (and
>[load,save]_array_type in [i,o]serializer.hpp)?

>FWIW, these are the macros I came up with:
>#define CONTAINER_ELEMENT_NAME(T, name)
[snip...]


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