summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2013-07-05 14:13:37 -0700
committerJosh Blum2013-07-05 14:13:37 -0700
commit086cf85eca88941819909f5877d9558aaa761b72 (patch)
tree750197523499df923b69dc2cdf0f8003e7d8a02a
parentbc8165bcc3a2703d8fd3d17925b6bcb55ddff6ef (diff)
downloadsandhi-086cf85eca88941819909f5877d9558aaa761b72.tar.gz
sandhi-086cf85eca88941819909f5877d9558aaa761b72.tar.bz2
sandhi-086cf85eca88941819909f5877d9558aaa761b72.zip
gras: revert block changes, test w/ callable now
-rw-r--r--include/gras/block.hpp22
-rw-r--r--include/gras/detail/block.hpp100
-rw-r--r--lib/block_props.cpp15
-rw-r--r--lib/gras_impl/block_data.hpp2
-rw-r--r--tests/block_props_test.cpp50
5 files changed, 0 insertions, 189 deletions
diff --git a/include/gras/block.hpp b/include/gras/block.hpp
index 9ea609a..f2f1b2b 100644
--- a/include/gras/block.hpp
+++ b/include/gras/block.hpp
@@ -166,23 +166,6 @@ struct GRAS_API Block : Element
* Provides polymorphic, thread-safe access to block properties.
******************************************************************/
- template <typename ClassType, typename ReturnType> void register_call(const std::string &key, ReturnType(ClassType::*fcn)(void));
- template <typename ClassType, typename ReturnType, typename Arg0> void register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &));
- template <typename ClassType, typename ReturnType, typename Arg0, typename Arg1> void register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &, const Arg1 &));
-
- template <typename ReturnType> ReturnType call(const std::string &key);
- template <typename ReturnType, typename Arg0> ReturnType call(const std::string &key, const Arg0 &);
- template <typename ReturnType, typename Arg0, typename Arg1> ReturnType call(const std::string &key, const Arg0 &, const Arg1 &);
-
-
- template <typename ClassType> void register_call(const std::string &key, void(ClassType::*fcn)(void));
- template <typename ClassType, typename Arg0> void register_call(const std::string &key, void(ClassType::*fcn)(const Arg0 &));
- template <typename ClassType, typename Arg0, typename Arg1> void register_call(const std::string &key, void(ClassType::*fcn)(const Arg0 &, const Arg1 &));
-
- void call(const std::string &key);
- template <typename Arg0> void call(const std::string &key, const Arg0 &);
- template <typename Arg0, typename Arg1> void call(const std::string &key, const Arg0 &, const Arg1 &);
-
/*!
* Register property getter method into the property interface.
* Call register_getter() from the contructor of the block.
@@ -447,11 +430,6 @@ struct GRAS_API Block : Element
/*******************************************************************
* private implementation guts for overloads and template support
******************************************************************/
-
- void _register_function(const std::string &, void *);
- virtual PMCC _handle_function_access(const std::string &, const std::vector<PMCC> &);
-
-
virtual PMCC _handle_prop_access(const std::string &, const PMCC &, const bool);
void _register_getter(const std::string &, void *);
void _register_setter(const std::string &, void *);
diff --git a/include/gras/detail/block.hpp b/include/gras/detail/block.hpp
index e098797..9dccb22 100644
--- a/include/gras/detail/block.hpp
+++ b/include/gras/detail/block.hpp
@@ -8,106 +8,6 @@
namespace gras
{
-struct GRAS_API FunctionRegistry
-{
- FunctionRegistry(void);
- virtual ~FunctionRegistry(void);
- virtual PMCC call(const std::vector<PMCC> &args) = 0;
-};
-
-template <typename ClassType, typename ReturnType, typename Arg0, typename Arg1>
-class FunctionRegistryImpl : public FunctionRegistry
-{
-public:
-
- typedef ReturnType(ClassType::*Fcn0)(void);
- typedef ReturnType(ClassType::*Fcn1)(const Arg0 &);
- typedef ReturnType(ClassType::*Fcn2)(const Arg0 &, const Arg1 &);
-
- FunctionRegistryImpl(ClassType *obj, Fcn0 fcn0, Fcn1 fcn1 = NULL, Fcn2 fcn2 = NULL):
- _obj(obj), _fcn0(fcn0), _fcn1(fcn1), _fcn2(fcn2)
- {}
- virtual ~FunctionRegistryImpl(void){}
-
- PMCC call(const std::vector<PMCC> &args)
- {
- if (_fcn0) return PMC_M((_obj->*_fcn0)());
- if (_fcn1) return PMC_M((_obj->*_fcn1)(args[0].safe_as<Arg0>()));
- if (_fcn2) return PMC_M((_obj->*_fcn2)(args[0].safe_as<Arg0>(), args[1].safe_as<Arg1>()));
- return PMCC();//should not get here
- }
-
-private:
- ClassType *_obj;
- Fcn0 _fcn0; Fcn1 _fcn1; Fcn2 _fcn2;
-};
-
-template <typename ClassType, typename ReturnType> void Block::register_call(const std::string &key, ReturnType(ClassType::*fcn)(void))
-{
- ClassType *obj = dynamic_cast<ClassType *>(this);
- void *fr = new FunctionRegistryImpl<ClassType, ReturnType, int, int>(obj, fcn);
- _register_function(key, fr);
-}
-
-template <typename ClassType, typename ReturnType, typename Arg0> void Block::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &))
-{
- ClassType *obj = dynamic_cast<ClassType *>(this);
- void *fr = new FunctionRegistryImpl<ClassType, ReturnType, Arg0, int>(obj, NULL, fcn);
- _register_function(key, fr);
-}
-
-template <typename ClassType, typename ReturnType, typename Arg0, typename Arg1> void Block::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &, const Arg1 &))
-{
- ClassType *obj = dynamic_cast<ClassType *>(this);
- void *fr = new FunctionRegistryImpl<ClassType, ReturnType, Arg0, Arg1>(obj, NULL, NULL, fcn);
- _register_function(key, fr);
-}
-
-template <typename ReturnType> ReturnType Block::call(const std::string &key)
-{
- std::vector<PMCC> args;
- PMCC r = _handle_function_access(key, args);
- return r.safe_as<ReturnType>();
-}
-
-template <typename ReturnType, typename Arg0> ReturnType Block::call(const std::string &key, const Arg0 &a0)
-{
- std::vector<PMCC> args;
- args.push_back(PMC_M(a0));
- PMCC r = _handle_function_access(key, args);
- return r.safe_as<ReturnType>();
-}
-
-template <typename ReturnType, typename Arg0, typename Arg1> ReturnType Block::call(const std::string &key, const Arg0 &a0, const Arg1 &a1)
-{
- std::vector<PMCC> args;
- args.push_back(PMC_M(a0));
- args.push_back(PMC_M(a1));
- PMCC r = _handle_function_access(key, args);
- return r.safe_as<ReturnType>();
-}
-
-inline void Block::call(const std::string &key)
-{
- std::vector<PMCC> args;
- _handle_function_access(key, args);
-}
-
-template <typename Arg0> void Block::call(const std::string &key, const Arg0 &a0)
-{
- std::vector<PMCC> args;
- args.push_back(PMC_M(a0));
- _handle_function_access(key, args);
-}
-
-template <typename Arg0, typename Arg1> void Block::call(const std::string &key, const Arg0 &a0, const Arg1 &a1)
-{
- std::vector<PMCC> args;
- args.push_back(PMC_M(a0));
- args.push_back(PMC_M(a1));
- _handle_function_access(key, args);
-}
-
struct GRAS_API PropertyRegistry
{
PropertyRegistry(void);
diff --git a/lib/block_props.cpp b/lib/block_props.cpp
index fc4c755..ae687be 100644
--- a/lib/block_props.cpp
+++ b/lib/block_props.cpp
@@ -5,9 +5,6 @@
using namespace gras;
-FunctionRegistry::FunctionRegistry(void){}
-FunctionRegistry::~FunctionRegistry(void){}
-
PropertyRegistry::PropertyRegistry(void){}
PropertyRegistry::~PropertyRegistry(void){}
@@ -116,15 +113,3 @@ PMCC Block::_get_property(const std::string &key)
{
return prop_access_dispatcher((*this)->block_actor, key, PMCC(), false);
}
-
-
-void Block::_register_function(const std::string &key, void *fr)
-{
- (*this)->block_data->function_registry[key].reset(reinterpret_cast<FunctionRegistry *>(fr));
-}
-
-PMCC Block::_handle_function_access(const std::string &key, const std::vector<PMCC> &args)
-{
- //TODO this is testing -- needs to call actor instead
- return (*this)->block_data->function_registry[key]->call(args);
-}
diff --git a/lib/gras_impl/block_data.hpp b/lib/gras_impl/block_data.hpp
index 664ee5a..cbc657e 100644
--- a/lib/gras_impl/block_data.hpp
+++ b/lib/gras_impl/block_data.hpp
@@ -18,7 +18,6 @@
namespace gras
{
-typedef boost::shared_ptr<FunctionRegistry> FunctionRegistrySptr;
typedef boost::shared_ptr<PropertyRegistry> PropertyRegistrySptr;
struct PropertyRegistryPair
{
@@ -83,7 +82,6 @@ struct BlockData
//property stuff
std::map<std::string, PropertyRegistryPair> property_registry;
- std::map<std::string, FunctionRegistrySptr> function_registry;
BlockStats stats;
};
diff --git a/tests/block_props_test.cpp b/tests/block_props_test.cpp
index 91afd24..f53a1c3 100644
--- a/tests/block_props_test.cpp
+++ b/tests/block_props_test.cpp
@@ -68,53 +68,3 @@ BOOST_AUTO_TEST_CASE(test_property_errors)
//wrong type for property
BOOST_CHECK_THROW(my_block.set("foo", "a string"), std::exception);
}
-
-struct MyBlockNewShit : gras::Block
-{
- MyBlockNewShit(void):
- gras::Block("MyBlockNewShit")
- {
- this->register_call("foo", &MyBlockNewShit::foo);
- this->register_call("bar", &MyBlockNewShit::bar);
- this->register_call("baz", &MyBlockNewShit::baz);
- //this->register_call("example_setter", &MyBlockNewShit::example_setter);
- }
-
- //dummy work
- void work(const InputItems &, const OutputItems &){}
-
- int foo(void)
- {
- return 42;
- }
-
- int bar(const std::string &a0)
- {
- return a0.size();
- }
-
- int baz(const std::string &a0, const bool &a1)
- {
- return a1?a0.size():-1;
- }
-
- void example_setter(const long &)
- {
-
- }
-};
-
-BOOST_AUTO_TEST_CASE(test_property_newshit)
-{
- MyBlockNewShit my_block;
- size_t my_foo = my_block.call<size_t>("foo");
- BOOST_CHECK_EQUAL(my_foo, size_t(42));
-
- size_t my_bar = my_block.call<size_t>("bar", "hello");
- BOOST_CHECK_EQUAL(my_bar, size_t(5));
-
- signed my_baz = my_block.call<signed>("baz", "hello", false);
- BOOST_CHECK_EQUAL(my_baz, signed(-1));
-
- //my_block.call("example_setter", 123);
-}