Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 6, 2008, 4:21:56 PM (16 years ago)
Author:
landauf
Message:

Added new 'MultiType', replacing MultiTypePrimitive, MultiTypeString and MultiTypeMath. MultiType can hold all types MultiTypeMath was able to hold, namely all primitives, pointers, string and several math objects (vector2, 3 and 4, quaternion, colourvalue, radian, degree).

The new MultiType has a completely changed behaviour, I'll explain this on a wiki page somewhen.
But to say the most important things in a few words:
The MultiType has a fixed type. This type is determined by the first assigned value (by using setValue(value), operator=(value) or MultiType(value)). Every other value getting assigned later, will be converted to the first type. But you can change the type (setType<T>()), convert the value (convert<T>()) or force the type of a newly assigned value manually (setValue<T>(value)) by using template functions.

In contrast, the old MultiTypeMath changed it's internal type whenever a new type was assigned. So be aware of this important change.

At the moment I can't see any issues, but there might very well be several problems yet to discover, so further tests will be done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/Functor.h

    r1592 r1716  
    3333#include "CorePrereqs.h"
    3434
    35 #include "util/MultiTypeMath.h"
     35#include "util/MultiType.h"
    3636#include "util/Debug.h"
    3737
     
    9595            virtual ~Functor() {}
    9696
    97             virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
     97            virtual void operator()(const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) = 0;
    9898
    9999            inline unsigned int getParamCount() const { return this->numParams_; }
    100100            inline bool hasReturnvalue() const { return this->hasReturnValue_; }
    101101            inline FunctionType getType() const { return this->type_; }
    102             inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; }
     102            inline MultiType getReturnvalue() const { return this->returnedValue_; }
    103103
    104104            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }
    105105            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }
    106106
    107             virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0;
     107            virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
    108108
    109109        protected:
     
    111111            bool hasReturnValue_;
    112112            FunctionType type_;
    113             MultiTypeMath returnedValue_;
     113            MultiType returnedValue_;
    114114
    115115            std::string typeReturnvalue_;
     
    121121        public:
    122122            virtual ~FunctorStatic() {}
    123             virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
     123            virtual void operator()(const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) = 0;
    124124    };
    125125
     
    136136            virtual ~FunctorMember() {}
    137137
    138             virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
    139             virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
    140 
    141             virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
     138            virtual void operator()(T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) = 0;
     139            virtual void operator()(const T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) = 0;
     140
     141            virtual void operator()(const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null)
    142142            {
    143143                if (this->bConstObject_)
     
    280280
    281281
    282 
     282/*
    283283#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
    284284#define FUNCTOR_EVALUATE_PARAM0
     
    303303    else if (index == 3) { P4 temp = param; param = temp; } \
    304304    else if (index == 4) { P5 temp = param; param = temp; }
    305 
     305*/
     306#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
     307#define FUNCTOR_EVALUATE_PARAM0
     308#define FUNCTOR_EVALUATE_PARAM1 \
     309    if (index == 0) { param.convert<P1>(); }
     310#define FUNCTOR_EVALUATE_PARAM2 \
     311    if (index == 0) { param.convert<P1>(); } \
     312    else if (index == 1) { param.convert<P2>(); }
     313#define FUNCTOR_EVALUATE_PARAM3 \
     314    if (index == 0) { param.convert<P1>(); } \
     315    else if (index == 1) { param.convert<P2>(); } \
     316    else if (index == 2) { param.convert<P3>(); }
     317#define FUNCTOR_EVALUATE_PARAM4 \
     318    if (index == 0) { param.convert<P1>(); } \
     319    else if (index == 1) { param.convert<P2>(); } \
     320    else if (index == 2) { param.convert<P3>(); } \
     321    else if (index == 3) { param.convert<P4>(); }
     322#define FUNCTOR_EVALUATE_PARAM5 \
     323    if (index == 0) { param.convert<P1>(); } \
     324    else if (index == 1) { param.convert<P2>(); } \
     325    else if (index == 2) { param.convert<P3>(); } \
     326    else if (index == 3) { param.convert<P4>(); } \
     327    else if (index == 4) { param.convert<P5>(); }
    306328
    307329
     
    324346            } \
    325347    \
    326             void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
     348            void operator()(const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) \
    327349            { \
    328350                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
    329351            } \
    330352    \
    331             virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     353            virtual void evaluateParam(unsigned int index, MultiType& param) const \
    332354            { \
    333355                FUNCTOR_EVALUATE_PARAM(numparams); \
     
    362384            } \
    363385    \
    364             void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
     386            void operator()(T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) \
    365387            { \
    366388                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
    367389            } \
    368390    \
    369             void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
     391            void operator()(const T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) \
    370392            { \
    371393                COUT(1) << "An error occurred in Functor.h:" << std::endl; \
     
    373395            } \
    374396    \
    375             virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     397            virtual void evaluateParam(unsigned int index, MultiType& param) const \
    376398            { \
    377399                FUNCTOR_EVALUATE_PARAM(numparams); \
     
    395417            } \
    396418    \
    397             void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
     419            void operator()(T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) \
    398420            { \
    399421                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
    400422            } \
    401423    \
    402             void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
     424            void operator()(const T* object, const MultiType& param1 = MT_null, const MultiType& param2 = MT_null, const MultiType& param3 = MT_null, const MultiType& param4 = MT_null, const MultiType& param5 = MT_null) \
    403425            { \
    404426                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
    405427            } \
    406428    \
    407             virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     429            virtual void evaluateParam(unsigned int index, MultiType& param) const \
    408430            { \
    409431                FUNCTOR_EVALUATE_PARAM(numparams); \
Note: See TracChangeset for help on using the changeset viewer.