diff options
-rw-r--r-- | include/gras/CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/gras/block.hpp | 3 | ||||
-rw-r--r-- | include/gras/block.i | 1 | ||||
-rw-r--r-- | include/gras/detail/block.hpp | 43 | ||||
-rw-r--r-- | include/gras/detail/property.hpp | 56 | ||||
-rw-r--r-- | lib/block_props.cpp | 4 |
6 files changed, 45 insertions, 63 deletions
diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index 8700492..12e1bb1 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -30,7 +30,6 @@ install(FILES detail/block.hpp detail/chrono.hpp - detail/property.hpp detail/sbuffer.hpp detail/work_buffer.hpp diff --git a/include/gras/block.hpp b/include/gras/block.hpp index 3cbc473..7595345 100644 --- a/include/gras/block.hpp +++ b/include/gras/block.hpp @@ -9,7 +9,6 @@ #include <gras/tags.hpp> #include <gras/work_buffer.hpp> #include <gras/buffer_queue.hpp> -#include <gras/detail/property.hpp> #include <vector> #include <string> @@ -471,7 +470,7 @@ struct GRAS_API Block : Element * private implementation guts for overloads and template support ******************************************************************/ virtual PMCC _handle_prop_access(const std::string &, const PMCC &, const bool); - void _register_property(const std::string &, PropertyRegistrySptr); + void _register_property(const std::string &, PMCC); virtual void _set_property(const std::string &, const PMCC &); virtual PMCC _get_property(const std::string &); }; diff --git a/include/gras/block.i b/include/gras/block.i index 5bfdc91..10ef70c 100644 --- a/include/gras/block.i +++ b/include/gras/block.i @@ -8,7 +8,6 @@ %} %include <gras/element.i> -%include <gras/detail/property.hpp> %import <gras/tags.i> %include <gras/tag_iter.i> %import <gras/sbuffer.i> 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> diff --git a/include/gras/detail/property.hpp b/include/gras/detail/property.hpp deleted file mode 100644 index 2fcdca0..0000000 --- a/include/gras/detail/property.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. - -#ifndef INCLUDED_GRAS_DETAIL_PROPERTY_HPP -#define INCLUDED_GRAS_DETAIL_PROPERTY_HPP - -#include <gras/gras.hpp> -#include <PMC/PMC.hpp> -#include <boost/shared_ptr.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<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 &); -}; - -} //namespace gras - -#endif /*INCLUDED_GRAS_DETAIL_PROPERTY_HPP*/ diff --git a/lib/block_props.cpp b/lib/block_props.cpp index 6bb20e3..672200b 100644 --- a/lib/block_props.cpp +++ b/lib/block_props.cpp @@ -91,9 +91,9 @@ static PMCC prop_access_dispatcher(ActorType &actor, const std::string &key, con return receiver.message.value; } -void Block::_register_property(const std::string &key, PropertyRegistrySptr pr) +void Block::_register_property(const std::string &key, PMCC pr) { - (*this)->block->prop_registry[key] = pr; + (*this)->block->prop_registry[key] = pr.as<PropertyRegistrySptr>(); } void Block::_set_property(const std::string &key, const PMCC &value) |