[Orxonox-commit 2472] r7179 - in code/branches/consolecommands3: . src/libraries/core src/libraries/util

landauf at orxonox.net landauf at orxonox.net
Wed Aug 18 15:39:02 CEST 2010


Author: landauf
Date: 2010-08-18 15:39:01 +0200 (Wed, 18 Aug 2010)
New Revision: 7179

Added:
   code/branches/consolecommands3/src/libraries/util/VA_NARGS.h
Modified:
   code/branches/consolecommands3/
   code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
   code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
   code/branches/consolecommands3/src/libraries/core/Functor.h
   code/branches/consolecommands3/src/libraries/core/LuaState.h
   code/branches/consolecommands3/src/libraries/util/Convert.h
Log:
merged consolecommands2 to consolecommands3


Property changes on: code/branches/consolecommands3
___________________________________________________________________
Modified: svn:mergeinfo
   - /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/menu:5941-6146,6148
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network64:2210-2355
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
   + /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/menu:5941-6146,6148
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network64:2210-2355
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890

Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	2010-08-18 13:28:12 UTC (rev 7178)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	2010-08-18 13:39:01 UTC (rev 7179)
@@ -27,6 +27,7 @@
  */
 
 #include "ConsoleCommand.h"
+#include <cassert>
 
 namespace orxonox
 {
@@ -70,3 +71,191 @@
             this->argumentList_.clear();
     }
 }
+
+#include "BaseObject.h" // remove this
+
+namespace orxonox
+{
+    _SetConsoleCommand("BaseObject", "setName", &BaseObject::setName, (BaseObject*)0);
+    _ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive));
+
+    _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
+    {
+        this->state_ = state;
+        _ConsoleCommand::registerCommand(group, name, this);
+    }
+
+    _ConsoleCommand& _ConsoleCommand::addShortcut()
+    {
+        _ConsoleCommand::registerCommand("", this->getName(), this);
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::addShortcut(const std::string&  name)
+    {
+        _ConsoleCommand::registerCommand("", name, this);
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::addGroup(const std::string& group)
+    {
+        _ConsoleCommand::registerCommand(group, this->getName(), this);
+        return *this;
+    }
+
+    _ConsoleCommand& _ConsoleCommand::addGroup(const std::string& group, const std::string&  name)
+    {
+        _ConsoleCommand::registerCommand(group, name, this);
+        return *this;
+    }
+
+    void _ConsoleCommand::setActive(bool bActive)
+    {
+        if (bActive)
+        {
+            if (this->state_ == State::Inactive)
+                this->state_ = State::Active;
+            else if (this->state_ == State::UninitializedInactive)
+                this->state_ = State::UninitializedActive;
+        }
+        else
+        {
+            if (this->state_ == State::Active)
+                this->state_ = State::Inactive;
+            else if (this->state_ == State::UninitializedActive)
+                this->state_ = State::UninitializedInactive;
+        }
+    }
+
+    void _ConsoleCommand::setInitialized(bool bInitialized)
+    {
+        if (bInitialized)
+        {
+            if (this->state_ == State::UninitializedActive)
+                this->state_ = State::Active;
+            else if (this->state_ == State::UninitializedInactive)
+                this->state_ = State::Inactive;
+        }
+        else
+        {
+            if (this->state_ == State::Active)
+                this->state_ = State::UninitializedActive;
+            else if (this->state_ == State::Inactive)
+                this->state_ = State::UninitializedInactive;
+        }
+    }
+
+    void _ConsoleCommand::setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode)
+    {
+        if (!functor)
+        {
+            this->setInitialized(false);
+            return;
+        }
+
+        if (!this->functionHeaderMatches(functor))
+        {
+            COUT(1) << "Error: Couldn't assign new function to console command with name \"" << this->getName() << "\", headers don't match." << std::endl;
+            return;
+        }
+
+        switch (mode)
+        {
+            default:
+            case _ConsoleCommand::ObjectPointer::Null:
+            {
+                this->functor_ = functor;
+            }
+            break;
+
+            case _ConsoleCommand::ObjectPointer::RawCopy:
+            {
+                void* object = (this->functor_) ? this->functor_->getRawObjectPointer() : 0;
+
+                this->functor_ = functor;
+
+                if (!this->functor_->getBaseObject())
+                    this->functor_->setRawObjectPointer(object);
+            }
+            break;
+
+            case _ConsoleCommand::ObjectPointer::CastViaBaseObject:
+            {
+                BaseObject* object = (this->functor_) ? this->functor_->getBaseObject() : 0;
+
+                this->functor_ = functor;
+
+                if (!this->functor_->getBaseObject())
+                    this->functor_->setBaseObject(object);
+            }
+            break;
+        }
+    }
+
+    bool _ConsoleCommand::functionHeaderMatches(Functor* functor) const
+    {
+        if (!this->functor_)
+        {
+            assert(false);
+            return false;
+        }
+        return (functor->getHeaderIdentifier() == this->functor_->getHeaderIdentifier());
+    }
+
+    void _ConsoleCommand::setObject(void* object)
+    {
+        if (this->functor_)
+            this->functor_->setRawObjectPointer(object);
+    }
+
+    void _ConsoleCommand::setObject(BaseObject* object)
+    {
+        if (this->functor_)
+            this->functor_->setBaseObject(object);
+    }
+
+    /* static */ const _ConsoleCommand* _ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
+    {
+        std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMap().find(group);
+        if (it_group != _ConsoleCommand::getCommandMap().end())
+        {
+            std::map<std::string, _ConsoleCommand*>::const_iterator it_name = it_group->second.find(name);
+            if (it_name != it_group->second.end())
+            {
+                return it_name->second;
+            }
+        }
+        if (bPrintError)
+        {
+            if (group == "")
+                COUT(0) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl;
+            else
+                COUT(0) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl;
+        }
+        return 0;
+    }
+
+    /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMap()
+    {
+        static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMap;
+        return commandMap;
+    }
+
+    /* static */ void _ConsoleCommand::registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command)
+    {
+        if (name == "")
+            return;
+
+        if (_ConsoleCommand::getCommand(group, name) != 0)
+        {
+            if (group == "")
+                COUT(2) << "Warning: A console command with shortcut name \"" << name << "\" already exists." << std::endl;
+            else
+                COUT(2) << "Warning: A console command with group \"" << group << "\" and name \"" << name << "\" already exists." << std::endl;
+        }
+        else
+        {
+            _ConsoleCommand::getCommandMap()[group][name] = command;
+        }
+    }
+}

