summaryrefslogtreecommitdiff
path: root/include/gras
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
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')
-rw-r--r--include/gras/block.hpp36
-rw-r--r--include/gras/detail/block.hpp18
-rw-r--r--include/gras/detail/property.hpp8
3 files changed, 43 insertions, 19 deletions
diff --git a/include/gras/block.hpp b/include/gras/block.hpp
index d3e9848..477ad8d 100644
--- a/include/gras/block.hpp
+++ b/include/gras/block.hpp
@@ -106,8 +106,9 @@ struct GRAS_API OutputPortConfig
size_t maximum_items;
};
-struct GRAS_API Block : Element
+class GRAS_API Block : public Element
{
+public:
//! Contruct an empty/null block
Block(void);
@@ -254,30 +255,43 @@ struct GRAS_API Block : Element
* that is of the exact type associated with this property.
* Otherwise, set_property with throw a type error.
*
- * Example with template argument to be type explicit:
- * my_block->set_property<size_t>("foo", 42);
+ * Examples with explicit argument types:
+ * my_block->set<size_t>("foo", 42);
+ * my_block->set("foo", size_t(42));
*
* \param key the string to identify this property
* \param value the new value to set to this property
*/
template <typename ValueType>
- void set_property(const std::string &key, const ValueType &value);
+ void set(const std::string &key, const ValueType &value);
/*!
- * Get the value of a registered property.
+ * Get the value of a registered property with reference semantics.
*
- * Note: the user must specify the correct value type
+ * Note: the user must be careful to only use a value
* that is of the exact type associated with this property.
* Otherwise, get_property with throw a type error.
*
- * Example with template argument to be type explicit:
- * const size_t foo = my_block->get_property<size_t>("foo");
+ * Example getting property with reference semantics:
+ * size_t foo; my_block->get("foo", foo);
+ *
+ * \param key the string to identify this property
+ * \param value a reference to set to the result
+ */
+ template <typename ValueType>
+ void get(const std::string &key, ValueType &value);
+
+ /*!
+ * Get the value of a registered property with return semantics.
+ *
+ * Example getting property with return value semantics:
+ * const size_t foo = my_block->get<size_t>("foo");
*
* \param key the string to identify this property
* \return the value of this property
*/
template <typename ValueType>
- ValueType get_property(const std::string &key);
+ ValueType get(const std::string &key);
/*******************************************************************
* Work related routines and fail states
@@ -429,9 +443,6 @@ struct GRAS_API Block : Element
* This method is called by the scheduler to allocate output buffers.
* The user may overload this method to create a custom allocator.
*
- * Example use case:
- * //TODO code example
- *
* \param which_output the output port index number
* \param config holds token and recommended length
* \return a shared ptr to a new buffer queue object
@@ -461,6 +472,7 @@ struct GRAS_API Block : Element
/*******************************************************************
* private implementation guts for template support
******************************************************************/
+private:
void _register_property(const std::string &, PropertyRegistrySptr);
void _set_property(const std::string &, const PMCC &);
PMCC _get_property(const std::string &);
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 &);