Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/ConsoleCommand.h @ 1505

Last change on this file since 1505 was 1505, checked in by rgrieder, 16 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
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 */
28
29#ifndef _ConsoleCommand_H__
30#define _ConsoleCommand_H__
31
32#include "CorePrereqs.h"
33
34#include "Executor.h"
35#include "ClassManager.h"
36#include "CommandExecutor.h"
37#include "ArgumentCompletionFunctions.h"
38
39
40#define SetConsoleCommand(classname, function,  bCreateShortcut) \
41    SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut)
42
43#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
44    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
45
46
47#define SetConsoleCommandShortcut(classname, function) \
48    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function))
49
50#define SetConsoleCommandShortcutExtern(function) \
51    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function))
52
53#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
54    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command)
55
56
57namespace orxonox
58{
59    namespace AccessLevel
60    {
61        enum Level
62        {
63            None,
64            User,
65            Admin,
66            Offline,
67            Debug,
68            Disabled
69        };
70    }
71
72    class _CoreExport ConsoleCommand : public ExecutorStatic
73    {
74        public:
75            ConsoleCommand(FunctorStatic* functor, const std::string& name = "");
76
77            inline ConsoleCommand& setDescription(const std::string& description)
78                { this->ExecutorStatic::setDescription(description); return (*this); }
79            inline ConsoleCommand& setDescriptionParam(int param, const std::string& description)
80                { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); }
81            inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description)
82                { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); }
83            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1)
84                { this->ExecutorStatic::setDefaultValues(param1); return (*this); }
85            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
86                { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); }
87            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
88                { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); }
89            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
90                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); }
91            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
92                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
93            inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param)
94                { this->ExecutorStatic::setDefaultValue(index, param); return (*this); }
95
96            inline ConsoleCommand& setAccessLevel(AccessLevel::Level level)
97                { this->accessLevel_ = level; return (*this); }
98            inline AccessLevel::Level getAccessLevel() const
99                { return this->accessLevel_; }
100
101            ConsoleCommand& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer);
102            ArgumentCompleter* getArgumentCompleter(unsigned int param) const;
103
104            void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
105            const ArgumentCompletionList& getArgumentCompletionList() const
106                { return this->argumentList_; }
107            ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
108                { return this->argumentList_.begin(); }
109            ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
110                { return this->argumentList_.end(); }
111
112            inline ConsoleCommand& setKeybindMode(KeybindMode::Enum mode)
113                { this->keybindMode_ = mode; return *this; }
114            inline KeybindMode::Enum getKeybindMode() const
115                { return this->keybindMode_; }
116
117            inline ConsoleCommand& setAxisParamIndex(int index)
118                { this->axisParamIndex_ = index; return *this; }
119            inline int getAxisParamIndex() const
120                { return this->axisParamIndex_; }
121
122            inline ConsoleCommand& setIsAxisRelative(bool val)
123                { this->bAxisRelative_ = val; return *this; }
124            inline int getIsAxisRelative() const
125                { return this->bAxisRelative_; }
126
127        private:
128            AccessLevel::Level accessLevel_;
129            ArgumentCompleter* argumentCompleter_[5];
130            ArgumentCompletionList argumentList_;
131
132            KeybindMode::Enum keybindMode_;
133            int axisParamIndex_;
134            bool bAxisRelative_;
135    };
136
137    inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "")
138    {
139        return new ConsoleCommand(functor, name);
140    }
141}
142
143#endif /* _ConsoleCommand_H__ */
Note: See TracBrowser for help on using the repository browser.