Modified: code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	2010-08-18 13:28:12 UTC (rev 7178)
+++ code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	2010-08-18 13:39:01 UTC (rev 7179)
@@ -32,7 +32,9 @@
 #include "CorePrereqs.h"
 
 #include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/facilities/expand.hpp>
 
+#include "util/VA_NARGS.h"
 #include "ArgumentCompletionFunctions.h"
 #include "CommandExecutor.h"
 #include "Executor.h"
@@ -154,4 +156,160 @@
     }
 }
 
+
+#define _SetConsoleCommand(...) \
+    BOOST_PP_EXPAND(BOOST_PP_CAT(_SetConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
+#define _SetConsoleCommand2(name, functionpointer) \
+    _SetConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer))
+#define _SetConsoleCommand3(group, name, functionpointer) \
+    _SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer))
+#define _SetConsoleCommand4(group, name, functionpointer, object) \
+    _SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object))
+
+#define _SetConsoleCommandGeneric(group, name, functor) \
+    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, functor))
+
+
+#define _DeclareConsoleCommand(...) \
+    BOOST_PP_CAT(_DeclareConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)
+#define _DeclareConsoleCommand2(name, functionpointer) \
+    _DeclareConsoleCommandGeneric("", name, functionpointer)
+#define _DeclareConsoleCommand3(group, name, functionpointer) \
+    _DeclareConsoleCommandGeneric(group, name, functionpointer)
+
+#define _DeclareConsoleCommandGeneric(group, name, functionpointer) \
+    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), orxonox::_ConsoleCommand::State::UninitializedActive))
+
+
+#define _ModifyConsoleCommand(...) \
+    orxonox::_ConsoleCommand::getCommand(__VA_ARGS__, true)->getManipulator()
+
+
+namespace orxonox
+{
+    class _CoreExport _ConsoleCommand : protected Executor
+    {
+        friend struct _ConsoleCommandManipulator;
+
+        public:
+            struct State
+            {
+                enum Enum
+                {
+                    UninitializedActive,
+                    UninitializedInactive,
+                    Active,
+                    Inactive
+                };
+            };
+
+            struct ObjectPointer
+            {
+                enum Enum
+                {
+                    Null,
+                    RawCopy,
+                    CastViaBaseObject
+                };
+            };
+
+            struct _ConsoleCommandManipulator
+            {
+                public:
+                    _ConsoleCommandManipulator(const _ConsoleCommand* command) : command_(const_cast<_ConsoleCommand*>(command)) {}
+
+                    template <class F>
+                    inline _ConsoleCommandManipulator& setFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
+                        { if (this->command_) { this->command_->setFunctor(createFunctor(function), mode); } return *this; }
+                    template <class F, class O>
+                    inline _ConsoleCommandManipulator& setFunction(F function, O* object)
+                        { if (this->command_) { this->command_->setFunctor(createFunctor(function, object)); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(Functor* functor)
+                        { if (this->command_) { this->command_->setFunctor(functor); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommand* command)
+                        { if (this->command_) { this->command_->setFunctor(command->functor_); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommandManipulator& manipulator)
+                        { if (this->command_) { this->command_->setFunctor(manipulator.command_->functor_); } return *this; }
+
+                    template <class F>
+                    inline _ConsoleCommandManipulator& pushFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
+                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function), mode); } return *this; }
+                    template <class F, class O>
+                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object)
+                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object)); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(Functor* functor)
+                        { if (this->command_) { this->command_->pushFunctor(functor); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommand* command)
+                        { if (this->command_) { this->command_->pushFunctor(command->functor_); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommandManipulator& manipulator)
+                        { if (this->command_) { this->command_->pushFunctor(manipulator.command_->functor_); } return *this; }
+
+                    inline _ConsoleCommandManipulator& popFunction()
+                        { if (this->command_) { this->command_->popFunctor(); } return *this; }
+
+                    inline _ConsoleCommandManipulator& setObject(void* object)
+                        { if (this->command_) { this->command_->setObject(object); } return *this; }
+                    inline _ConsoleCommandManipulator& setObject(BaseObject* object)
+                        { if (this->command_) { this->command_->setObject(object); } return *this; }
+
+                    inline _ConsoleCommandManipulator& setActive(bool bActive)
+                        { if (this->command_) { this->command_->setActive(bActive); } return *this; }
+
+                private:
+                    _ConsoleCommand* command_;
+            };
+
+        public:
+            _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state = State::Active);
+
+            _ConsoleCommand& addShortcut();
+            _ConsoleCommand& addShortcut(const std::string&  name);
+            _ConsoleCommand& addGroup(const std::string& group);
+            _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
+
+            void setActive(bool bActive);
+            inline State::Enum getState() const
+                { return this->state_; }
+            inline bool isActive() const
+                { return (this->state_ == State::Active); }
+
+            static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
+                { return _ConsoleCommand::getCommandMap(); }
+
+            static inline const _ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)
+                { return _ConsoleCommand::getCommand("", name, bPrintError); }
+            static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
+
+            inline _ConsoleCommandManipulator getManipulator() const
+                { return this; }
+
+        private:
+            static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
+            static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
+
+            void setInitialized(bool bInitialized);
+
+            void setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
+            void pushFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
+            void popFunctor();
+            bool functionHeaderMatches(Functor* functor) const;
+
+            void setObject(void* object);
+            void setObject(BaseObject* object);
+
+            State::Enum state_;
+            const std::type_info& functionHeader_;
+    };
+
+    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
+    {
+        return new _ConsoleCommand("", name, functor, state);
+    }
+
+    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
+    {
+        return new _ConsoleCommand(group, name, functor, state);
+    }
+}
+
 #endif /* _ConsoleCommand_H__ */

