[Orxonox-commit 6328] r10985 - code/branches/cpp11_v2/src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Sun Dec 27 23:43:12 CET 2015


Author: landauf
Date: 2015-12-27 23:43:12 +0100 (Sun, 27 Dec 2015)
New Revision: 10985

Modified:
   code/branches/cpp11_v2/src/libraries/core/command/Functor.h
Log:
call function without using a touple

Modified: code/branches/cpp11_v2/src/libraries/core/command/Functor.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/command/Functor.h	2015-12-27 22:40:47 UTC (rev 10984)
+++ code/branches/cpp11_v2/src/libraries/core/command/Functor.h	2015-12-27 22:43:12 UTC (rev 10985)
@@ -115,8 +115,7 @@
 
 #include "core/CorePrereqs.h"
 
-#include <array>
-#include <tuple>
+#include <typeinfo>
 
 #include "util/Output.h"
 #include "util/MultiType.h"
@@ -384,7 +383,7 @@
                 { return this->functionPointer_; }
 
             // see Functor::getFullIdentifier()
-            const std::type_info& getFullIdentifier() const
+            virtual const std::type_info& getFullIdentifier() const override
                 { return typeid(F); }
 
         protected:
@@ -394,15 +393,15 @@
     namespace detail
     {
         // Helper class to get the type of the function pointer with the given class, parameters, return-value, and constness
-        template <class R, class O, bool isconst, class... Params> struct FunctionPointer                                   { typedef R (O::*Type)(Params...); };
-        template <class R, class O, class... Params>               struct FunctionPointer<R, O, true, Params...>            { typedef R (O::*Type)(Params...) const; };
-        template <class R, class... Params>                        struct FunctionPointer<R, void, false, Params...>        { typedef R (*Type)(Params...); };
+        template <class R, class O, bool isconst, class... Params> struct FunctionPointer                            { typedef R (O::*Type)(Params...); };
+        template <class R, class O, class... Params>               struct FunctionPointer<R, O, true, Params...>     { typedef R (O::*Type)(Params...) const; };
+        template <class R, class... Params>                        struct FunctionPointer<R, void, false, Params...> { typedef R (*Type)(Params...); };
 
         // Helper class, used to call a function-pointer with a given object and parameters and to return its return-value (if available)
-        template <class R, class O, bool isconst, class... Params>         struct FunctorCaller                                        { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, Params...>::Type functionPointer, O* object, const Params&... parameters)    { return (object->*functionPointer)(parameters...); } };
-        template <class O, bool isconst, class... Params>                  struct FunctorCaller<void, O, isconst, Params...>           { static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, Params...>::Type functionPointer, O* object, const Params&... parameters) { (object->*functionPointer)(parameters...); return MultiType::Null; } };
-        template <class R, bool isconst, class... Params>                  struct FunctorCaller<R, void, isconst, Params...>           { static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, Params...>::Type functionPointer, void*, const Params&... parameters)     { return (*functionPointer)(parameters...); } };
-        template <bool isconst, class... Params>                           struct FunctorCaller<void, void, isconst, Params...>        { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, Params...>::Type functionPointer, void*, const Params&... parameters)  { (*functionPointer)(parameters...); return MultiType::Null; } };
+        template <class R, class O, bool isconst, class... Params> struct FunctorCaller                                 { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, Params...>::Type       functionPointer, O* object, const Params&... parameters, const UnusedParams&...) { return (object->*functionPointer)(parameters...); } };
+        template <class O, bool isconst, class... Params>          struct FunctorCaller<void, O, isconst, Params...>    { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionPointer<void, O, isconst, Params...>::Type    functionPointer, O* object, const Params&... parameters, const UnusedParams&...) { (object->*functionPointer)(parameters...); return MultiType::Null; } };
+        template <class R, bool isconst, class... Params>          struct FunctorCaller<R, void, isconst, Params...>    { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionPointer<R, void, isconst, Params...>::Type    functionPointer, void*,     const Params&... parameters, const UnusedParams&...) { return (*functionPointer)(parameters...); } };
+        template <bool isconst, class... Params>                   struct FunctorCaller<void, void, isconst, Params...> { template <class... UnusedParams> static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, Params...>::Type functionPointer, void*,     const Params&... parameters, const UnusedParams&...) { (*functionPointer)(parameters...); return MultiType::Null; } };
 
         // Helper class to determine if a function has a returnvalue
         template <class T>
