From e23e5f43a97c72f1bf0dd240376bf89ff19f356c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 5 Jul 2013 14:53:22 -0700 Subject: gras: save callable work compiling w/ minor unit test --- include/gras/detail/callable.hpp | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'include/gras/detail') diff --git a/include/gras/detail/callable.hpp b/include/gras/detail/callable.hpp index 86b741d..5e7854a 100644 --- a/include/gras/detail/callable.hpp +++ b/include/gras/detail/callable.hpp @@ -8,15 +8,15 @@ namespace gras { -struct GRAS_API CallableRegistry +struct GRAS_API CallableRegistryEntry { - CallableRegistry(void); - virtual ~CallableRegistry(void); + CallableRegistryEntry(void); + virtual ~CallableRegistryEntry(void); virtual PMCC call(const std::vector &args) = 0; }; template -class CallableRegistryImpl : public CallableRegistry +class CallableRegistryEntryImpl : public CallableRegistryEntry { public: @@ -24,10 +24,10 @@ public: typedef ReturnType(ClassType::*Fcn1)(const Arg0 &); typedef ReturnType(ClassType::*Fcn2)(const Arg0 &, const Arg1 &); - CallableRegistryImpl(ClassType *obj, Fcn0 fcn0, Fcn1 fcn1 = NULL, Fcn2 fcn2 = NULL): + CallableRegistryEntryImpl(ClassType *obj, Fcn0 fcn0, Fcn1 fcn1 = NULL, Fcn2 fcn2 = NULL): _obj(obj), _fcn0(fcn0), _fcn1(fcn1), _fcn2(fcn2) {} - virtual ~CallableRegistryImpl(void){} + virtual ~CallableRegistryEntryImpl(void){} PMCC call(const std::vector &args) { @@ -42,35 +42,40 @@ private: Fcn0 _fcn0; Fcn1 _fcn1; Fcn2 _fcn2; }; -template void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(void)) +template +void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(void)) { ClassType *obj = dynamic_cast(this); - void *fr = new CallableRegistryImpl(obj, fcn); + void *fr = new CallableRegistryEntryImpl(obj, fcn); _register_call(key, fr); } -template void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &)) +template +void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &)) { ClassType *obj = dynamic_cast(this); - void *fr = new CallableRegistryImpl(obj, NULL, fcn); + void *fr = new CallableRegistryEntryImpl(obj, NULL, fcn); _register_call(key, fr); } -template void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &, const Arg1 &)) +template +void Callable::register_call(const std::string &key, ReturnType(ClassType::*fcn)(const Arg0 &, const Arg1 &)) { ClassType *obj = dynamic_cast(this); - void *fr = new CallableRegistryImpl(obj, NULL, NULL, fcn); + void *fr = new CallableRegistryEntryImpl(obj, NULL, NULL, fcn); _register_call(key, fr); } -template ReturnType Callable::call(const std::string &key) +template +ReturnType Callable::call(const std::string &key) { std::vector args; PMCC r = _handle_call(key, args); return r.safe_as(); } -template ReturnType Callable::call(const std::string &key, const Arg0 &a0) +template +ReturnType Callable::call(const std::string &key, const Arg0 &a0) { std::vector args; args.push_back(PMC_M(a0)); @@ -78,7 +83,8 @@ template ReturnType Callable::call(const st return r.safe_as(); } -template ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) +template +ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) { std::vector args; args.push_back(PMC_M(a0)); @@ -87,20 +93,23 @@ template ReturnType Callable return r.safe_as(); } -inline void Callable::call(const std::string &key) +inline +void Callable::call(const std::string &key) { std::vector args; _handle_call(key, args); } -template void Callable::call(const std::string &key, const Arg0 &a0) +template +void Callable::call(const std::string &key, const Arg0 &a0) { std::vector args; args.push_back(PMC_M(a0)); _handle_call(key, args); } -template void Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) +template +void Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) { std::vector args; args.push_back(PMC_M(a0)); -- cgit