Modified: code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-18 13:28:12 UTC (rev 7178)
+++ code/branches/consolecommands3/src/libraries/core/Functor.h	2010-08-18 13:39:01 UTC (rev 7179)
@@ -30,10 +30,14 @@
 #ifndef _Functor_H__
 #define _Functor_H__
 
+#include <typeinfo>
+
 #include "CorePrereqs.h"
 
+#include "util/Convert.h"
 #include "util/Debug.h"
 #include "util/MultiType.h"
+#include "BaseObject.h"
 
 namespace orxonox
 {
@@ -111,6 +115,15 @@
 
             virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
 
+            virtual void setBaseObject(BaseObject* object) {}
+            virtual void setBaseObject(const BaseObject* object) {}
+            virtual BaseObject* getBaseObject() const { return 0; }
+
+            virtual void setRawObjectPointer(void* object) {}
+            virtual void* getRawObjectPointer() const { return 0; }
+
+            virtual const std::type_info& getHeaderIdentifier() const = 0;
+
         protected:
             unsigned int numParams_;
             bool hasReturnValue_;
@@ -169,6 +182,40 @@
                 return this;
             }
 
+            void setBaseObject(BaseObject* object)
+            {
+                this->bConstObject_ = false;
+                this->object_ = dynamic_cast<T*>(object);
+            }
+
+            void setBaseObject(const BaseObject* object)
+            {
+                this->bConstObject_ = true;
+                this->constObject_ = dynamic_cast<const T*>(object);
+            }
+
+            BaseObject* getBaseObject() const
+            {
+                if (this->bConstObject_)
+                    return const_cast<BaseObject*>(upcast<const BaseObject*>(this->constObject_));
+                else
+                    return upcast<BaseObject*>(this->object_);
+            }
+
+            void setRawObjectPointer(void* object)
+            {
+                this->bConstObject_ = false;
+                this->object_ = (T*)object;
+            }
+
+            void* getRawObjectPointer() const
+            {
+                if (this->bConstObject_)
+                    return (void*)this->constObject_;
+                else
+                    return (void*)this->object_;
+            }
+
             typedef std::pair<T*, const T*> Objects;
 
             inline Objects getObjects() const
