[Orxonox-commit 2481] r7188 - code/branches/consolecommands3/src/libraries/core

landauf at orxonox.net landauf at orxonox.net
Thu Aug 19 13:23:44 CEST 2010


Author: landauf
Date: 2010-08-19 13:23:43 +0200 (Thu, 19 Aug 2010)
New Revision: 7188

Modified:
   code/branches/consolecommands3/src/libraries/core/Executor.h
   code/branches/consolecommands3/src/libraries/core/Functor.h
   code/branches/consolecommands3/src/libraries/core/LuaState.h
Log:
reduced amount of member variables in Functor by moving these rarely used properties into virtual functions (which also fixes a small bug, because only FunctorStatic provided all required information so far)

Modified: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 00:42:40 UTC (rev 7187)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h	2010-08-19 11:23:43 UTC (rev 7188)
@@ -67,13 +67,13 @@
                 { return this->functor_->getParamCount(); }
             inline bool hasReturnvalue() const
                 { return this->functor_->hasReturnvalue(); }
-            inline FunctionType::Value getType() const
+            inline Functor::Type::Enum getType() const
                 { return this->functor_->getType(); }
             inline const MultiType& getReturnvalue() const
                 { return this->functor_->getReturnvalue(); }
-            inline const std::string& getTypenameParam(unsigned int param) const
+            inline std::string getTypenameParam(unsigned int param) const
                 { return this->functor_->getTypenameParam(param); }
-            inline const std::string& getTypenameReturnvalue() const
+            inline std::string getTypenameReturnvalue() const
                 { return this->functor_->getTypenameReturnvalue(); }
 
             inline void setName(const std::string& name)

Modified: code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-19 00:42:40 UTC (rev 7187)
+++ code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-19 11:23:43 UTC (rev 7188)
@@ -42,17 +42,6 @@
 {
     const unsigned int MAX_FUNCTOR_ARGUMENTS = 5;
 
-    namespace FunctionType
-    {
-        enum Value
-        {
-            Member,
-            ConstMember,
-            Static
-        };
-    }
-
-
     template <class T>
     inline std::string typeToString() { return "unknown"; }
 
@@ -99,19 +88,32 @@
     class _CoreExport Functor
     {
         public:
+            struct Type
+            {
+                enum Enum
+                {
+                    Member,
+                    ConstMember,
+                    Static,
+                    Lua
+                };
+            };
+
+        public:
             Functor() {}
             virtual ~Functor() {}
 
             virtual void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
 
-            inline unsigned int getParamCount() const { return this->numParams_; }
-            inline bool hasReturnvalue() const { return this->hasReturnValue_; }
-            inline FunctionType::Value getType() const { return this->type_; }
             inline const MultiType& getReturnvalue() const { return this->returnedValue_; }
 
-            const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : BLANKSTRING; }
-            const std::string& getTypenameReturnvalue() const { return this->typeReturnvalue_; }
+            virtual Type::Enum getType() const = 0;
+            virtual unsigned int getParamCount() const = 0;
+            virtual bool hasReturnvalue() const = 0;
 
+            virtual std::string getTypenameParam(unsigned int param) const = 0;
+            virtual std::string getTypenameReturnvalue() const = 0;
+
             virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
 
             virtual void setRawObjectPointer(void* object) {}
@@ -120,13 +122,7 @@
             virtual const std::type_info& getHeaderIdentifier() const = 0;
 
         protected:
-            unsigned int numParams_;
-            bool hasReturnValue_;
-            FunctionType::Value type_;
             MultiType returnedValue_;
-
-            std::string typeReturnvalue_;
-            std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
     };
 
     class _CoreExport FunctorStatic : public Functor
@@ -285,17 +281,38 @@
 
 
 
