summaryrefslogtreecommitdiff
path: root/include/gras/detail/property.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/gras/detail/property.hpp')
-rw-r--r--include/gras/detail/property.hpp63
1 files changed, 63 insertions, 0 deletions
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*/