summaryrefslogtreecommitdiff
path: root/include/gras/detail
diff options
context:
space:
mode:
authorJosh Blum2013-03-17 15:47:30 -0700
committerJosh Blum2013-03-17 15:47:30 -0700
commitc70c996658138d0f38a1670f073cc327ff5ab920 (patch)
tree21a869c9df27675f8ef2552746b2109cbdd14a84 /include/gras/detail
parentf637a4081cef9d28d98e209efbd02099c56777a9 (diff)
downloadsandhi-c70c996658138d0f38a1670f073cc327ff5ab920.tar.gz
sandhi-c70c996658138d0f38a1670f073cc327ff5ab920.tar.bz2
sandhi-c70c996658138d0f38a1670f073cc327ff5ab920.zip
gras: property tweaks and c++ unit tests
Diffstat (limited to 'include/gras/detail')
-rw-r--r--include/gras/detail/block.hpp18
-rw-r--r--include/gras/detail/property.hpp8
2 files changed, 19 insertions, 7 deletions
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 <typename ClassType, typename ValueType>
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<ClassType, ValueType>(this, get, set));
+ pr.reset(new PropertyRegistryImpl<ClassType, ValueType>((ClassType *)this, get, set));
this->_register_property(key, pr);
}
template <typename ValueType>
-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 <typename ValueType>
+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<ValueType>();
}
template <typename ValueType>
-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<ValueType>();
}
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<PropertyRegistry> PropertyRegistrySptr;
template <typename ClassType, typename ValueType>
-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<ValueType>());
+ (_my_class->*_setter)(value.as<ValueType>());
}
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 &);