Boost logo

Boost Users :

From: Stefan Strasser (sstrasser_at_[hidden])
Date: 2005-03-17 16:22:16


remi.chateauneu_at_[hidden] schrieb:
> To summarize, given a struct or class, you just needed one or several
> list of fields, to be able to serialize these fields only, in a specific
> order.
>
> There were operators for serializing to a screen, creating 'CREATE
> TABLE', 'INSERT' and 'SELECT' sql queries, writing to a network socket,
> filling Windows dialogs, etc...
>

I had a quick look at a code example of your library and like to add
that it is possible to do this without having to declare a list of
members outside the class:

struct Class{
        FIELD(int,a);
};

#define FIELD(ValueT,name)
   struct _##name##_Function{
   inline void Register(){
     _RegisterField<This,ValueT,_##name##_Function>()(&This::name,#name);
   }
   }
   _ClassField<ValueT,_##name##_Function> name;

_ClassField is a class which behaves like a ValueT, with one difference:

template<typename ValueT,typename Function>
_ClassField<ValueT,Function>::_ClassField(){
   //generates _no_ code, empty inline function. is there to
instantiated _StaticRegisterer<Function>
   _StaticRegisterer<Function>::field.Reference()
}

template<typename T>
struct _StaticRegisterer{
   static _FieldRegisterer<T> field;
};

template<typename T>
struct _FieldRegisterer{
   _FieldRegisterer(); //this gets called at program startup, _not_ at
field construction, and registers the field.
   inline void Reference(){}
};

-- 
Stefan Strasser

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