@@ -420,15 +419,6 @@
         struct GetNthParamType<0, T, Other...>
         { typedef T Type; };
 
-        //Barebones implementation of (make_)index_sequence for C++11
-        template <std::size_t...> struct index_sequence {};
-
-        template <std::size_t N, std::size_t... Is>
-        struct make_index_sequence : make_index_sequence<N - 1, N - 1, Is...> {};
-
-        template <std::size_t... Is>
-        struct make_index_sequence<0u, Is...> : index_sequence<Is...> {};
-
         //Helper structs to deduce the first N types of a parameter pack
         template<class... Types> struct type_list {};
 
@@ -490,8 +480,7 @@
             // see FunctorMember::operator()()
             virtual MultiType operator()(O* object, const MultiType& param1 = MultiType::Null, const MultiType& param2 = MultiType::Null, const MultiType& param3 = MultiType::Null, const MultiType& param4 = MultiType::Null, const MultiType& param5 = MultiType::Null) override
             {
-                auto multis = std::make_tuple(param1, param2, param3, param4, param5);
-                return callHelper(object, multis, detail::make_index_sequence<sizeof...(Params)>{});
+                return detail::FunctorCaller<R, O, isconst, Params...>::call(this->functionPointer_, object, param1, param2, param3, param4, param5);
             }
 
             // see Functor::clone()
@@ -566,13 +555,6 @@
             }
 
     private:
-            /// Helper function that extracts index numbers of parameters from a tuple. Needed to call the function pointer with the correct amount of arguments.
-            template<typename Tup, std::size_t... index>
-            MultiType callHelper(O* object, Tup&& tup, detail::index_sequence<index...>)
-            {
-                return detail::FunctorCaller<R, O, isconst, Params...>::call(this->functionPointer_, object, std::get<index>(std::forward<Tup>(tup))...);
-            }
-
             ///Helper function that deduces a parameter pack of types and returns the corresponding identifier
             template<class... Types>
             const std::type_info& getTypelistIdentifier(detail::type_list<Types...>) const
@@ -616,13 +598,13 @@
         template <class F, class R, class... Params> inline FunctorMemberPtr<F> callableHelper(const F& obj, R(F::*func)(Params...)) { return std::make_shared<FunctorCallable<F, R, false, Params...>>(obj); }
     }
 
-    template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...), OO* object) { return std::make_shared<FunctorTemplate<R, O, false, Params...>>(functionPointer, object); }   ///< Creates a new FunctorMember with the given function-pointer and an assigned object
-    template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const, OO* object) { return std::make_shared<FunctorTemplate<R, O, true, Params...>>(functionPointer, object); }   ///< Creates a new FunctorMember with the given function-pointer and an assigned object
+    template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...),       OO* object) { return std::make_shared<FunctorTemplate<R, O, false, Params...>>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object
+    template <class R, class O, class OO, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const, OO* object) { return std::make_shared<FunctorTemplate<R, O, true,  Params...>>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object
 
-    template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...)) { return std::make_shared<FunctorTemplate<R, O, false, Params...>>(functionPointer); }   ///< Creates a new FunctorMember with the given function-pointer
-    template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const) { return std::make_shared<FunctorTemplate<R, O, true, Params...>>(functionPointer); }   ///< Creates a new FunctorMember with the given function-pointer
+    template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...))       { return std::make_shared<FunctorTemplate<R, O, false, Params...>>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer
+    template <class R, class O, class... Params> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(Params...) const) { return std::make_shared<FunctorTemplate<R, O, true,  Params...>>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer
 
-    template <class R, class... Params> inline FunctorStaticPtr createFunctor(R (*functionPointer)(Params...)) { return std::make_shared<FunctorTemplate<R, void, false, Params...>>(functionPointer); }   ///< Creates a new Functor with the given function-pointer
+    template <class R, class... Params> inline FunctorStaticPtr createFunctor(R (*functionPointer)(Params...)) { return std::make_shared<FunctorTemplate<R, void, false, Params...>>(functionPointer); } ///< Creates a new FunctorStatic with the given function-pointer
     
     template <class F> inline FunctorMemberPtr<F> createFunctor(const F& obj) { return detail::callableHelper(obj, &F::operator()); } ///< Creates a new Functor with a callable object
 }




More information about the Orxonox-commit mailing list