- Timestamp:
- Aug 25, 2010, 7:07:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
r7215 r7216 37 37 38 38 #include "util/VA_NARGS.h" 39 #include "core/Identifier.h"40 39 #include "ArgumentCompletionFunctions.h" 41 #include "CommandExecutor.h"42 40 #include "Executor.h" 43 44 45 #define SetConsoleCommand(classname, function, bCreateShortcut) \46 SetConsoleCommandGeneric(classname, function, #function, bCreateShortcut)47 #define SetConsoleCommandAlias(classname, function, name, bCreateShortcut) \48 SetConsoleCommandGeneric(classname, function, name, bCreateShortcut)49 50 #define SetConsoleCommandGeneric(classname, function, name, bCreateShortcut) \51 orxonox::ConsoleCommand& BOOST_PP_CAT(classname##function##consolecommand__, __LINE__) = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name), bCreateShortcut)52 53 54 #define SetConsoleCommandShortcut(classname, function) \55 SetConsoleCommandShortcutAliasGeneric(classname, function, #function)56 #define SetConsoleCommandShortcutAlias(classname, function, name) \57 SetConsoleCommandShortcutAliasGeneric(classname, function, name)58 #define SetConsoleCommandShortcutAliasGeneric(classname, function, name) \59 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), name))60 61 #define SetConsoleCommandShortcutExtern(function) \62 SetConsoleCommandShortcutExternAliasGeneric(function, #function)63 #define SetConsoleCommandShortcutExternAlias(function, name) \64 SetConsoleCommandShortcutExternAliasGeneric(function, name)65 #define SetConsoleCommandShortcutExternAliasGeneric(function, name) \66 SetConsoleCommandShortcutGeneric(BOOST_PP_CAT(function##consolecommand__, __LINE__), orxonox::createConsoleCommand(orxonox::createFunctor(&function), name))67 68 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \69 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)70 71 72 namespace orxonox73 {74 namespace AccessLevel75 {76 enum Value77 {78 None,79 User,80 Admin,81 Offline,82 Debug,83 Disabled84 };85 }86 87 class _CoreExport ConsoleCommand : public Executor88 {89 public:90 ConsoleCommand(const FunctorPtr& functor, const std::string& name = "");91 92 ConsoleCommand& description(const std::string& description);93 const std::string& getDescription() const;94 95 ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);96 const std::string& getDescriptionParam(unsigned int param) const;97 98 ConsoleCommand& descriptionReturnvalue(const std::string& description);99 const std::string& getDescriptionReturnvalue(int param) const;100 101 inline ConsoleCommand& defaultValues(const MultiType& param1)102 { this->Executor::setDefaultValues(param1); return (*this); }103 inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2)104 { this->Executor::setDefaultValues(param1, param2); return (*this); }105 inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)106 { this->Executor::setDefaultValues(param1, param2, param3); return (*this); }107 inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)108 { this->Executor::setDefaultValues(param1, param2, param3, param4); return (*this); }109 inline ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)110 { this->Executor::setDefaultValues(param1, param2, param3, param4, param5); return (*this); }111 inline ConsoleCommand& defaultValue(unsigned int index, const MultiType& param)112 { this->Executor::setDefaultValue(index, param); return (*this); }113 114 inline ConsoleCommand& accessLevel(AccessLevel::Value level)115 { this->accessLevel_ = level; return (*this); }116 inline AccessLevel::Value getAccessLevel() const117 { return this->accessLevel_; }118 119 ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer);120 ArgumentCompleter* getArgumentCompleter(unsigned int param) const;121 122 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 = "");123 const ArgumentCompletionList& getArgumentCompletionList() const124 { return this->argumentList_; }125 ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const126 { return this->argumentList_.begin(); }127 ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const128 { return this->argumentList_.end(); }129 130 inline ConsoleCommand& setAsInputCommand()131 {132 this->keybindMode(KeybindMode::OnHold);133 this->defaultValue(0, Vector2(0.0f, 0.0f));134 this->inputConfiguredParam(0);135 return *this;136 }137 138 inline ConsoleCommand& keybindMode(KeybindMode::Value mode)139 { this->keybindMode_ = mode; return *this; }140 inline KeybindMode::Value getKeybindMode() const141 { return this->keybindMode_; }142 143 inline ConsoleCommand& inputConfiguredParam(int index)144 { this->inputConfiguredParam_ = index; return *this; }145 inline int getInputConfiguredParam_() const146 { return this->inputConfiguredParam_; }147 148 private:149 AccessLevel::Value accessLevel_;150 ArgumentCompleter* argumentCompleter_[5];151 ArgumentCompletionList argumentList_;152 153 KeybindMode::Value keybindMode_;154 int inputConfiguredParam_;155 156 LanguageEntryLabel description_;157 LanguageEntryLabel descriptionReturnvalue_;158 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];159 };160 161 inline ConsoleCommand* createConsoleCommand(const FunctorPtr& functor, const std::string& name = "")162 {163 return new ConsoleCommand(functor, name);164 }165 }166 41 167 42 … … 452 327 static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false); 453 328 329 static void destroyAll(); 330 454 331 private: 455 332 static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
Note: See TracChangeset
for help on using the changeset viewer.