Boost logo

Boost :

Subject: Re: [boost] interest in properties library
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2008-12-20 14:20:19

On Sat, Dec 20, 2008 at 5:29 AM, Daniel Oberhoff
<daniel.oberhoff_at_[hidden]> wrote:
> HasPropertiesBase<VariantTypes> * foo = new Foo;
> foo->set_property("a", 1);
> int a = get<int>( foo->get_property( "a" ) );

If this is your typical use case, I would implement properties
non-intrusively in a separate property_database:

property_database pd;
boost::shared_ptr<Foo> foo(new Foo);

The property_database class is essentially a
std::map<boost::weak_ptr<void>,std::map<std::string,boost::any>>, and
you'd dynamic_cast<void *> the pointers passed to set and get.

Another thought, you can also use tag types to make the properties
compile-time type-safe. See the similar system used in
In that case the syntax could be:

typedef property<struct tag_a,int> prop_a;
int p=pd.get<prop_a>(foo);

Emil Dotchevski
Reverge Studios, Inc.

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