@@ -189,6 +236,18 @@
 
 
 
+    template <int r, class R, class P1, class P2, class P3, class P4, class P5>
+    struct FunctorHeaderIdentifier {};
+
+
+
+    inline Functor* createFunctor(Functor* functor)
+    {
+        return functor;
+    }
+
+
+
 #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams, additionalobject) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams(additionalobject)
 #define FUNCTOR_TEMPLATE000(additionalobject)
 #define FUNCTOR_TEMPLATE001(additionalobject) template <class P1>
@@ -293,6 +352,20 @@
 
 
 
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams) FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES##numparams(returnvalue)
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES0(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), void, void, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES1(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, void, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES2(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES3(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES4(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES5(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, P5>
+
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue) FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE##returnvalue
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE0 void
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE1 R
+
+
+
 #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
 #define FUNCTOR_EVALUATE_PARAM0
 #define FUNCTOR_EVALUATE_PARAM1 \
@@ -319,7 +392,6 @@
 
 
 
-
 #define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \
     FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \
     class FunctorStatic##returnvalue##numparams : public FunctorStatic \
@@ -341,11 +413,16 @@
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \
     \
-            virtual void evaluateParam(unsigned int index, MultiType& param) const \
+            void evaluateParam(unsigned int index, MultiType& param) const \
             { \
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            const std::type_info& getHeaderIdentifier() const \
+            { \
+                return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \
+            } \
+    \
         private: \
             FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     }; \
@@ -385,11 +462,16 @@
                 COUT(1) << "Error: Function is not const." << std::endl; \
             } \
     \
-            virtual void evaluateParam(unsigned int index, MultiType& param) const \
+            void evaluateParam(unsigned int index, MultiType& param) const \
             { \
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            const std::type_info& getHeaderIdentifier() const \
+            { \
+                return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \
+            } \
+    \
         private: \
             FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     }; \
@@ -417,11 +499,16 @@
                 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
             } \
     \
-            virtual void evaluateParam(unsigned int index, MultiType& param) const \
+            void evaluateParam(unsigned int index, MultiType& param) const \
             { \
                 FUNCTOR_EVALUATE_PARAM(numparams); \
             } \
     \
+            const std::type_info& getHeaderIdentifier() const \
+            { \
+                return typeid(FunctorHeaderIdentifier FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams)); \
+            } \
+    \
         private: \
             FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \
     }; \
