summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------grextras0
-rw-r--r--include/gras/block.i5
-rw-r--r--include/gras/callable.hpp8
-rw-r--r--include/gras/element.hpp8
-rw-r--r--include/gras/element.i5
-rw-r--r--lib/element.cpp5
-rw-r--r--lib/element_impl.hpp1
-rw-r--r--tests/block_props_test.py12
8 files changed, 29 insertions, 15 deletions
diff --git a/grextras b/grextras
-Subproject 79583e7fd6302ea4555c476dcfd9ab4c55a5fff
+Subproject 1b06249e988127c488593c2691cd1f87dbf0397
diff --git a/include/gras/block.i b/include/gras/block.i
index 2ba9779..0fed36d 100644
--- a/include/gras/block.i
+++ b/include/gras/block.i
@@ -19,8 +19,11 @@
%include <gras/block.hpp>
////////////////////////////////////////////////////////////////////////
-// Create pythonic gateway to get and set
+// Create pythonic methods
////////////////////////////////////////////////////////////////////////
+%pythoncode %{
+from PMC import *
+%}
%extend gras::Block
{
%insert("python")
diff --git a/include/gras/callable.hpp b/include/gras/callable.hpp
index ad74dd7..9d24c83 100644
--- a/include/gras/callable.hpp
+++ b/include/gras/callable.hpp
@@ -31,8 +31,9 @@ namespace gras
* - The overloaded () operator sucks with pointers.
* - The overloaded () operator has template issues.
*/
-struct GRAS_API Callable
+class GRAS_API Callable
{
+public:
//! Default constructor
Callable(void);
@@ -42,6 +43,7 @@ struct GRAS_API Callable
/*******************************************************************
* Register API - don't look here, template magic, not helpful
******************************************************************/
+protected:
template <typename ClassType, typename ReturnType>
void register_call(const std::string &key, ReturnType(ClassType::*fcn)(void));
@@ -69,6 +71,7 @@ struct GRAS_API Callable
/*******************************************************************
* Call API - don't look here, template magic, not helpful
******************************************************************/
+public:
template <typename ReturnType>
ReturnType x(const std::string &key);
@@ -96,8 +99,11 @@ struct GRAS_API Callable
/*******************************************************************
* Private registration hooks
******************************************************************/
+protected:
void _register_call(const std::string &, void *);
+public:
virtual PMCC _handle_call(const std::string &, const PMCC &);
+private:
boost::shared_ptr<void> _call_registry;
};
diff --git a/include/gras/element.hpp b/include/gras/element.hpp
index 9b46d76..df47bef 100644
--- a/include/gras/element.hpp
+++ b/include/gras/element.hpp
@@ -105,7 +105,7 @@ struct GRAS_API Element : Callable, boost::shared_ptr<ElementImpl>
void adopt_element(const std::string &name, const Element &child);
/*!
- * Locate a block in the element tree hierarchy.
+ * Locate an element in the element tree hierarchy.
*
* Paths are unix style, absolte and relatives paths are possible.
* This call throws an invalid argument when bad paths are given.
@@ -113,10 +113,10 @@ struct GRAS_API Element : Callable, boost::shared_ptr<ElementImpl>
* Example path: /my_hier_block/my_block0
* Example path: ../my_block1
*
- * \param path a path to a block (leaf) in the tree
- * \return a pointer to the block
+ * \param path a path to an element (leaf) in the tree
+ * \return a pointer to the element object
*/
- Block *locate_block(const std::string &path);
+ Element *locate_element(const std::string &path);
};
diff --git a/include/gras/element.i b/include/gras/element.i
index 8fbba00..38055a1 100644
--- a/include/gras/element.i
+++ b/include/gras/element.i
@@ -12,6 +12,8 @@
namespace gras
{
%ignore Element::set_container;
+ %ignore Callable::x;
+ %ignore Callable::register_call;
}
////////////////////////////////////////////////////////////////////////
@@ -23,9 +25,10 @@ namespace gras
// Export swig element comprehension
////////////////////////////////////////////////////////////////////////
%include <std_string.i>
+%import <PMC/PMC.i>
%include <gras/gras.hpp>
+%include <gras/callable.hpp>
%include <gras/element.hpp>
-%import <PMC/PMC.i>
////////////////////////////////////////////////////////////////////////
// Operator overloads for Element
diff --git a/lib/element.cpp b/lib/element.cpp
index 1781fc7..43a6d06 100644
--- a/lib/element.cpp
+++ b/lib/element.cpp
@@ -18,6 +18,7 @@ Element::Element(const std::string &name)
{
this->reset(new ElementImpl());
(*this)->name = name;
+ (*this)->self = this;
size_t which = 0;
while (true)
{
@@ -106,7 +107,7 @@ void Element::adopt_element(const std::string &name, const Element &child)
(*this)->children[name] = child;
}
-Block *Element::locate_block(const std::string &path)
+Element *Element::locate_element(const std::string &path)
{
//split the paths into nodes
std::vector<std::string> nodes;
@@ -142,5 +143,5 @@ Block *Element::locate_block(const std::string &path)
}
//return block ptr as result
- return elem->block_data->block;
+ return elem->self;
}
diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp
index 23f7127..91497ed 100644
--- a/lib/element_impl.hpp
+++ b/lib/element_impl.hpp
@@ -43,6 +43,7 @@ struct ElementImpl
//element tree stuff
Element parent;
std::map<std::string, Element> children;
+ Element *self;
//things may be in this element
boost::shared_ptr<Apology::Worker> worker;
diff --git a/tests/block_props_test.py b/tests/block_props_test.py
index 65acaac..61efc4a 100644
--- a/tests/block_props_test.py
+++ b/tests/block_props_test.py
@@ -59,27 +59,27 @@ class BlockPropsTest(unittest.TestCase):
my_block.x("set_foo", 42)
self.assertEqual(my_block.x("get_foo"), 42)
- my_block0 = tb.locate_block('/my_hier/my_block')
+ my_block0 = tb.locate_element('/my_hier/my_block')
self.assertEqual(my_block0.x("get_foo"), 42)
- my_block1 = hb.locate_block('my_block')
+ my_block1 = hb.locate_element('my_block')
self.assertEqual(my_block1.x("get_foo"), 42)
- my_block2 = hb.locate_block('./../my_hier/my_block')
+ my_block2 = hb.locate_element('./../my_hier/my_block')
self.assertEqual(my_block2.x("get_foo"), 42)
threw = False
- try: hb.locate_block('../../my_hier/my_block')
+ try: hb.locate_element('../../my_hier/my_block')
except: threw = True
self.assertTrue(threw)
threw = False
- try: hb.locate_block('../../my_hier/my_block0')
+ try: hb.locate_element('../../my_hier/my_block0')
except: threw = True
self.assertTrue(threw)
threw = False
- try: hb.locate_block('../../my_hier/my_block/test')
+ try: hb.locate_element('../../my_hier/my_block/test')
except: threw = True
self.assertTrue(threw)