Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7188


Ignore:
Timestamp:
Aug 19, 2010, 1:23:43 PM (14 years ago)
Author:
landauf
Message:

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)

Location:
code/branches/consolecommands3/src/libraries/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/Executor.h

    r7187 r7188  
    6868            inline bool hasReturnvalue() const
    6969                { return this->functor_->hasReturnvalue(); }
    70             inline FunctionType::Value getType() const
     70            inline Functor::Type::Enum getType() const
    7171                { return this->functor_->getType(); }
    7272            inline const MultiType& getReturnvalue() const
    7373                { return this->functor_->getReturnvalue(); }
    74             inline const std::string& getTypenameParam(unsigned int param) const
     74            inline std::string getTypenameParam(unsigned int param) const
    7575                { return this->functor_->getTypenameParam(param); }
    76             inline const std::string& getTypenameReturnvalue() const
     76            inline std::string getTypenameReturnvalue() const
    7777                { return this->functor_->getTypenameReturnvalue(); }
    7878
  • code/branches/consolecommands3/src/libraries/core/Functor.h

    r7185 r7188  
    4242{
    4343    const unsigned int MAX_FUNCTOR_ARGUMENTS = 5;
    44 
    45     namespace FunctionType
    46     {
    47         enum Value
    48         {
    49             Member,
    50             ConstMember,
    51             Static
    52         };
    53     }
    54 
    5544
    5645    template <class T>
     
    10089    {
    10190        public:
     91            struct Type
     92            {
     93                enum Enum
     94                {
     95                    Member,
     96                    ConstMember,
     97                    Static,
     98                    Lua
     99                };
     100            };
     101
     102        public:
    102103            Functor() {}
    103104            virtual ~Functor() {}
     
    105106            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;
    106107
    107             inline unsigned int getParamCount() const { return this->numParams_; }
    108             inline bool hasReturnvalue() const { return this->hasReturnValue_; }
    109             inline FunctionType::Value getType() const { return this->type_; }
    110108            inline const MultiType& getReturnvalue() const { return this->returnedValue_; }
    111109
    112             const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : BLANKSTRING; }
    113             const std::string& getTypenameReturnvalue() const { return this->typeReturnvalue_; }
     110            virtual Type::Enum getType() const = 0;
     111            virtual unsigned int getParamCount() const = 0;
     112            virtual bool hasReturnvalue() const = 0;
     113
     114            virtual std::string getTypenameParam(unsigned int param) const = 0;
     115            virtual std::string getTypenameReturnvalue() const = 0;
    114116
    115117            virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
     
    121123
    122124        protected:
    123             unsigned int numParams_;
    124             bool hasReturnValue_;
    125             FunctionType::Value type_;
    126125            MultiType returnedValue_;
    127 
    128             std::string typeReturnvalue_;
    129             std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
    130126    };
    131127
     
    286282
    287283
    288 #define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams
    289 #define FUNCTOR_TYPENAME_PARAMS0
    290 #define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();
    291 #define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();
    292 #define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();
    293 #define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();
    294 #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>();
     284#define FUNCTOR_TYPENAME_PARAM(numparams) FUNCTOR_TYPENAME_PARAM##numparams
     285#define FUNCTOR_TYPENAME_PARAM0 \
     286    return BLANKSTRING
     287#define FUNCTOR_TYPENAME_PARAM1 \
     288    if (param == 0) { return typeToString<P1>(); } \
     289    else { return BLANKSTRING; }
     290#define FUNCTOR_TYPENAME_PARAM2 \
     291    if (param == 0) { return typeToString<P1>(); } \
     292    else if (param == 1) { return typeToString<P2>(); } \
     293    else { return BLANKSTRING; }
     294#define FUNCTOR_TYPENAME_PARAM3 \
     295    if (param == 0) { return typeToString<P1>(); } \
     296    else if (param == 1) { return typeToString<P2>(); } \
     297    else if (param == 2) { return typeToString<P3>(); } \
     298    else { return BLANKSTRING; }
     299#define FUNCTOR_TYPENAME_PARAM4 \
     300    if (param == 0) { return typeToString<P1>(); } \
     301    else if (param == 1) { return typeToString<P2>(); } \
     302    else if (param == 2) { return typeToString<P3>(); } \
     303    else if (param == 3) { return typeToString<P4>(); } \
     304    else { return BLANKSTRING; }
     305#define FUNCTOR_TYPENAME_PARAM5 \
     306    if (param == 0) { return typeToString<P1>(); } \
     307    else if (param == 1) { return typeToString<P2>(); } \
     308    else if (param == 2) { return typeToString<P3>(); } \
     309    else if (param == 3) { return typeToString<P4>(); } \
     310    else if (param == 4) { return typeToString<P5>(); } \
     311    else { return BLANKSTRING; }
    295312
    296313#define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue
    297 #define FUNCTOR_TYPENAME_RETURN0
    298 #define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();
     314#define FUNCTOR_TYPENAME_RETURN0 BLANKSTRING
     315#define FUNCTOR_TYPENAME_RETURN1 typeToString<R>()
    299316
    300317
     
    375392            FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    376393            { \
    377                 this->numParams_ = numparams; \
    378                 this->hasReturnValue_ = returnvalue; \
    379                 this->type_ = FunctionType::Static; \
    380394                this->functionPointer_ = functionPointer; \
    381                 \
    382                 FUNCTOR_TYPENAME_PARAMS(numparams); \
    383                 FUNCTOR_TYPENAME_RETURN(returnvalue); \
    384395            } \
    385396    \
     
    393404                FUNCTOR_EVALUATE_PARAM(numparams); \
    394405            } \
     406    \
     407            Functor::Type::Enum getType() const { return Functor::Type::Static; } \
     408            unsigned int getParamCount() const { return numparams; } \
     409            bool hasReturnvalue() const { return returnvalue; } \
     410            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
     411            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
    395412    \
    396413            const std::type_info& getHeaderIdentifier() const \
     
    421438            FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
    422439            { \
    423                 this->numParams_ = numparams; \
    424                 this->hasReturnValue_ = returnvalue; \
    425                 this->type_ = FunctionType::Member; \
    426440                this->functionPointer_ = functionPointer; \
    427441            } \
     
    442456                FUNCTOR_EVALUATE_PARAM(numparams); \
    443457            } \
     458    \
     459            Functor::Type::Enum getType() const { return Functor::Type::Member; } \
     460            unsigned int getParamCount() const { return numparams; } \
     461            bool hasReturnvalue() const { return returnvalue; } \
     462            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
     463            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
    444464    \
    445465            const std::type_info& getHeaderIdentifier() const \
     
    459479            FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
    460480            { \
    461                 this->numParams_ = numparams; \
    462                 this->hasReturnValue_ = returnvalue; \
    463                 this->type_ = FunctionType::ConstMember; \
    464481                this->functionPointer_ = functionPointer; \
    465482            } \
     
    479496                FUNCTOR_EVALUATE_PARAM(numparams); \
    480497            } \
     498    \
     499            Functor::Type::Enum getType() const { return Functor::Type::ConstMember; } \
     500            unsigned int getParamCount() const { return numparams; } \
     501            bool hasReturnvalue() const { return returnvalue; } \
     502            std::string getTypenameParam(unsigned int param) const { FUNCTOR_TYPENAME_PARAM(numparams); } \
     503            std::string getTypenameReturnvalue() const { return FUNCTOR_TYPENAME_RETURN(returnvalue); } \
    481504    \
    482505            const std::type_info& getHeaderIdentifier() const \
  • code/branches/consolecommands3/src/libraries/core/LuaState.h

    r7179 r7188  
    5454            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);
    5555            void evaluateParam(unsigned int index, MultiType& param) const {}
     56
     57            Functor::Type::Enum getType() const { return Functor::Type::Lua; } \
     58            unsigned int getParamCount() const { return 0; }
     59            bool hasReturnvalue() const { return 0; }
     60            std::string getTypenameParam(unsigned int param) const { return BLANKSTRING; }
     61            std::string getTypenameReturnvalue() const { return BLANKSTRING; }
     62
    5663            const std::type_info& getHeaderIdentifier() const { return typeid(this); }
    5764
Note: See TracChangeset for help on using the changeset viewer.