Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/ConsoleCommand.h @ 1427

Last change on this file since 1427 was 1416, checked in by landauf, 17 years ago
  • fixed a bug in CommandExecutor
  • InGameConsole wraps now too long output lines and does something similar for the input line
File size: 5.7 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 "Identifier.h"
37#include "CommandExecutor.h"
38#include "ArgumentCompletionFunctions.h"
39
40
41#define SetConsoleCommand(classname, function,  bCreateShortcut) \
42    SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut)
43
44#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
45    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)command, bCreateShortcut)
46
47
48#define SetConsoleCommandShortcut(classname, function) \
49    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function))
50
51#define SetConsoleCommandShortcutExtern(function) \
52    SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function))
53
54#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
55    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)command)
56
57
58namespace orxonox
59{
60    namespace AccessLevel
61    {
62        enum Level
63        {
64            None,
65            User,
66            Admin,
67            Offline,
68            Debug,
69            Disabled
70        };
71    }
72
73    class _CoreExport ConsoleCommand : public ExecutorStatic
74    {
75        public:
76            ConsoleCommand(FunctorStatic* functor, const std::string& name = "");
77
78            inline ConsoleCommand& setDescription(const std::string& description)
79                { this->ExecutorStatic::setDescription(description); return (*this); }
80            inline ConsoleCommand& setDescriptionParam(int param, const std::string& description)
81                { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); }
82            inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description)
83                { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); }
84            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1)
85                { this->ExecutorStatic::setDefaultValues(param1); return (*this); }
86            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
87                { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); }
88            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
89                { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); }
90            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
91                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); }
92            inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
93                { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }
94            inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param)
95                { this->ExecutorStatic::setDefaultValue(index, param); return (*this); }
96
97            inline ConsoleCommand& setAccessLevel(AccessLevel::Level level)
98                { this->accessLevel_ = level; return (*this); }
99            inline AccessLevel::Level getAccessLevel() const
100                { return this->accessLevel_; }
101
102            ConsoleCommand& setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void));
103
104            const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList(unsigned int param);
105            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin(unsigned int param);
106            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd(unsigned int param);
107
108        private:
109            AccessLevel::Level accessLevel_;
110            std::list<std::pair<std::string, std::string> > (*autocompletionFunction_[5]) (void);
111            std::list<std::pair<std::string, std::string> > argumentList_;
112    };
113
114    inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "")
115    {
116        return new ConsoleCommand(functor, name);
117    }
118}
119
120#endif /* _ConsoleCommand_H__ */
Note: See TracBrowser for help on using the repository browser.