// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. #ifndef INCLUDED_GRAS_DETAIL_BLOCK_HPP #define INCLUDED_GRAS_DETAIL_BLOCK_HPP 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 PropertyRegistrySptr; template 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()); } 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 */ template inline void Block::register_getter( const std::string &key, ValueType(ClassType::*get)(void) ) { ClassType *obj = dynamic_cast(this); PropertyRegistrySptr pr; pr.reset(new PropertyRegistryImpl(obj, get, NULL)); this->_register_getter(key, PMC_M(pr)); } template inline void Block::register_setter( const std::string &key, void(ClassType::*set)(const ValueType &) ) { ClassType *obj = dynamic_cast(this); PropertyRegistrySptr pr; pr.reset(new PropertyRegistryImpl(obj, NULL, set)); this->_register_setter(key, PMC_M(pr)); } template inline void Block::set(const std::string &key, const ValueType &value) { this->_set_property(key, PMC_M(value)); } template inline void Block::get(const std::string &key, ValueType &value) { value = this->_get_property(key).as(); } template inline ValueType Block::get(const std::string &key) { return this->_get_property(key).as(); } } //namespace gras #endif /*INCLUDED_GRAS_DETAIL_BLOCK_HPP*/