|
Boost : |
Subject: Re: [boost] interest in properties library
From: Sergey Sadovnikov (flex_ferrum_at_[hidden])
Date: 2008-12-20 18:20:52
Hello, Daniel.
Saturday, December 20, 2008 at 4:29:53 PM you wrote:
DO> What I still want to do is enable simpler syntax and maybe signals
DO> triggered by property and other goodies, but that is actually rather
DO> simple to do, using bind and/or lambda.
Some time ago I showed another way to define properties for the class.
I think what this way quite simpler. Take a look:
Some class which describes game item:
class Item
{
public:
Item() : properties__(this) {;} // that is all you need to // initialize properties for the class instance.
virtual ~Item() {;}
PROPERTIES(Item,
// Static information about item
PROPERTY(SItemInfo const*, ItemInfo)
// Quantity of the stored items (with default // initializer
PROPERTY_I(size_t, Quantity, 0)
// Flag which indicates what item is on the base
PROPERTY_I(bool, IsOnTheBase, false)
);
};
Usage of this class in the code:
boost::shared_ptr<Item> i(new Item());
i->Quantity = quantity;
Class 'Item' contains simple properties whose directly mapped to the
data members.
Another class, which contains "getter" property:
class Module
{
public:
PROPERTIES(Module,
// Common information about module
RO_PROPERTY(SModuleInfo, ModuleInfo, GetModuleInfo)
);
virtual const SModuleInfo& GetModuleInfo() const {return m_ModuleInfo;}
};
This property can be accessed in the same way:
SModuleInfo mi = module.ModuleInfo;
or in the 'function-style' way:
int size = module.ModuleInfo().ModuleSize;
Also you can define n-arity indexer properties:
class Base : public IBase
{
public:
PROPERTIES(Base,
RO_INDEX_PROPERTY(const IModule*, Map, 2, (TPARAM, TPARAM), GetModule)
);
};
Usage is:
Base& b = ...;
IModule* m = b.Map[1][2];
, virtual properties:
class IModule
{
public:
PROPERTIES(IModule,
// definition of the abstract property
ABSTRACT_RO_PROPERTY(SModuleInfo, ModuleInfo)
);
};
-- class Module : public IModule { public: PROPERTIES(Module, // Implementation of the abstract property IMPLEMENT_PROPERTY(IModule, RO_PROPERTY(SModuleInfo, ModuleInfo, GetModuleInfo)) ); enumerate properties in runtime, simple serialize/deserialize properties and so on. Best Regards, Sergey mailto:flex_ferrum_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk