From 9c02d6698f852d94736ce3a88e593bf45d22361d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 21 Dec 2014 23:46:14 +0100 Subject: allowing to store Function objects in Variants, added simple unit test for the Method class --- src/core/common/Function.hpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/core/common/Function.hpp') diff --git a/src/core/common/Function.hpp b/src/core/common/Function.hpp index 8113c9d..04030c8 100644 --- a/src/core/common/Function.hpp +++ b/src/core/common/Function.hpp @@ -36,15 +36,18 @@ namespace ousia { /** * The Function interface defines all the methods needed to represent a - * generic function. Function objects can be called using the "call" function in + * generic function. Function objects can be called using the "call" function in * which an array of Variant is supplied to the function and a Variant is * returned to the caller. */ class Function { +protected: + Function() {}; + public: - Function(const Function&) = delete; - Function(Function&&) = delete; - virtual ~Function() {}; + Function(const Function &) = delete; + Function(Function &&) = delete; + virtual ~Function(){}; /** * Abstract function which is meant to call the underlying function (be it @@ -90,29 +93,22 @@ public: * * @param method is a pointer at the C++ function that should be called. */ - Method(Callback method) : method(method){}; + Method(Callback method) : method(method) {}; /** * Calls the underlying method. * - * @param args is a vector containing all arguments that shouild be passed + * @param args is a vector containing all arguments that should be passed * to the method. * @return a Variant containing the return value. */ Variant call(const Variant::arrayType &args = Variant::arrayType{}, void *thisRef = nullptr) const override { - // Dynamically cast thisRef to the given type - T *tRef = dynamic_cast(thisRef); - - // Make sure the cast is successfull - assert(tRef != nullptr); - // Call the method - return method(args, tRef); + return method(args, static_cast(thisRef)); } }; - } #endif /* _OUSIA_FUNCTION_HPP_ */ -- cgit v1.2.3