diff options
-rw-r--r-- | include/gras/callable.hpp | 24 | ||||
-rw-r--r-- | include/gras/detail/callable.hpp | 16 | ||||
-rw-r--r-- | tests/callable_test.cpp | 30 |
3 files changed, 38 insertions, 32 deletions
diff --git a/include/gras/callable.hpp b/include/gras/callable.hpp index 6573370..2405b9d 100644 --- a/include/gras/callable.hpp +++ b/include/gras/callable.hpp @@ -23,7 +23,13 @@ namespace gras * this->register_call("set_foo", &MyClass::set_foo); * * Call a method on a instance of MyClass: - * my_class->call("set_foo", new_foo_val); + * my_class->x("set_foo", new_foo_val); + * + * Why x for the call method? + * - The "x" is short, one character of screen width. + * - The "x" looks like "*", which is commonly used. + * - The overloaded () operator sucks with pointers. + * - The overloaded () operator has template issues. */ struct GRAS_API Callable { @@ -64,28 +70,28 @@ struct GRAS_API Callable * Call API - don't look here, template magic, not helpful ******************************************************************/ template <typename ReturnType> - ReturnType call(const std::string &key); + ReturnType x(const std::string &key); inline - void call(const std::string &key); + void x(const std::string &key); template <typename ReturnType, typename Arg0> - ReturnType call(const std::string &key, const Arg0 &); + ReturnType x(const std::string &key, const Arg0 &); template <typename Arg0> - void call(const std::string &key, const Arg0 &); + void x(const std::string &key, const Arg0 &); template <typename ReturnType, typename Arg0, typename Arg1> - ReturnType call(const std::string &key, const Arg0 &, const Arg1 &); + ReturnType x(const std::string &key, const Arg0 &, const Arg1 &); template <typename Arg0, typename Arg1> - void call(const std::string &key, const Arg0 &, const Arg1 &); + void x(const std::string &key, const Arg0 &, const Arg1 &); template <typename ReturnType, typename Arg0, typename Arg1, typename Arg2> - ReturnType call(const std::string &key, const Arg0 &, const Arg1 &, const Arg2 &); + ReturnType x(const std::string &key, const Arg0 &, const Arg1 &, const Arg2 &); template <typename Arg0, typename Arg1, typename Arg2> - void call(const std::string &key, const Arg0 &, const Arg1 &, const Arg2 &); + void x(const std::string &key, const Arg0 &, const Arg1 &, const Arg2 &); /******************************************************************* * Private registration hooks diff --git a/include/gras/detail/callable.hpp b/include/gras/detail/callable.hpp index 23e3ab6..b3f0d00 100644 --- a/include/gras/detail/callable.hpp +++ b/include/gras/detail/callable.hpp @@ -202,7 +202,7 @@ void Callable::register_call(const std::string &key, void(ClassType::*fcn)(const * Call implementations with 0 args **********************************************************************/ template <typename ReturnType> -ReturnType Callable::call(const std::string &key) +ReturnType Callable::x(const std::string &key) { PMCC args[0]; PMCC r = _handle_call(key, args); @@ -210,7 +210,7 @@ ReturnType Callable::call(const std::string &key) } inline -void Callable::call(const std::string &key) +void Callable::x(const std::string &key) { PMCC args[0]; _handle_call(key, args); @@ -220,7 +220,7 @@ void Callable::call(const std::string &key) * Call implementations with 1 args **********************************************************************/ template <typename ReturnType, typename Arg0> -ReturnType Callable::call(const std::string &key, const Arg0 &a0) +ReturnType Callable::x(const std::string &key, const Arg0 &a0) { PMCC args[1]; args[0] = PMC_M(a0); @@ -229,7 +229,7 @@ ReturnType Callable::call(const std::string &key, const Arg0 &a0) } template <typename Arg0> -void Callable::call(const std::string &key, const Arg0 &a0) +void Callable::x(const std::string &key, const Arg0 &a0) { PMCC args[1]; args[0] = PMC_M(a0); @@ -240,7 +240,7 @@ void Callable::call(const std::string &key, const Arg0 &a0) * Call implementations with 2 args **********************************************************************/ template <typename ReturnType, typename Arg0, typename Arg1> -ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) +ReturnType Callable::x(const std::string &key, const Arg0 &a0, const Arg1 &a1) { PMCC args[2]; args[0] = PMC_M(a0); @@ -250,7 +250,7 @@ ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1 } template <typename Arg0, typename Arg1> -void Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) +void Callable::x(const std::string &key, const Arg0 &a0, const Arg1 &a1) { PMCC args[2]; args[0] = PMC_M(a0); @@ -262,7 +262,7 @@ void Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1) * Call implementations with 3 args **********************************************************************/ template <typename ReturnType, typename Arg0, typename Arg1, typename Arg2> -ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1, const Arg2 &a2) +ReturnType Callable::x(const std::string &key, const Arg0 &a0, const Arg1 &a1, const Arg2 &a2) { PMCC args[3]; args[0] = PMC_M(a0); @@ -273,7 +273,7 @@ ReturnType Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1 } template <typename Arg0, typename Arg1, typename Arg2> -void Callable::call(const std::string &key, const Arg0 &a0, const Arg1 &a1, const Arg2 &a2) +void Callable::x(const std::string &key, const Arg0 &a0, const Arg1 &a1, const Arg2 &a2) { PMCC args[3]; args[0] = PMC_M(a0); diff --git a/tests/callable_test.cpp b/tests/callable_test.cpp index 684a820..3cbbc5e 100644 --- a/tests/callable_test.cpp +++ b/tests/callable_test.cpp @@ -69,48 +69,48 @@ BOOST_AUTO_TEST_CASE(test_registered_methods) { MyClass my_class; { - size_t ret = my_class.call<size_t>("test_args0_with_return"); + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(0)); } { - size_t ret = my_class.call<size_t>("test_args1_with_return", 42); + size_t ret = my_class.x<size_t>("test_args1_with_return", 42); BOOST_CHECK_EQUAL(ret, size_t(42)); } { - size_t ret = my_class.call<size_t>("test_args2_with_return", 1, "OK"); + size_t ret = my_class.x<size_t>("test_args2_with_return", 1, "OK"); BOOST_CHECK_EQUAL(ret, size_t(3)); } { - size_t ret = my_class.call<size_t>("test_args3_with_return", 1, "OK", true); + size_t ret = my_class.x<size_t>("test_args3_with_return", 1, "OK", true); BOOST_CHECK_EQUAL(ret, size_t(3)); } { - size_t ret = my_class.call<size_t>("test_args3_with_return", 1, "OK", false); + size_t ret = my_class.x<size_t>("test_args3_with_return", 1, "OK", false); BOOST_CHECK_EQUAL(ret, size_t(0)); } { - my_class.call("test_args0_with_no_return"); //this adds 1 to count - size_t ret = my_class.call<size_t>("test_args0_with_return"); + my_class.x("test_args0_with_no_return"); //this adds 1 to count + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(1)); } { - my_class.call("test_args1_with_no_return", 42); - size_t ret = my_class.call<size_t>("test_args0_with_return"); + my_class.x("test_args1_with_no_return", 42); + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(42)); } { - my_class.call("test_args2_with_no_return", 1, "OK"); - size_t ret = my_class.call<size_t>("test_args0_with_return"); + my_class.x("test_args2_with_no_return", 1, "OK"); + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(3)); } { - my_class.call("test_args3_with_no_return", 1, "OK", true); - size_t ret = my_class.call<size_t>("test_args0_with_return"); + my_class.x("test_args3_with_no_return", 1, "OK", true); + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(3)); } { - my_class.call("test_args3_with_no_return", 1, "OK", false); - size_t ret = my_class.call<size_t>("test_args0_with_return"); + my_class.x("test_args3_with_no_return", 1, "OK", false); + size_t ret = my_class.x<size_t>("test_args0_with_return"); BOOST_CHECK_EQUAL(ret, size_t(0)); } } |