Boost logo

Boost :

Subject: Re: [boost] interest in properties library
From: Daniel Oberhoff (daniel.oberhoff_at_[hidden])
Date: 2008-12-20 08:29:53

> On Fri, Dec 19, 2008 at 5:50 AM, Daniel Oberhoff <
> daniel.oberhoff_at_[hidden]> wrote:
> > Hi,
> >
> > I am thinking about submitting a library proposal and would like
> to query
> > wether there is any interest in such a library and chance of
> success of such
> > a proposal.
> >
> > The basic idea is to implement the possibility to decorate a class
> with
> > named properties, such that given a pointer to an instance
> properties can be
> > accessed by name rather than using set/get methods. Also the type
> of the
> > instance should not need to be known at compile time, other than
> that it
> > derives from a suitable base class describing the property
> mechanisms.
> >
> > There is a rough implementation existing and used in a product
> environment.
> > Setting and getting is done using appropriate boost functions. Type
> > resolution is done using RTTI (especially dynamic cast). Complex
> inheritance
> > hierarchies are supported through virtual inheritance from the
> base class,
> > such that several classes along the hierarchy can contribute
> property slots.
> > CRTP and static initialization is used to register properties.
> Convenient
> > setter/getter function generators are provided as is a mechanism
> to access
> > nested properties using dot notation.
> I'm not sure I follow exactly what you mean, could you give a small
> example
> of the interface and usage? It sounds like you are referring to
> something
> along the lines of C# properties though I don't immediately see what
> you are
> using dynamic casting for or what exactly this provides as a benefit
> over
> get/set methods. Thanks.

sorry, forgot the examples. so, to enable properties for a class:

class Foo : public HasProperties<VariantTypes, foo>


        typedef HasProperties<VariantTypes, foo> PBase;
        typedef Foo This;

        static void init_properties()
                PBase::add_ivar_property_rw( "a", &This::a );


                int a;



HasPropertiesBase<VariantTypes> * foo = new Foo;
foo->set_property("a", 1);
int a = get<int>( foo->get_property( "a" ) );

Here VariantTyped is a mpl::sequence

Furthermore it still works when a class has several such properties
activated classes along its inheritance ancestors, and all properties
can be acessed unless there is a name conflict, in which case classes
further down override properties from its ancestors, though this could
be handled differently.

What I still want to do is enable simpler syntax and maybe signals
triggered by property and other goodies, but that is actually rather
simple to do, using bind and/or lambda.



Boost list run by bdawes at, gregod at, cpdaniel at, john at