From fc80d2c0acec4f668b58a05bd5a3a06b0a2a2280 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Jul 2013 18:50:01 -0700 Subject: gras: begin replacing set/get with callable --- include/gras/detail/block.hpp | 91 ---------------------------------------- include/gras/detail/callable.hpp | 2 - 2 files changed, 93 deletions(-) (limited to 'include/gras/detail') diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp index 9dccb22..3f94e54 100644 --- a/include/gras/detail/block.hpp +++ b/include/gras/detail/block.hpp @@ -3,100 +3,9 @@ #ifndef INCLUDED_GRAS_DETAIL_BLOCK_HPP #define INCLUDED_GRAS_DETAIL_BLOCK_HPP -#include - namespace gras { -struct GRAS_API PropertyRegistry -{ - PropertyRegistry(void); - virtual ~PropertyRegistry(void); - virtual void set(const PMCC &) = 0; - virtual PMCC get(void) = 0; - virtual const std::type_info &type(void) const = 0; -}; - -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.safe_as()); - } - - PMCC get(void) - { - return PMC_M((_my_class->*_getter)()); - } - - const std::type_info &type(void) const - { - return typeid(ValueType); - } - -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); - void *pr = new PropertyRegistryImpl(obj, get, NULL); - this->_register_getter(key, pr); -} - -template -inline void Block::register_setter( - const std::string &key, - void(ClassType::*set)(const ValueType &) -) -{ - ClassType *obj = dynamic_cast(this); - void *pr = new PropertyRegistryImpl(obj, NULL, set); - this->_register_setter(key, 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).safe_as(); -} - -template -inline ValueType Block::get(const std::string &key) -{ - return this->_get_property(key).safe_as(); -} - template inline void Block::post_output_msg(const size_t i, const ValueType &value) { diff --git a/include/gras/detail/callable.hpp b/include/gras/detail/callable.hpp index b3f0d00..3f5252d 100644 --- a/include/gras/detail/callable.hpp +++ b/include/gras/detail/callable.hpp @@ -3,8 +3,6 @@ #ifndef INCLUDED_GRAS_DETAIL_CALLABLE_HPP #define INCLUDED_GRAS_DETAIL_CALLABLE_HPP -#include - namespace gras { -- cgit