I think it is possible to implement a reflection framework using the
preprocessor library.  In much the same way that one of the links
previously mentioned
( http://www.garret.ru/~knizhnik/cppreflection/docs/reflect.html ), a
description system could be made.  The difference is that unlike the
example definition of the above link:

class A {
  public:
    int    i;
    char*  pc;
    double d;
  protected:
    long   larr[10];
    A**    ppa;
    A*     pa;
  public:
    RTTI_DESCRIBE_STRUCT((RTTI_FIELD(i, RTTI_FLD_PUBLIC),
                          RTTI_PTR(pc, RTTI_FLD_PUBLIC),
                          RTTI_FIELD(d, RTTI_FLD_PUBLIC),
                          RTTI_ARRAY(larr, RTTI_FLD_PROTECTED),
                          RTTI_PTR_TO_PTR(ppa, RTTI_FLD_PROTECTED),
                          RTTI_PTR(pa, RTTI_FLD_PROTECTED)));
};

We would have something more like the following:

#define A_DESCRIPTION DESCRIBE_STRUCT(6, \
           (RTTI_(int, i, RTTI_FLD_PUBLIC), \
            RTTI_(char*, pc, RTTI_FLD_PUBLIC), \
            RTTI_(double, d, RTTI_FLD_PUBLIC), \
            RTTI_ARRAY(long, 10, larr, RTTI_FLD_PROTECTED), \
            RTTI_(A**, ppa, RTTI_FLD_PROTECTED), \
            RTTI_(A*, pa, RTTI_FLD_PROTECTED)));

class A
{
    IMPLEMENT_DESCRIPTION(A_DESCRIPTION);
    int x; // some member variable which is not described
};

This has the advantage that you don't to respecify everything twice, and
yet, most of the serialization functions could be generated automatically
from A_DESCRIPTION.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to