Boost logo

Boost :

From: remi.chateauneu_at_[hidden]
Date: 2007-05-12 17:23:13


Dean Michael Berris a écrit :
> On 5/12/07, remi.chateauneu_at_[hidden] <remi.chateauneu_at_[hidden]> wrote:
>
>> This library does not specifically aim at serialization, but more
>> generally at providing for a given class, the list of its members.
>> Given such a list - a kind of tuple - it is possible to apply algorithms
>> which basically iterates over the members of this class. For example:
>>
>>
> Hmmm... I distinctly remember Joel de Guzman having something like
> this made part of Fusion -- which allows you to create aggregate types
> where you can iterate over the elements of the type. That required
> some preprocessor programming, which was called BOOST_FUSION_STRUCT
> (or something similar) instead of just the normal "struct".
> How is this different?
>
I do not know enough of this great library 'Fusion' to make a serious
analysis, and BOOST_FUSION_ADAPT_STRUCT seems very close to what I did,
although the whole library seems more oriented towards compile-time
operations ? My specific needs are:
- Iterations at run-time on class members, not only at compile-time,
because some operations might be difficult to code (Trivial example: Add
the latest ')' in a SQL query string). This implies, for example, that
manipulation on a list of class members are done with plain STL algorithms.
- The possibility to add dynamic attributes for class members, indexed
for example by typeid (Column names in a SQL table, or specific format
for displaying a given class member), which may change from one object
to another of the same class.
- The possibility to consider as a plain data member, any method
(getter/setter ...) of a class, even if there is no underlying member,
or if they are private, and also base classes.
 
>> Most of these features are implemented and running. It is designed to
>> add more 'plugins' of this type - and of course Boost.Serialization is
>> worth trying. A class can have as many members list as needed, and does
>> not have to be changed because the members lists are different objects.
>> The need came out of applications with dozens of business classes, where
>> the database persistence routines had to be re-written all the time.
>>
> Have you seen how Soci (http://soci.sourceforge.net/) does it for the
> SQL/DB stuff?
>
This is great too. Please let me quote
http://soci.sourceforge.net/doc/exchange.html

        v.set("ID", p.id);
        v.set("FIRST_NAME", p.firstName);
        v.set("LAST_NAME", p.lastName);
...
sql << "insert into person(id, first_name, last_name) "
       "values(:ID, :FIRST_NAME, :LAST_NAME)", use(p);"

Yes, it would be useful to generate the function 'to' and the 'insert'
query, using any all-purpose form of class members list. As an
illustration, I would generate the query with a members list defined
this way:

struct Person {
  int id;
  std::string firstName;
};

struct Person_Def {
  template< size_t > struct at ;
  static const size_t size = 2 ;
};

template<> struct Person_Def::at<0>
: public crd::member_t< Person, typeof( Person().id ), &Person::id > {};

template<> struct Person_Def::at<1>
: public crd::member_t< Person, typeof( Person().firstName ),
&Person::firstName > {};

Hope it answers your question.

>>> Do you have more readable documentation about the library?
>>>
>> Unfortunately not for the moment, although the code is short (1100 lines
>> in four files, without test programs) and well-documented, with examples.
>>
> I personally would like to see a writeup with a clear statement of the
> rationale and what it's intended to do.
>
Agreed - btw, what are the recommended tools for editing Boost
documentation ?

Thanks for your attention.


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