Boost logo

Boost :

From: Craigp (craigp_at_[hidden])
Date: 2003-10-06 03:13:51


VC71 complains that only integral constants can have a static
initializer. The following seems to work:

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

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

#define CONTAINER_ELEMENT_NAME(T, NAME) \
namespace boost{ \
namespace serialization { \
namespace stl { \
template <>
\
const char* container_element_name<T>::name = NAME;
\
}}}

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).

So assuming this is legal (it's ok to put the initializers in header
files? Duplicate initialization via multiple includes isn't a problem?),
this is perfect.

Thanks!
--craig

"Brian McNamara" <lorgon_at_[hidden]> wrote in message
news:<20031006051501.GB13144_at_[hidden]>...
> On Sun, Oct 05, 2003 at 07:13:58PM -0700, Craigp wrote:
> > 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?
>
> 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
>
> (3) specialize this tiny little class (rather than specializing a
> whole big function/class) as desired:
>
> template <> container_element_name< MapTiles > {
> static const char* name = "tile";
> };
>
> Yes/no/maybe?
>
> --
> -Brian McNamara (lorgon_at_[hidden])
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


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