-#define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams
-#define FUNCTOR_TYPENAME_PARAMS0
-#define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();
-#define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();
-#define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();
-#define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();
-#define FUNCTOR_TYPENAME_PARAMS5 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); this->typeParam_[4] = typeToString<P5>();
+#define FUNCTOR_TYPENAME_PARAM(numparams) FUNCTOR_TYPENAME_PARAM##numparams
+#define FUNCTOR_TYPENAME_PARAM0 \
+    return BLANKSTRING
+#define FUNCTOR_TYPENAME_PARAM1 \
+    if (param == 0) { return typeToString<P1>(); } \
+    else { return BLANKSTRING; }
+#define FUNCTOR_TYPENAME_PARAM2 \
+    if (param == 0) { return typeToString<P1>(); } \
+    else if (param == 1) { return typeToString<P2>(); } \
+    else { return BLANKSTRING; }
+#define FUNCTOR_TYPENAME_PARAM3 \
+    if (param == 0) { return typeToString<P1>(); } \
+    else if (param == 1) { return typeToString<P2>(); } \
+    else if (param == 2) { return typeToString<P3>(); } \
+    else { return BLANKSTRING; }
+#define FUNCTOR_TYPENAME_PARAM4 \
+    if (param == 0) { return typeToString<P1>(); } \
+    else if (param == 1) { return typeToString<P2>(); } \
+    else if (param == 2) { return typeToString<P3>(); } \
+    else if (param == 3) { return typeToString<P4>(); } \
+    else { return BLANKSTRING; }
+#define FUNCTOR_TYPENAME_PARAM5 \
+    if (param == 0) { return typeToString<P1>(); } \
+    else if (param == 1) { return typeToString<P2>(); } \
+    else if (param == 2) { return typeToString<P3>(); } \
+    else if (param == 3) { return typeToString<P4>(); } \
+    else if (param == 4) { return typeToString<P5>(); } \
+    else { return BLANKSTRING; }
 
 #define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue
-#define FUNCTOR_TYPENAME_RETURN0
-#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();
+#define FUNCTOR_TYPENAME_RETURN0 BLANKSTRING
+#define FUNCTOR_TYPENAME_RETURN1 typeToString<R>()
 
 
 
@@ -374,13 +391,7 @@
         public: \
             FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
             { \
-                this->numParams_ = numparams; \
-                this->hasReturnValue_ = returnvalue; \
-                this->type_ = FunctionType::Static; \
                 this->functionPointer_ = functionPointer; \
-                \
-                FUNCTOR_TYPENAME_PARAMS(numparams); \
-                FUNCTOR_TYPENAME_RETURN(returnvalue); \
             } \
     \
             void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) \
@@ -393,6 +404,12 @@
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            Functor::Type::Enum getType() const { return Functor::Type::Static; } \
+            unsigned int getParamCount() const { return numparams; } \
+            bool hasReturnvalue() const { return returnvalue; } \
+            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
+            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
+    \
             const std::type_info& getHeaderIdentifier() const \
             { \
                 return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \
@@ -420,9 +437,6 @@
         public: \
             FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
             { \
-                this->numParams_ = numparams; \
-                this->hasReturnValue_ = returnvalue; \
-                this->type_ = FunctionType::Member; \
                 this->functionPointer_ = functionPointer; \
             } \
     \
@@ -442,6 +456,12 @@
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            Functor::Type::Enum getType() const { return Functor::Type::Member; } \
+            unsigned int getParamCount() const { return numparams; } \
+            bool hasReturnvalue() const { return returnvalue; } \
+            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
+            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
+    \
             const std::type_info& getHeaderIdentifier() const \
             { \
                 return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \
@@ -458,9 +478,6 @@
         public: \
             FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
             { \
-                this->numParams_ = numparams; \
-                this->hasReturnValue_ = returnvalue; \
-                this->type_ = FunctionType::ConstMember; \
                 this->functionPointer_ = functionPointer; \
             } \
     \
@@ -479,6 +496,12 @@
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            Functor::Type::Enum getType() const { return Functor::Type::ConstMember; } \
+            unsigned int getParamCount() const { return numparams; } \
+            bool hasReturnvalue() const { return returnvalue; } \
+            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
+            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
+    \
             const std::type_info& getHeaderIdentifier() const \
             { \
                 return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \

Modified: code/branches/consolecommands3/src/libraries/core/LuaState.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-19 00:42:40 UTC (rev 7187)
+++ code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-19 11:23:43 UTC (rev 7188)
@@ -53,6 +53,13 @@
             LuaFunctor(const std::string& code, LuaState* luaState);
             void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null);
             void evaluateParam(unsigned int index, MultiType& param) const {}
+
+            Functor::Type::Enum getType() const { return Functor::Type::Lua; } \
+            unsigned int getParamCount() const { return 0; }
+            bool hasReturnvalue() const { return 0; }
+            std::string getTypenameParam(unsigned int param) const { return BLANKSTRING; }
+            std::string getTypenameReturnvalue() const { return BLANKSTRING; }
+
             const std::type_info& getHeaderIdentifier() const { return typeid(this); }
 
         private:




More information about the Orxonox-commit mailing list