diff options
Diffstat (limited to 'include/gras/detail')
-rw-r--r-- | include/gras/detail/block.hpp | 35 | ||||
-rw-r--r-- | include/gras/detail/property.hpp | 63 |
2 files changed, 98 insertions, 0 deletions
diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp new file mode 100644 index 0000000..483b2bf --- /dev/null +++ b/include/gras/detail/block.hpp @@ -0,0 +1,35 @@ +// 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 +{ + +template <typename ClassType, typename ValueType> +GRAS_FORCE_INLINE void Block::register_property( + const std::string &key, + ValueType(ClassType::*get)(void), + void(ClassType::*set)(const ValueType &) +) +{ + boost::shared_ptr<PropertyRegistry> pr; + pr.reset(new PropertyRegistryImpl<ClassType, ValueType>(this, get, set)); + this->property_interface_register(key, pr); +} + +template <typename ValueType> +GRAS_FORCE_INLINE void Block::set_property(const std::string &key, const ValueType &value) +{ + return this->property_interface_set(key, PMC_M(value)); +} + +template <typename ValueType> +GRAS_FORCE_INLINE ValueType Block::get_property(const std::string &key) +{ + return this->property_interface_get(key).as<ValueType>(); +} + +} //namespace gras + +#endif /*INCLUDED_GRAS_DETAIL_BLOCK_HPP*/ diff --git a/include/gras/detail/property.hpp b/include/gras/detail/property.hpp new file mode 100644 index 0000000..467fb70 --- /dev/null +++ b/include/gras/detail/property.hpp @@ -0,0 +1,63 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#ifndef INCLUDED_GRAS_DETAIL_PROPERTY_HPP +#define INCLUDED_GRAS_DETAIL_PROPERTY_HPP + +#include <PMC/PMC.hpp> + +namespace gras +{ + +struct PropertyRegistry +{ + PropertyRegistry(void){} + ~PropertyRegistry(void){} + virtual void set(const PMCC &) = 0; + virtual PMCC get(void) = 0; +}; + +template <typename ClassType, typename ValueType> +struct PropertyRegistryImpl : PropertyRegistry +{ + PropertyRegistryImpl( + ClassType *my_class, + ValueType(ClassType::*getter)(void), + void(ClassType::*setter)(const ValueType &) + ): + _my_class(my_class), + _getter(getter), + _setter(setter) + {} + ~PropertyRegistryImpl(void){} + + void set(const PMCC &value) + { + return _setter(_my_class, value.as<ValueType>()); + } + + PMCC get(void) + { + return PMC_M(_getter(_my_class)); + } + + ClassType *_my_class; + ValueType(ClassType::*_getter)(void); + void(ClassType::*_setter)(const ValueType &); +}; + +struct PropertyInterface +{ + virtual void property_interface_register( + const std::string &key, + boost::shared_ptr<PropertyRegistry> pr + ) = 0; + + virtual void property_interface_set(const std::string &key, const PMCC &value) = 0; + + virtual PMCC property_interface_get(const std::string &key) = 0; + +}; + +} //namespace gras + +#endif /*INCLUDED_GRAS_DETAIL_PROPERTY_HPP*/ |