Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 1:10:46 AM (17 years ago)
Author:
rgrieder
Message:

SVN doesn't seem to like me. Reverted some really badly converted line endings.

Location:
code/branches/network/src/core
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/core/Error.cc

    r1494 r1495  
    11/*
    22 *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net < *
     3 *                    > www.orxonox.net <
     4 *
    45 *
    56 *   License notice:
     
    2526 *
    2627 */
    27 /**    @file Error.cc    @brief Implementation of the Error class.*/
     28
     29/**
     30    @file Error.cc
     31    @brief Implementation of the Error class.
     32*/
     33
    2834#include "Error.h"
    2935#include "Debug.h"
     36
    3037namespace orxonox
    3138{
  • code/branches/network/src/core/Error.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Nicolas Perrenoud *   Co-authors: *      ... * *//**    @file Error.h    @brief Definition of the Error class.*/#ifndef _Error_H__
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Nicolas Perrenoud
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file Error.h
     31    @brief Definition of the Error class.
     32*/
     33
     34#ifndef _Error_H__
    235#define _Error_H__
    336
    4 #include "CorePrereqs.h"#include <string>
     37#include "CorePrereqs.h"
     38
     39#include <string>
     40
    541namespace orxonox
    642{
  • code/branches/network/src/core/Functor.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Fabian 'x3n' Landau *   Co-authors: *      ... * *   Inspiration: Functor by Benjamin Grauer */#ifndef _Functor_H__#define _Functor_H__#include "CorePrereqs.h"#include "util/MultiTypeMath.h"#include "Debug.h"#define MAX_FUNCTOR_ARGUMENTS 5namespace orxonox{    enum FunctionType    {        FT_MEMBER,        FT_CONSTMEMBER,        FT_STATIC    };    template <class T>    inline std::string typeToString() { return "unknown"; }#define CreateTypeToStringTemplate(type) \    template <> \    inline std::string typeToString<type>() { return #type; } \    template <> \    inline std::string typeToString<type&>() { return #type; } \    template <> \    inline std::string typeToString<const type>() { return #type; } \    template <> \    inline std::string typeToString<const type&>() { return #type; }    CreateTypeToStringTemplate(int);    CreateTypeToStringTemplate(unsigned int);    CreateTypeToStringTemplate(char);    CreateTypeToStringTemplate(unsigned char);    CreateTypeToStringTemplate(short);    CreateTypeToStringTemplate(unsigned short);    CreateTypeToStringTemplate(long);    CreateTypeToStringTemplate(unsigned long);    CreateTypeToStringTemplate(float);    CreateTypeToStringTemplate(double);    CreateTypeToStringTemplate(long double);    CreateTypeToStringTemplate(bool);    CreateTypeToStringTemplate(Vector2);    CreateTypeToStringTemplate(Vector3);    CreateTypeToStringTemplate(Quaternion);    CreateTypeToStringTemplate(ColourValue);    CreateTypeToStringTemplate(Radian);    CreateTypeToStringTemplate(Degree);    template <> \    inline std::string typeToString<std::string>() { return "string"; } \    template <> \    inline std::string typeToString<std::string&>() { return "string"; } \    template <> \    inline std::string typeToString<const std::string>() { return "string"; } \    template <> \    inline std::string typeToString<const std::string&>() { return "string"; }    class _CoreExport Functor    {        public:            Functor() {}            virtual ~Functor() {}            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;            inline unsigned int getParamCount() const { return this->numParams_; }            inline bool hasReturnvalue() const { return this->hasReturnValue_; }            inline FunctionType getType() const { return this->type_; }            inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; }            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0;        protected:            unsigned int numParams_;            bool hasReturnValue_;            FunctionType type_;            MultiTypeMath returnedValue_;            std::string typeReturnvalue_;            std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];    };    class _CoreExport FunctorStatic : public Functor    {        public:            virtual ~FunctorStatic() {}            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;    };    template <class T>    class FunctorMember : public Functor    {        public:            FunctorMember()            {                constObject_ = 0;                object_ = 0;                bConstObject_ = false;            }            virtual ~FunctorMember() {}            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;            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;            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)            {                if (this->bConstObject_)                {                    if (this->constObject_)                        (*this)(this->constObject_, param1, param2, param3, param4, param5);                    else                    {                        COUT(1) << "An error occurred in Functor.h:" << std::endl;                        COUT(1) << "Error: No const object set." << std::endl;                    }                }                else                {                    if (this->object_)                        (*this)(this->object_, param1, param2, param3, param4, param5);                    else                    {                        COUT(1) << "An error occurred in Functor.h:" << std::endl;                        COUT(1) << "Error: No object set." << std::endl;                    }                }            }            void setObject(T* object)            {                this->bConstObject_ = false;                this->object_ = object;            }            void setObject(const T* object)            {                this->bConstObject_ = true;                this->constObject_ = object;            }        private:            const T* constObject_;            T* object_;            bool bConstObject_;    };#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams#define FUNCTOR_TEMPLATE000#define FUNCTOR_TEMPLATE001 template <class P1>#define FUNCTOR_TEMPLATE002 template <class P1, class P2>#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE010 template <class R>#define FUNCTOR_TEMPLATE011 template <class R, class P1>#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE100 template <class T>#define FUNCTOR_TEMPLATE101 template <class T, class P1>#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE110 template <class T, class R>#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams#define FUNCTOR_TEMPLATE_CLASSES000#define FUNCTOR_TEMPLATE_CLASSES001 <P1>#define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2>#define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES010 <R>#define FUNCTOR_TEMPLATE_CLASSES011 <R, P1>#define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES100 <T>#define FUNCTOR_TEMPLATE_CLASSES101 <T, P1>#define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES110 <T, R>#define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1>#define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5>#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_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue#define FUNCTOR_TYPENAME_RETURN0#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();#define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams#define FUNCTOR_FUNCTION_PARAMS0#define FUNCTOR_FUNCTION_PARAMS1 P1 param1#define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2#define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3#define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4#define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5#define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue#define FUNCTOR_FUNCTION_RETURNVALUE0 void#define FUNCTOR_FUNCTION_RETURNVALUE1 R#define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams#define FUNCTOR_FUNCTION_CALL0#define FUNCTOR_FUNCTION_CALL1 param1#define FUNCTOR_FUNCTION_CALL2 param1, param2#define FUNCTOR_FUNCTION_CALL3 param1, param2, param3#define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4#define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5#define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams#define FUNCTOR_EVALUATE_PARAM0#define FUNCTOR_EVALUATE_PARAM1 \    if (index == 0) { P1 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM2 \    if (index == 0) { P1 temp = param; param = temp; } \    else if (index == 1) { P2 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM3 \    if (index == 0) { P1 temp = param; param = temp; } \    else if (index == 1) { P2 temp = param; param = temp; } \    else if (index == 2) { P3 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM4 \    if (index == 0) { P1 temp = param; param = temp; } \    else if (index == 1) { P2 temp = param; param = temp; } \    else if (index == 2) { P3 temp = param; param = temp; } \    else if (index == 3) { P4 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM5 \    if (index == 0) { P1 temp = param; param = temp; } \    else if (index == 1) { P2 temp = param; param = temp; } \    else if (index == 2) { P3 temp = param; param = temp; } \    else if (index == 3) { P4 temp = param; param = temp; } \    else if (index == 4) { P5 temp = param; param = temp; }#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \    class FunctorStatic##returnvalue##numparams : public FunctorStatic \    { \        public: \            FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \            { \                this->numParams_ = numparams; \                this->hasReturnValue_ = returnvalue; \                this->type_ = FT_STATIC; \                this->functionPointer_ = functionPointer; \                \                FUNCTOR_TYPENAME_PARAMS(numparams); \                FUNCTOR_TYPENAME_RETURN(returnvalue); \            } \    \            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) \            { \                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \            } \    \            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \            { \                FUNCTOR_EVALUATE_PARAM(numparams); \            } \    \        private: \            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \    }; \    \    \    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \    inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \    { \        return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \    }#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \    class FunctorMember##returnvalue##numparams : public FunctorMember<T> \    { \        public: \            FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \            { \                this->numParams_ = numparams; \                this->hasReturnValue_ = returnvalue; \                this->type_ = FT_MEMBER; \                this->functionPointer_ = functionPointer; \            } \    \            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) \            { \                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \            } \    \            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) \            { \                COUT(1) << "An error occurred in Functor.h:" << std::endl; \                COUT(1) << "Error: Function is not const." << std::endl; \            } \    \            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \            { \                FUNCTOR_EVALUATE_PARAM(numparams); \            } \    \        private: \            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \    }; \    \    \    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \    class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \    { \        public: \            FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \            { \                this->numParams_ = numparams; \                this->hasReturnValue_ = returnvalue; \                this->type_ = FT_CONSTMEMBER; \                this->functionPointer_ = functionPointer; \            } \    \            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) \            { \                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \            } \    \            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) \            { \                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \            } \    \            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \            { \                FUNCTOR_EVALUATE_PARAM(numparams); \            } \    \        private: \            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \    }; \    \    \    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \    inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \    { \        return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \    } \    \    \    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \    inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \    { \        return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \    }// disable annoying warning about forcing value to boolean
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Fabian 'x3n' Landau
     24 *   Co-authors:
     25 *      ...
     26 *
     27 *   Inspiration: Functor by Benjamin Grauer
     28 */
     29
     30#ifndef _Functor_H__
     31#define _Functor_H__
     32
     33#include "CorePrereqs.h"
     34
     35#include "util/MultiTypeMath.h"
     36#include "Debug.h"
     37
     38#define MAX_FUNCTOR_ARGUMENTS 5
     39
     40namespace orxonox
     41{
     42    enum FunctionType
     43    {
     44        FT_MEMBER,
     45        FT_CONSTMEMBER,
     46        FT_STATIC
     47    };
     48
     49
     50    template <class T>
     51    inline std::string typeToString() { return "unknown"; }
     52
     53#define CreateTypeToStringTemplate(type) \
     54    template <> \
     55    inline std::string typeToString<type>() { return #type; } \
     56    template <> \
     57    inline std::string typeToString<type&>() { return #type; } \
     58    template <> \
     59    inline std::string typeToString<const type>() { return #type; } \
     60    template <> \
     61    inline std::string typeToString<const type&>() { return #type; }
     62
     63    CreateTypeToStringTemplate(int);
     64    CreateTypeToStringTemplate(unsigned int);
     65    CreateTypeToStringTemplate(char);
     66    CreateTypeToStringTemplate(unsigned char);
     67    CreateTypeToStringTemplate(short);
     68    CreateTypeToStringTemplate(unsigned short);
     69    CreateTypeToStringTemplate(long);
     70    CreateTypeToStringTemplate(unsigned long);
     71    CreateTypeToStringTemplate(float);
     72    CreateTypeToStringTemplate(double);
     73    CreateTypeToStringTemplate(long double);
     74    CreateTypeToStringTemplate(bool);
     75    CreateTypeToStringTemplate(Vector2);
     76    CreateTypeToStringTemplate(Vector3);
     77    CreateTypeToStringTemplate(Quaternion);
     78    CreateTypeToStringTemplate(ColourValue);
     79    CreateTypeToStringTemplate(Radian);
     80    CreateTypeToStringTemplate(Degree);
     81
     82    template <> \
     83    inline std::string typeToString<std::string>() { return "string"; } \
     84    template <> \
     85    inline std::string typeToString<std::string&>() { return "string"; } \
     86    template <> \
     87    inline std::string typeToString<const std::string>() { return "string"; } \
     88    template <> \
     89    inline std::string typeToString<const std::string&>() { return "string"; }
     90
     91    class _CoreExport Functor
     92    {
     93        public:
     94            Functor() {}
     95            virtual ~Functor() {}
     96
     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;
     98
     99            inline unsigned int getParamCount() const { return this->numParams_; }
     100            inline bool hasReturnvalue() const { return this->hasReturnValue_; }
     101            inline FunctionType getType() const { return this->type_; }
     102            inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; }
     103
     104            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }
     105            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }
     106
     107            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0;
     108
     109        protected:
     110            unsigned int numParams_;
     111            bool hasReturnValue_;
     112            FunctionType type_;
     113            MultiTypeMath returnedValue_;
     114
     115            std::string typeReturnvalue_;
     116            std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
     117    };
     118
     119    class _CoreExport FunctorStatic : public Functor
     120    {
     121        public:
     122            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;
     124    };
     125
     126    template <class T>
     127    class FunctorMember : public Functor
     128    {
     129        public:
     130            FunctorMember()
     131            {
     132                constObject_ = 0;
     133                object_ = 0;
     134                bConstObject_ = false;
     135            }
     136            virtual ~FunctorMember() {}
     137
     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)
     142            {
     143                if (this->bConstObject_)
     144                {
     145                    if (this->constObject_)
     146                        (*this)(this->constObject_, param1, param2, param3, param4, param5);
     147                    else
     148                    {
     149                        COUT(1) << "An error occurred in Functor.h:" << std::endl;
     150                        COUT(1) << "Error: No const object set." << std::endl;
     151                    }
     152                }
     153                else
     154                {
     155                    if (this->object_)
     156                        (*this)(this->object_, param1, param2, param3, param4, param5);
     157                    else
     158                    {
     159                        COUT(1) << "An error occurred in Functor.h:" << std::endl;
     160                        COUT(1) << "Error: No object set." << std::endl;
     161                    }
     162                }
     163            }
     164
     165            void setObject(T* object)
     166            {
     167                this->bConstObject_ = false;
     168                this->object_ = object;
     169            }
     170
     171            void setObject(const T* object)
     172            {
     173                this->bConstObject_ = true;
     174                this->constObject_ = object;
     175            }
     176
     177        private:
     178            const T* constObject_;
     179            T* object_;
     180            bool bConstObject_;
     181    };
     182
     183
     184
     185#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams
     186#define FUNCTOR_TEMPLATE000
     187#define FUNCTOR_TEMPLATE001 template <class P1>
     188#define FUNCTOR_TEMPLATE002 template <class P1, class P2>
     189#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>
     190#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>
     191#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>
     192#define FUNCTOR_TEMPLATE010 template <class R>
     193#define FUNCTOR_TEMPLATE011 template <class R, class P1>
     194#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>
     195#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>
     196#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>
     197#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>
     198#define FUNCTOR_TEMPLATE100 template <class T>
     199#define FUNCTOR_TEMPLATE101 template <class T, class P1>
     200#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>
     201#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>
     202#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>
     203#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>
     204#define FUNCTOR_TEMPLATE110 template <class T, class R>
     205#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>
     206#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>
     207#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>
     208#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>
     209#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>
     210
     211
     212
     213#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams
     214#define FUNCTOR_TEMPLATE_CLASSES000
     215#define FUNCTOR_TEMPLATE_CLASSES001 <P1>
     216#define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2>
     217#define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3>
     218#define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4>
     219#define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5>
     220#define FUNCTOR_TEMPLATE_CLASSES010 <R>
     221#define FUNCTOR_TEMPLATE_CLASSES011 <R, P1>
     222#define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2>
     223#define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3>
     224#define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4>
     225#define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5>
     226#define FUNCTOR_TEMPLATE_CLASSES100 <T>
     227#define FUNCTOR_TEMPLATE_CLASSES101 <T, P1>
     228#define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2>
     229#define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3>
     230#define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4>
     231#define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5>
     232#define FUNCTOR_TEMPLATE_CLASSES110 <T, R>
     233#define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1>
     234#define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2>
     235#define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3>
     236#define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4>
     237#define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5>
     238
     239
     240
     241#define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams
     242#define FUNCTOR_TYPENAME_PARAMS0
     243#define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();
     244#define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();
     245#define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();
     246#define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();
     247#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>();
     248
     249#define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue
     250#define FUNCTOR_TYPENAME_RETURN0
     251#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();
     252
     253
     254
     255#define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams
     256#define FUNCTOR_FUNCTION_PARAMS0
     257#define FUNCTOR_FUNCTION_PARAMS1 P1 param1
     258#define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2
     259#define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3
     260#define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4
     261#define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5
     262
     263#define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue
     264#define FUNCTOR_FUNCTION_RETURNVALUE0 void
     265#define FUNCTOR_FUNCTION_RETURNVALUE1 R
     266
     267
     268
     269#define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams
     270#define FUNCTOR_FUNCTION_CALL0
     271#define FUNCTOR_FUNCTION_CALL1 param1
     272#define FUNCTOR_FUNCTION_CALL2 param1, param2
     273#define FUNCTOR_FUNCTION_CALL3 param1, param2, param3
     274#define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4
     275#define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5
     276
     277#define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)
     278#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall
     279#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall
     280
     281
     282
     283#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
     284#define FUNCTOR_EVALUATE_PARAM0
     285#define FUNCTOR_EVALUATE_PARAM1 \
     286    if (index == 0) { P1 temp = param; param = temp; }
     287#define FUNCTOR_EVALUATE_PARAM2 \
     288    if (index == 0) { P1 temp = param; param = temp; } \
     289    else if (index == 1) { P2 temp = param; param = temp; }
     290#define FUNCTOR_EVALUATE_PARAM3 \
     291    if (index == 0) { P1 temp = param; param = temp; } \
     292    else if (index == 1) { P2 temp = param; param = temp; } \
     293    else if (index == 2) { P3 temp = param; param = temp; }
     294#define FUNCTOR_EVALUATE_PARAM4 \
     295    if (index == 0) { P1 temp = param; param = temp; } \
     296    else if (index == 1) { P2 temp = param; param = temp; } \
     297    else if (index == 2) { P3 temp = param; param = temp; } \
     298    else if (index == 3) { P4 temp = param; param = temp; }
     299#define FUNCTOR_EVALUATE_PARAM5 \
     300    if (index == 0) { P1 temp = param; param = temp; } \
     301    else if (index == 1) { P2 temp = param; param = temp; } \
     302    else if (index == 2) { P3 temp = param; param = temp; } \
     303    else if (index == 3) { P4 temp = param; param = temp; } \
     304    else if (index == 4) { P5 temp = param; param = temp; }
     305
     306
     307
     308
     309
     310#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
     311    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
     312    class FunctorStatic##returnvalue##numparams : public FunctorStatic \
     313    { \
     314        public: \
     315            FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     316            { \
     317                this->numParams_ = numparams; \
     318                this->hasReturnValue_ = returnvalue; \
     319                this->type_ = FT_STATIC; \
     320                this->functionPointer_ = functionPointer; \
     321                \
     322                FUNCTOR_TYPENAME_PARAMS(numparams); \
     323                FUNCTOR_TYPENAME_RETURN(returnvalue); \
     324            } \
     325    \
     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) \
     327            { \
     328                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     329            } \
     330    \
     331            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     332            { \
     333                FUNCTOR_EVALUATE_PARAM(numparams); \
     334            } \
     335    \
     336        private: \
     337            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     338    }; \
     339    \
     340    \
     341    FUNCTOR_TEMPLATE(0, returnvalue, numparams) \
     342    inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     343    { \
     344        return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \
     345    }
     346
     347
     348
     349
     350
     351#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \
     352    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     353    class FunctorMember##returnvalue##numparams : public FunctorMember<T> \
     354    { \
     355        public: \
     356            FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     357            { \
     358                this->numParams_ = numparams; \
     359                this->hasReturnValue_ = returnvalue; \
     360                this->type_ = FT_MEMBER; \
     361                this->functionPointer_ = functionPointer; \
     362            } \
     363    \
     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) \
     365            { \
     366                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     367            } \
     368    \
     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) \
     370            { \
     371                COUT(1) << "An error occurred in Functor.h:" << std::endl; \
     372                COUT(1) << "Error: Function is not const." << std::endl; \
     373            } \
     374    \
     375            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     376            { \
     377                FUNCTOR_EVALUATE_PARAM(numparams); \
     378            } \
     379    \
     380        private: \
     381            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     382    }; \
     383    \
     384    \
     385    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     386    class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \
     387    { \
     388        public: \
     389            FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
     390            { \
     391                this->numParams_ = numparams; \
     392                this->hasReturnValue_ = returnvalue; \
     393                this->type_ = FT_CONSTMEMBER; \
     394                this->functionPointer_ = functionPointer; \
     395            } \
     396    \
     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) \
     398            { \
     399                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     400            } \
     401    \
     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) \
     403            { \
     404                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     405            } \
     406    \
     407            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     408            { \
     409                FUNCTOR_EVALUATE_PARAM(numparams); \
     410            } \
     411    \
     412        private: \
     413            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \
     414    }; \
     415    \
     416    \
     417    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     418    inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \
     419    { \
     420        return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     421    } \
     422    \
     423    \
     424    FUNCTOR_TEMPLATE(1, returnvalue, numparams) \
     425    inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \
     426    { \
     427        return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \
     428    }
     429
     430
     431// disable annoying warning about forcing value to boolean
    2432#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    3433#pragma warning(push)
    4434#pragma warning(disable:4100 4800)
    5435#endif
    6 #define CREATE_ALL_STATIC_FUNCTORS() \    CREATE_STATIC_FUNCTOR(0, 0); \    CREATE_STATIC_FUNCTOR(0, 1); \    CREATE_STATIC_FUNCTOR(0, 2); \    CREATE_STATIC_FUNCTOR(0, 3); \    CREATE_STATIC_FUNCTOR(0, 4); \    CREATE_STATIC_FUNCTOR(0, 5); \    CREATE_STATIC_FUNCTOR(1, 0); \    CREATE_STATIC_FUNCTOR(1, 1); \    CREATE_STATIC_FUNCTOR(1, 2); \    CREATE_STATIC_FUNCTOR(1, 3); \    CREATE_STATIC_FUNCTOR(1, 4); \    CREATE_STATIC_FUNCTOR(1, 5)#define CREATE_ALL_MEMBER_FUNCTORS() \    CREATE_MEMBER_FUNCTOR(0, 0); \    CREATE_MEMBER_FUNCTOR(0, 1); \    CREATE_MEMBER_FUNCTOR(0, 2); \    CREATE_MEMBER_FUNCTOR(0, 3); \    CREATE_MEMBER_FUNCTOR(0, 4); \    CREATE_MEMBER_FUNCTOR(0, 5); \    CREATE_MEMBER_FUNCTOR(1, 0); \    CREATE_MEMBER_FUNCTOR(1, 1); \    CREATE_MEMBER_FUNCTOR(1, 2); \    CREATE_MEMBER_FUNCTOR(1, 3); \    CREATE_MEMBER_FUNCTOR(1, 4); \    CREATE_MEMBER_FUNCTOR(1, 5)    CREATE_ALL_STATIC_FUNCTORS();    CREATE_ALL_MEMBER_FUNCTORS();}#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     436
     437#define CREATE_ALL_STATIC_FUNCTORS() \
     438    CREATE_STATIC_FUNCTOR(0, 0); \
     439    CREATE_STATIC_FUNCTOR(0, 1); \
     440    CREATE_STATIC_FUNCTOR(0, 2); \
     441    CREATE_STATIC_FUNCTOR(0, 3); \
     442    CREATE_STATIC_FUNCTOR(0, 4); \
     443    CREATE_STATIC_FUNCTOR(0, 5); \
     444    CREATE_STATIC_FUNCTOR(1, 0); \
     445    CREATE_STATIC_FUNCTOR(1, 1); \
     446    CREATE_STATIC_FUNCTOR(1, 2); \
     447    CREATE_STATIC_FUNCTOR(1, 3); \
     448    CREATE_STATIC_FUNCTOR(1, 4); \
     449    CREATE_STATIC_FUNCTOR(1, 5)
     450
     451
     452#define CREATE_ALL_MEMBER_FUNCTORS() \
     453    CREATE_MEMBER_FUNCTOR(0, 0); \
     454    CREATE_MEMBER_FUNCTOR(0, 1); \
     455    CREATE_MEMBER_FUNCTOR(0, 2); \
     456    CREATE_MEMBER_FUNCTOR(0, 3); \
     457    CREATE_MEMBER_FUNCTOR(0, 4); \
     458    CREATE_MEMBER_FUNCTOR(0, 5); \
     459    CREATE_MEMBER_FUNCTOR(1, 0); \
     460    CREATE_MEMBER_FUNCTOR(1, 1); \
     461    CREATE_MEMBER_FUNCTOR(1, 2); \
     462    CREATE_MEMBER_FUNCTOR(1, 3); \
     463    CREATE_MEMBER_FUNCTOR(1, 4); \
     464    CREATE_MEMBER_FUNCTOR(1, 5)
     465
     466
     467    CREATE_ALL_STATIC_FUNCTORS();
     468    CREATE_ALL_MEMBER_FUNCTORS();
     469}
     470
     471#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
    7472#pragma warning(pop)
    8 #endif#endif /* _Functor_H__ */
     473#endif
     474
     475#endif /* _Functor_H__ */
  • code/branches/network/src/core/Identifier.cc

    r1494 r1495  
    11/*
    22 *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net < *
     3 *                    > www.orxonox.net <
     4 *
    45 *
    56 *   License notice:
     
    3031    @brief Implementation of the Identifier class.
    3132*/
    32 #include "Identifier.h"#include <ostream>
     33
     34#include "Identifier.h"
     35
     36#include <ostream>
     37
    3338#include "Factory.h"
    34 #include "ConsoleCommand.h"#include "CommandExecutor.h"
     39#include "ConsoleCommand.h"
     40#include "CommandExecutor.h"
     41
    3542namespace orxonox
    3643{
     
    3946    // ###############################
    4047    int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero (this static member variable is ok: it's used in main(), not before)
     48
    4149    /**
    4250        @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
     
    4553    {
    4654        this->bCreatedOneObject_ = false;
    47         this->factory_ = 0;        this->bHasConfigValues_ = false;        this->bHasConsoleCommands_ = false;
    48 
    49         this->children_ = new std::set<const Identifier*>();        this->directChildren_ = new std::set<const Identifier*>();        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables        static unsigned int classIDcounter_s = 0;
    50         this->classID_ = classIDcounter_s++;    }
     55        this->factory_ = 0;
     56
     57        this->bHasConfigValues_ = false;
     58        this->bHasConsoleCommands_ = false;
     59
     60        this->children_ = new std::set<const Identifier*>();
     61        this->directChildren_ = new std::set<const Identifier*>();
     62
     63        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables
     64        static unsigned int classIDcounter_s = 0;
     65        this->classID_ = classIDcounter_s++;
     66    }
    5167
    5268    /**
     
    5571    Identifier::~Identifier()
    5672    {
    57         delete this->children_;        delete this->directChildren_;    }
     73        delete this->children_;
     74        delete this->directChildren_;
     75    }
    5876
    5977    /**
     
    6785
    6886        if (parents)
    69         {            this->parents_ = (*parents);            this->directParents_ = (*parents);            // Iterate through all parents
     87        {
     88            this->parents_ = (*parents);
     89            this->directParents_ = (*parents);
     90
     91            // Iterate through all parents
    7092            for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    71             {                // Tell the parent we're one of it's children                (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);                // Erase all parents of our parent from our direct-parent-list                for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)                {                    // Search for the parent's parent in our direct-parent-list                    for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)                    {                        if ((*it1) == (*it2))                        {                            // We've found a non-direct parent in our list: Erase it                            this->directParents_.erase(it2);                            break;                        }                    }                }            }            // Now iterate through all direct parents            for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)            {                // Tell the parent we're one of it's direct children                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);            }
     93            {
     94                // Tell the parent we're one of it's children
     95                (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     96
     97                // Erase all parents of our parent from our direct-parent-list
     98                for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
     99                {
     100                    // Search for the parent's parent in our direct-parent-list
     101                    for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
     102                    {
     103                        if ((*it1) == (*it2))
     104                        {
     105                            // We've found a non-direct parent in our list: Erase it
     106                            this->directParents_.erase(it2);
     107                            break;
     108                        }
     109                    }
     110                }
     111            }
     112
     113            // Now iterate through all direct parents
     114            for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     115            {
     116                // Tell the parent we're one of it's direct children
     117                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     118            }
    72119        }
    73120    }
     
    85132        else
    86133        {
    87             COUT(1) << "An error occurred in Identifier.cc:" << std::endl;            COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
     134            COUT(1) << "An error occurred in Identifier.cc:" << std::endl;
     135            COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl;
    88136            COUT(1) << "Aborting..." << std::endl;
    89137            abort();
     
    127175    {
    128176        return (this->parents_.find(identifier) != this->parents_.end());
    129     }    /**        @brief Returns true, if the assigned identifier is a direct child of the given identifier.        @param identifier The identifier to compare with    */    bool Identifier::isDirectChildOf(const Identifier* identifier) const    {        return (this->directParents_.find(identifier) != this->directParents_.end());    }
     177    }
     178
     179    /**
     180        @brief Returns true, if the assigned identifier is a direct child of the given identifier.
     181        @param identifier The identifier to compare with
     182    */
     183    bool Identifier::isDirectChildOf(const Identifier* identifier) const
     184    {
     185        return (this->directParents_.find(identifier) != this->directParents_.end());
     186    }
     187
    130188    /**
    131189        @brief Returns true, if the assigned identifier is a parent of the given identifier.
     
    135193    {
    136194        return (this->children_->find(identifier) != this->children_->end());
    137     }    /**        @brief Returns true, if the assigned identifier is a direct parent of the given identifier.        @param identifier The identifier to compare with    */    bool Identifier::isDirectParentOf(const Identifier* identifier) const    {        return (this->directChildren_->find(identifier) != this->directChildren_->end());    }    /**        @brief Returns the map that stores all Identifiers.        @return The map    */    std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()    {        static std::map<std::string, Identifier*> identifierMap;        return identifierMap;    }    /**        @brief Returns the map that stores all Identifiers.        @return The map    */    std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()    {        static std::map<std::string, Identifier*> lowercaseIdentifierMap;        return lowercaseIdentifierMap;    }    /**        @brief Adds the ConfigValueContainer of a variable, given by the string of its name.        @param varname The name of the variablee        @param container The container    */    void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)    {        std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname);        if (it != this->configValues_.end())        {            COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl;        }        this->bHasConfigValues_ = true;        this->configValues_[varname] = container;        this->configValues_LC_[getLowercase(varname)] = container;    }    /**        @brief Returns the ConfigValueContainer of a variable, given by the string of its name.        @param varname The name of the variable        @return The ConfigValueContainer    */    ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname)    {        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);        if (it != configValues_.end())            return ((*it).second);        else            return 0;    }    /**        @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.        @param varname The name of the variable in lowercase        @return The ConfigValueContainer    */    ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)    {        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);        if (it != configValues_LC_.end())            return ((*it).second);        else            return 0;    }    /**        @brief Adds a new console command of this class.        @param executor The executor of the command        @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command        @return The executor of the command    */    ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut)    {        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName());        if (it != this->consoleCommands_.end())        {            COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl;        }        this->bHasConsoleCommands_ = true;        this->consoleCommands_[command->getName()] = command;        this->consoleCommands_LC_[getLowercase(command->getName())] = command;        if (bCreateShortcut)            CommandExecutor::addConsoleCommandShortcut(command);        return (*command);    }    /**        @brief Returns the executor of a console command with given name.        @brief name The name of the requested console command        @return The executor of the requested console command    */    ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const    {        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);        if (it != this->consoleCommands_.end())            return (*it).second;        else            return 0;    }    /**        @brief Returns the executor of a console command with given name in lowercase.        @brief name The name of the requested console command in lowercae        @return The executor of the requested console command    */    ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const    {        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);        if (it != this->consoleCommands_LC_.end())            return (*it).second;        else            return 0;    }    /**        @brief Lists the names of all Identifiers in a std::set<const Identifier*>.        @param out The outstream        @param list The list (or set) of Identifiers        @return The outstream    */    std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)    {        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)            out << (*it)->getName() << " ";        return out;    }}
     195    }
     196
     197    /**
     198        @brief Returns true, if the assigned identifier is a direct parent of the given identifier.
     199        @param identifier The identifier to compare with
     200    */
     201    bool Identifier::isDirectParentOf(const Identifier* identifier) const
     202    {
     203        return (this->directChildren_->find(identifier) != this->directChildren_->end());
     204    }
     205
     206    /**
     207        @brief Returns the map that stores all Identifiers.
     208        @return The map
     209    */
     210    std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
     211    {
     212        static std::map<std::string, Identifier*> identifierMap;
     213        return identifierMap;
     214    }
     215
     216    /**
     217        @brief Returns the map that stores all Identifiers.
     218        @return The map
     219    */
     220    std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
     221    {
     222        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
     223        return lowercaseIdentifierMap;
     224    }
     225
     226    /**
     227        @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
     228        @param varname The name of the variablee
     229        @param container The container
     230    */
     231    void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
     232    {
     233        std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname);
     234        if (it != this->configValues_.end())
     235        {
     236            COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl;
     237        }
     238
     239        this->bHasConfigValues_ = true;
     240        this->configValues_[varname] = container;
     241        this->configValues_LC_[getLowercase(varname)] = container;
     242    }
     243
     244    /**
     245        @brief Returns the ConfigValueContainer of a variable, given by the string of its name.
     246        @param varname The name of the variable
     247        @return The ConfigValueContainer
     248    */
     249    ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname)
     250    {
     251        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
     252        if (it != configValues_.end())
     253            return ((*it).second);
     254        else
     255            return 0;
     256    }
     257
     258    /**
     259        @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.
     260        @param varname The name of the variable in lowercase
     261        @return The ConfigValueContainer
     262    */
     263    ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)
     264    {
     265        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
     266        if (it != configValues_LC_.end())
     267            return ((*it).second);
     268        else
     269            return 0;
     270    }
     271
     272    /**
     273        @brief Adds a new console command of this class.
     274        @param executor The executor of the command
     275        @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command
     276        @return The executor of the command
     277    */
     278    ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut)
     279    {
     280        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName());
     281        if (it != this->consoleCommands_.end())
     282        {
     283            COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl;
     284        }
     285
     286        this->bHasConsoleCommands_ = true;
     287        this->consoleCommands_[command->getName()] = command;
     288        this->consoleCommands_LC_[getLowercase(command->getName())] = command;
     289
     290        if (bCreateShortcut)
     291            CommandExecutor::addConsoleCommandShortcut(command);
     292
     293        return (*command);
     294    }
     295
     296    /**
     297        @brief Returns the executor of a console command with given name.
     298        @brief name The name of the requested console command
     299        @return The executor of the requested console command
     300    */
     301    ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const
     302    {
     303        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);
     304        if (it != this->consoleCommands_.end())
     305            return (*it).second;
     306        else
     307            return 0;
     308    }
     309
     310    /**
     311        @brief Returns the executor of a console command with given name in lowercase.
     312        @brief name The name of the requested console command in lowercae
     313        @return The executor of the requested console command
     314    */
     315    ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const
     316    {
     317        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);
     318        if (it != this->consoleCommands_LC_.end())
     319            return (*it).second;
     320        else
     321            return 0;
     322    }
     323
     324    /**
     325        @brief Lists the names of all Identifiers in a std::set<const Identifier*>.
     326        @param out The outstream
     327        @param list The list (or set) of Identifiers
     328        @return The outstream
     329    */
     330    std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
     331    {
     332        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
     333            out << (*it)->getName() << " ";
     334
     335        return out;
     336    }
     337}
  • code/branches/network/src/core/Identifier.h

    r1494 r1495  
    11/*
    22 *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net < *
     3 *                    > www.orxonox.net <
     4 *
    45 *
    56 *   License notice:
     
    6263#include "Debug.h"
    6364#include "Iterator.h"
    64 #include "MetaObjectList.h"#include "util/String.h"
     65#include "MetaObjectList.h"
     66#include "util/String.h"
     67
    6568namespace orxonox
    6669{
  • code/branches/network/src/core/InputBuffer.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Fabian 'x3n' Landau *   Co-authors: *      Reto Grieder * */#ifndef _InputBuffer_H__#define _InputBuffer_H__#include "CorePrereqs.h"#include <string>#include <list>#include "InputInterfaces.h"#include "OrxonoxClass.h"namespace orxonox{    class BaseInputBufferListenerTuple    {    public:        BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput,            bool trueKeyFalseChar, char _char, KeyCode::Enum key)            : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput),              trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key)        { }        virtual ~BaseInputBufferListenerTuple() { }        virtual void callFunction() = 0;        bool bListenToAllChanges_;        bool bOnlySingleInput_;        bool trueKeyFalseChar_;        char char_;        KeyCode::Enum key_;    };    template <class T>    class InputBufferListenerTuple : public BaseInputBufferListenerTuple    {    public:        InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges,            bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key)            : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key),              listener_(listener), function_(function)        { }
    2         virtual ~InputBufferListenerTuple() { }        void callFunction()        {            (listener_->*function_)();        }        T* listener_;        void (T::*function_)();    };    class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass    {        public:            InputBuffer();            InputBuffer(const std::string allowedChars);            void setConfigValues();            template <class T>            void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key)            {                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);                this->listeners_.insert(this->listeners_.end(), newTuple);            }            template <class T>            void unregisterListener(T* listener)            {                for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )                {                    InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it);                    if (refListener && refListener->listener_ == listener)                        this->listeners_.erase(it++);                    else                        it++;                }            }            void set(const std::string& input, bool update = true);            void insert(const std::string& input, bool update = true);            void insert(const char& input, bool update = true);            void clear(bool update = true);            void removeAtCursor(bool update = true);            void removeBehindCursor(bool update = true);            void updated();            void updated(const char& update, bool bSingleInput);            inline std::string get() const                { return this->buffer_; }            inline unsigned int getSize() const                { return this->buffer_.size(); }            inline unsigned int getCursorPosition() const                { return this->cursor_; }            inline void setCursorPosition(unsigned int cursor)                { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } }            inline void setCursorToEnd()                { this->cursor_ = this->buffer_.size(); }            inline void setCursorToBegin()                { this->cursor_ = 0; }            inline void increaseCursor()                { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } }            inline void decreaseCursor()                { if (this->cursor_ > 0) { --this->cursor_; } }        private:            bool charIsAllowed(const char& input);            void keyPressed (const KeyEvent& evt);            void keyReleased(const KeyEvent& evt) { }            void keyHeld    (const KeyEvent& evt);            void processKey (const KeyEvent &e);            void tickInput(float dt, const HandlerState& state);            std::string buffer_;            std::list<BaseInputBufferListenerTuple*> listeners_;            std::string allowedChars_;            unsigned int cursor_;            KeyCode::Enum lastKey_;            float timeSinceKeyPressed_;            float timeSinceKeyRepeated_;            int keysToRepeat_;            float keyRepeatDeleay_;            float keyRepeatTime_;    };}#endif /* _InputBuffer_H__ */
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Fabian 'x3n' Landau
     24 *   Co-authors:
     25 *      Reto Grieder
     26 *
     27 */
     28
     29#ifndef _InputBuffer_H__
     30#define _InputBuffer_H__
     31
     32#include "CorePrereqs.h"
     33
     34#include <string>
     35#include <list>
     36
     37#include "InputInterfaces.h"
     38#include "OrxonoxClass.h"
     39
     40namespace orxonox
     41{
     42    class BaseInputBufferListenerTuple
     43    {
     44    public:
     45        BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput,
     46            bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     47            : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput),
     48              trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key)
     49        { }
     50        virtual ~BaseInputBufferListenerTuple() { }
     51        virtual void callFunction() = 0;
     52        bool bListenToAllChanges_;
     53        bool bOnlySingleInput_;
     54        bool trueKeyFalseChar_;
     55        char char_;
     56        KeyCode::Enum key_;
     57    };
     58
     59    template <class T>
     60    class InputBufferListenerTuple : public BaseInputBufferListenerTuple
     61    {
     62    public:
     63        InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges,
     64            bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key)
     65            : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key),
     66              listener_(listener), function_(function)
     67        { }
     68        virtual ~InputBufferListenerTuple() { }
     69        void callFunction()
     70        {
     71            (listener_->*function_)();
     72        }
     73        T* listener_;
     74        void (T::*function_)();
     75    };
     76
     77    class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass
     78    {
     79        public:
     80            InputBuffer();
     81            InputBuffer(const std::string allowedChars);
     82
     83            void setConfigValues();
     84
     85            template <class T>
     86            void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput)
     87            {
     88                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);
     89                this->listeners_.insert(this->listeners_.end(), newTuple);
     90            }
     91            template <class T>
     92            void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput)
     93            {
     94                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned);
     95                this->listeners_.insert(this->listeners_.end(), newTuple);
     96            }
     97            template <class T>
     98            void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput)
     99            {
     100                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);
     101                this->listeners_.insert(this->listeners_.end(), newTuple);
     102            }
     103            template <class T>
     104            void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput)
     105            {
     106                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned);
     107                this->listeners_.insert(this->listeners_.end(), newTuple);
     108            }
     109
     110            template <class T>
     111            void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key)
     112            {
     113                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     114                this->listeners_.insert(this->listeners_.end(), newTuple);
     115            }
     116            template <class T>
     117            void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key)
     118            {
     119                InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key);
     120                this->listeners_.insert(this->listeners_.end(), newTuple);
     121            }
     122
     123            template <class T>
     124            void unregisterListener(T* listener)
     125            {
     126                for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); )
     127                {
     128                    InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it);
     129                    if (refListener && refListener->listener_ == listener)
     130                        this->listeners_.erase(it++);
     131                    else
     132                        it++;
     133                }
     134            }
     135
     136            void set(const std::string& input, bool update = true);
     137            void insert(const std::string& input, bool update = true);
     138            void insert(const char& input, bool update = true);
     139            void clear(bool update = true);
     140            void removeAtCursor(bool update = true);
     141            void removeBehindCursor(bool update = true);
     142
     143            void updated();
     144            void updated(const char& update, bool bSingleInput);
     145
     146            inline std::string get() const
     147                { return this->buffer_; }
     148            inline unsigned int getSize() const
     149                { return this->buffer_.size(); }
     150
     151            inline unsigned int getCursorPosition() const
     152                { return this->cursor_; }
     153            inline void setCursorPosition(unsigned int cursor)
     154                { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } }
     155            inline void setCursorToEnd()
     156                { this->cursor_ = this->buffer_.size(); }
     157            inline void setCursorToBegin()
     158                { this->cursor_ = 0; }
     159            inline void increaseCursor()
     160                { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } }
     161            inline void decreaseCursor()
     162                { if (this->cursor_ > 0) { --this->cursor_; } }
     163
     164        private:
     165            bool charIsAllowed(const char& input);
     166
     167            void keyPressed (const KeyEvent& evt);
     168            void keyReleased(const KeyEvent& evt) { }
     169            void keyHeld    (const KeyEvent& evt);
     170            void processKey (const KeyEvent &e);
     171
     172            void tickInput(float dt, const HandlerState& state);
     173
     174            std::string buffer_;
     175            std::list<BaseInputBufferListenerTuple*> listeners_;
     176            std::string allowedChars_;
     177            unsigned int cursor_;
     178
     179            KeyCode::Enum lastKey_;
     180            float timeSinceKeyPressed_;
     181            float timeSinceKeyRepeated_;
     182            int keysToRepeat_;
     183
     184            float keyRepeatDeleay_;
     185            float keyRepeatTime_;
     186    };
     187}
     188
     189#endif /* _InputBuffer_H__ */
  • code/branches/network/src/core/InputManager.cc

    r1494 r1495  
    4141#include "KeyBinder.h"
    4242#include "CommandExecutor.h"
    43 #include "ConsoleCommand.h"#include "Shell.h"
     43#include "ConsoleCommand.h"
     44#include "Shell.h"
     45
    4446namespace orxonox
    4547{
     
    150152      addKeyHandler(buffer_, "buffer");
    151153      Shell::getInstance().setInputBuffer(buffer_);
     154
    152155      keyBinder_ = new KeyBinder();
    153156      keyBinder_->loadBindings();
     
    194197        // register our listener in OIS.
    195198        keyboard_->setEventCallback(this);
    196         // note: OIS will not detect keys that have already been down when the keyboard was created.        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
     199        // note: OIS will not detect keys that have already been down when the keyboard was created.
     200        CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl;
    197201        return true;
    198202      }
     
    310314  void InputManager::setConfigValues()
    311315  {
    312     if (joySticksSize_)    {      std::vector<MultiTypeMath> coeffPos;
     316    if (joySticksSize_)
     317    {
     318      std::vector<MultiTypeMath> coeffPos;
    313319      std::vector<MultiTypeMath> coeffNeg;
    314320      std::vector<MultiTypeMath> zero;
     
    323329      }
    324330
    325       ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");      if (!cont)      {          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);          getIdentifier()->addConfigValueContainer("CoeffPos", cont);      }      cont->getValue(&coeffPos);      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");      if (!cont)      {          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);          getIdentifier()->addConfigValueContainer("CoeffNeg", cont);      }      cont->getValue(&coeffNeg);      cont = getIdentifier()->getConfigValueContainer("Zero");      if (!cont)      {          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);          getIdentifier()->addConfigValueContainer("Zero", cont);      }      cont->getValue(&zero);      // copy values to our own variables      for (unsigned int i = 0; i < 24; i++)      {        joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i];        joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i];        joySticksCalibration_[0].zeroStates[i]    = zero[i];      }    }  }
     331      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     332      if (!cont)
     333      {
     334          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);
     335          getIdentifier()->addConfigValueContainer("CoeffPos", cont);
     336      }
     337      cont->getValue(&coeffPos);
     338
     339      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     340      if (!cont)
     341      {
     342          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);
     343          getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
     344      }
     345      cont->getValue(&coeffNeg);
     346
     347      cont = getIdentifier()->getConfigValueContainer("Zero");
     348      if (!cont)
     349      {
     350          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);
     351          getIdentifier()->addConfigValueContainer("Zero", cont);
     352      }
     353      cont->getValue(&zero);
     354
     355      // copy values to our own variables
     356      for (unsigned int i = 0; i < 24; i++)
     357      {
     358        joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i];
     359        joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i];
     360        joySticksCalibration_[0].zeroStates[i]    = zero[i];
     361      }
     362    }
     363  }
    326364
    327365  /**
     
    624662      else
    625663        joySticksCalibration_[0].positiveCoeff[i] =  1.0f;
     664
    626665      // config value
    627       ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");      assert(cont);      cont->set(i, joySticksCalibration_[0].positiveCoeff[i]);      // negative coefficient
     666      ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
     667      assert(cont);
     668      cont->set(i, joySticksCalibration_[0].positiveCoeff[i]);
     669
     670      // negative coefficient
    628671      if (marginalsMin_[i] == INT_MAX)
    629672        marginalsMin_[i] = -32768;
    630673      // coefficients
    631674      if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i])
    632         joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]);      else        joySticksCalibration_[0].negativeCoeff[i] =  1.0f;      // config value
    633       cont = getIdentifier()->getConfigValueContainer("CoeffNeg");      assert(cont);      cont->set(i, joySticksCalibration_[0].negativeCoeff[i]);      // zero states
     675        joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]);
     676      else
     677        joySticksCalibration_[0].negativeCoeff[i] =  1.0f;
     678      // config value
     679      cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
     680      assert(cont);
     681      cont->set(i, joySticksCalibration_[0].negativeCoeff[i]);
     682
     683      // zero states
    634684      if (i < 8)
    635685      {
     
    647697      }
    648698      // config value
    649       cont = getIdentifier()->getConfigValueContainer("Zero");      assert(cont);      cont->set(i, joySticksCalibration_[0].zeroStates[i]);    }
     699      cont = getIdentifier()->getConfigValueContainer("Zero");
     700      assert(cont);
     701      cont->set(i, joySticksCalibration_[0].zeroStates[i]);
     702    }
    650703  }
    651704
  • code/branches/network/src/core/KeyBinder.cc

    r1494 r1495  
    4141#include "ConfigValueIncludes.h"
    4242#include "CoreIncludes.h"
    43 #include "CommandExecutor.h"#include "ConsoleCommand.h"#include "Executor.h"
     43#include "CommandExecutor.h"
     44#include "ConsoleCommand.h"
     45#include "Executor.h"
    4446// TODO: only needed by the CalibratorCallback class; move to new file
    4547#include "InputManager.h"
  • code/branches/network/src/core/Script_clean.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Benjamin Knecht *   Co-authors: *      ... * *//**
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Benjamin Knecht
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
    230 @file  script.h
    331 @brief Representation of an interface to lua
  • code/branches/network/src/core/SignalHandler.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Christoph Renner *   Co-authors: *      ... * */
    2 /**    @file SignalHandler.h    @brief Definition of the SignalHandler class.*/#ifndef _SignalHandler_H__
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Christoph Renner
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file SignalHandler.h
     31    @brief Definition of the SignalHandler class.
     32*/
     33
     34#ifndef _SignalHandler_H__
    335#define _SignalHandler_H__
    436
Note: See TracChangeset for help on using the changeset viewer.