From c70c996658138d0f38a1670f073cc327ff5ab920 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 17 Mar 2013 15:47:30 -0700 Subject: gras: property tweaks and c++ unit tests --- include/gras/detail/block.hpp | 18 ++++++++++++++---- include/gras/detail/property.hpp | 8 +++++--- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'include/gras/detail') diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp index a8bc2b1..c464446 100644 --- a/include/gras/detail/block.hpp +++ b/include/gras/detail/block.hpp @@ -6,6 +6,10 @@ namespace gras { +/*! + * The following functions implement the templated methods in Block + */ + template GRAS_FORCE_INLINE void Block::register_property( const std::string &key, @@ -14,18 +18,24 @@ GRAS_FORCE_INLINE void Block::register_property( ) { PropertyRegistrySptr pr; - pr.reset(new PropertyRegistryImpl(this, get, set)); + pr.reset(new PropertyRegistryImpl((ClassType *)this, get, set)); this->_register_property(key, pr); } template -GRAS_FORCE_INLINE void Block::set_property(const std::string &key, const ValueType &value) +GRAS_FORCE_INLINE void Block::set(const std::string &key, const ValueType &value) +{ + this->_set_property(key, PMC_M(value)); +} + +template +GRAS_FORCE_INLINE void Block::get(const std::string &key, ValueType &value) { - return this->_set_property(key, PMC_M(value)); + value = this->_get_property(key).as(); } template -GRAS_FORCE_INLINE ValueType Block::get_property(const std::string &key) +GRAS_FORCE_INLINE ValueType Block::get(const std::string &key) { return this->_get_property(key).as(); } diff --git a/include/gras/detail/property.hpp b/include/gras/detail/property.hpp index fd13025..2fcdca0 100644 --- a/include/gras/detail/property.hpp +++ b/include/gras/detail/property.hpp @@ -21,8 +21,9 @@ struct GRAS_API PropertyRegistry typedef boost::shared_ptr PropertyRegistrySptr; template -struct PropertyRegistryImpl : PropertyRegistry +class PropertyRegistryImpl : public PropertyRegistry { +public: PropertyRegistryImpl( ClassType *my_class, ValueType(ClassType::*getter)(void), @@ -36,14 +37,15 @@ struct PropertyRegistryImpl : PropertyRegistry void set(const PMCC &value) { - return _setter(_my_class, value.as()); + (_my_class->*_setter)(value.as()); } PMCC get(void) { - return PMC_M(_getter(_my_class)); + return PMC_M((_my_class->*_getter)()); } +private: ClassType *_my_class; ValueType(ClassType::*_getter)(void); void(ClassType::*_setter)(const ValueType &); -- cgit