diff options
Diffstat (limited to 'include/gras/detail/block.hpp')
-rw-r--r-- | include/gras/detail/block.hpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp index 588c3cc..2a48080 100644 --- a/include/gras/detail/block.hpp +++ b/include/gras/detail/block.hpp @@ -6,6 +6,47 @@ namespace gras { +struct GRAS_API PropertyRegistry +{ + PropertyRegistry(void); + virtual ~PropertyRegistry(void); + virtual void set(const PMCC &) = 0; + virtual PMCC get(void) = 0; +}; + +typedef boost::shared_ptr<PropertyRegistry> PropertyRegistrySptr; + +template <typename ClassType, typename ValueType> +class PropertyRegistryImpl : public PropertyRegistry +{ +public: + PropertyRegistryImpl( + ClassType *my_class, + ValueType(ClassType::*getter)(void), + void(ClassType::*setter)(const ValueType &) + ): + _my_class(my_class), + _getter(getter), + _setter(setter) + {} + virtual ~PropertyRegistryImpl(void){} + + void set(const PMCC &value) + { + (_my_class->*_setter)(value.as<ValueType>()); + } + + PMCC get(void) + { + return PMC_M((_my_class->*_getter)()); + } + +private: + ClassType *_my_class; + ValueType(ClassType::*_getter)(void); + void(ClassType::*_setter)(const ValueType &); +}; + /*! * The following functions implement the templated methods in Block */ @@ -19,7 +60,7 @@ inline void Block::register_property( { PropertyRegistrySptr pr; pr.reset(new PropertyRegistryImpl<ClassType, ValueType>((ClassType *)this, get, set)); - this->_register_property(key, pr); + this->_register_property(key, PMC_M(pr)); } template <typename ValueType> |