@@ -458,6 +545,7 @@
     }
 
 
+
 // disable annoying warning about forcing value to boolean
 #ifdef ORXONOX_COMPILER_MSVC
 #pragma warning(push)

Modified: code/branches/consolecommands3/src/libraries/core/LuaState.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-18 13:28:12 UTC (rev 7178)
+++ code/branches/consolecommands3/src/libraries/core/LuaState.h	2010-08-18 13:39:01 UTC (rev 7179)
@@ -53,6 +53,7 @@
             LuaFunctor(const std::string& code, LuaState* luaState);
             void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null);
             void evaluateParam(unsigned int index, MultiType& param) const {}
+            const std::type_info& getHeaderIdentifier() const { return typeid(this); }
 
         private:
             std::string code_;

Modified: code/branches/consolecommands3/src/libraries/util/Convert.h
===================================================================
--- code/branches/consolecommands3/src/libraries/util/Convert.h	2010-08-18 13:28:12 UTC (rev 7178)
+++ code/branches/consolecommands3/src/libraries/util/Convert.h	2010-08-18 13:39:01 UTC (rev 7179)
@@ -115,6 +115,34 @@
                 return false;
         }
     };
+
+    ////////////
+    // upcast //
+    ////////////
+    namespace detail
+    {
+        // perform a static cast if ToType is a base of FromType
+        template<class ToType, class FromType>
+        FORCEINLINE ToType upcast(FromType input, detail::Int2Type<true>)
+        {
+            return static_cast<ToType>(input);
+        }
+
+        // return zero if ToType is not a base of FromType
+        template<class ToType, class FromType>
+        FORCEINLINE ToType upcast(FromType input, detail::Int2Type<false>)
+        {
+            return 0;
+        }
+    }
+
+    // performs an upcast if ToType is a base of FromType, returns zero otherwise
+    template <class ToType, class FromType>
+    FORCEINLINE ToType upcast(FromType input)
+    {
+        enum { probe = ImplicitConversion<FromType, ToType>::exists };
+        return detail::upcast<ToType, FromType>(input, detail::Int2Type<probe>());
+    }
 }
 
 

Copied: code/branches/consolecommands3/src/libraries/util/VA_NARGS.h (from rev 7178, code/branches/consolecommands2/src/libraries/util/VA_NARGS.h)
===================================================================
--- code/branches/consolecommands3/src/libraries/util/VA_NARGS.h	                        (rev 0)
+++ code/branches/consolecommands3/src/libraries/util/VA_NARGS.h	2010-08-18 13:39:01 UTC (rev 7179)
@@ -0,0 +1,61 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro.
+*/
+
+#include <boost/preprocessor/facilities/expand.hpp>
+
+/**
+    @brief Returns the number of arguments passed to a variadic macro. Important: The number of arguments must be greater than zero (ORXONOX_VA_NARGS() returns 1).
+*/
+#define ORXONOX_VA_NARGS(...) \
+    ORXONOX_VA_NARGS_CONCAT(__VA_ARGS__, ORXONOX_VA_NARGS_NUMBERS)
+
+
+// some helper macros //
+
+#define ORXONOX_VA_NARGS_CONCAT(...) \
+    BOOST_PP_EXPAND(ORXONOX_VA_NARGS_INTERN(__VA_ARGS__))
+
+#define ORXONOX_VA_NARGS_INTERN( \
+    arg1,  arg2,  arg3,  arg4,  arg5,  arg6,  arg7,  arg8,  arg9,  arg10, \
+    arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, \
+    arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, \
+    arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, \
+    arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48, arg49, arg50, \
+    arg51, arg52, arg53, arg54, arg55, arg56, arg57, arg58, arg59, arg60, \
+    arg61, arg62, arg63, argn, ...) argn
+
+#define ORXONOX_VA_NARGS_NUMBERS \
+    63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, \
+    47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, \
+    31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, \
+    15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0




More information about the Orxonox-commit mailing list