| 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(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(command) | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | namespace 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& setArgumentCompleter(unsigned int param, ArgumentCompleter* completer); | 
|---|
| 103 | ArgumentCompleter* getArgumentCompleter(unsigned int param) const; | 
|---|
| 104 |  | 
|---|
| 105 | 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 = ""); | 
|---|
| 106 | const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList() const | 
|---|
| 107 | { return this->argumentList_; } | 
|---|
| 108 | std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin() const | 
|---|
| 109 | { return this->argumentList_.begin(); } | 
|---|
| 110 | std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd() const | 
|---|
| 111 | { return this->argumentList_.end(); } | 
|---|
| 112 |  | 
|---|
| 113 | private: | 
|---|
| 114 | AccessLevel::Level accessLevel_; | 
|---|
| 115 | ArgumentCompleter* argumentCompleter_[5]; | 
|---|
| 116 | std::list<std::pair<std::string, std::string> > argumentList_; | 
|---|
| 117 | }; | 
|---|
| 118 |  | 
|---|
| 119 | inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "") | 
|---|
| 120 | { | 
|---|
| 121 | return new ConsoleCommand(functor, name); | 
|---|
| 122 | } | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | #endif /* _ConsoleCommand_H__ */ | 
|---|