Changeset 1341 for code/branches/console/src/core/CommandExecutor.h
- Timestamp:
- May 21, 2008, 1:33:42 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandExecutor.h
r1255 r1341 32 32 #include "CorePrereqs.h" 33 33 34 #include <string>35 34 #include <map> 36 #include <list>37 35 38 #include "util/SubString.h" 39 #include "util/MultiTypeMath.h" 36 #include "CommandEvaluation.h" 40 37 41 38 #define COMMAND_EXECUTOR_CURSOR "$" … … 43 40 namespace orxonox 44 41 { 45 enum CommandState46 {47 CS_Uninitialized,48 CS_Empty,49 CS_FunctionClass_Or_Shortcut_Or_Keyword,50 CS_Shortcut_Params,51 CS_Shortcut_Finished,52 CS_Function,53 CS_Function_Params,54 CS_Function_Finished,55 CS_ConfigValueClass,56 CS_ConfigValue,57 CS_ConfigValueType,58 CS_ConfigValueFinished,59 CS_KeybindKey,60 CS_KeybindCommand,61 CS_KeybindFinished,62 CS_Error63 };64 65 void source(const std::string& filename);66 std::string echo(const std::string& text);67 void puts(bool newline, const std::string& test);68 69 void write(const std::string& filename, const std::string& text);70 void append(const std::string& filename, const std::string& text);71 std::string read(const std::string& filename);72 73 enum KeybindMode {}; // temporary74 75 ///////////////////////76 // CommandEvaluation //77 ///////////////////////78 class _CoreExport CommandEvaluation79 {80 friend class CommandExecutor;81 82 public:83 CommandEvaluation();84 85 KeybindMode getKeybindMode();86 bool isValid() const;87 88 inline void setAdditionalParameter(const std::string& param)89 { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }90 inline std::string getAdditionalParameter() const91 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }92 93 void setEvaluatedParameter(unsigned int index, MultiTypeMath param);94 MultiTypeMath getEvaluatedParameter(unsigned int index) const;95 96 void evaluateParams();97 98 bool hasReturnvalue() const;99 MultiTypeMath getReturnvalue() const;100 101 private:102 std::string processedCommand_;103 SubString tokens_;104 std::string additionalParameter_;105 106 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctionClasses_;107 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleShortcuts_;108 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;109 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValueClasses_;110 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleConfigValues_;111 std::list<std::pair<const std::string*, const std::string*> > listOfPossibleKeys_;112 113 Identifier* functionclass_;114 Identifier* configvalueclass_;115 ExecutorStatic* shortcut_;116 ExecutorStatic* function_;117 ConfigValueContainer* configvalue_;118 ConfigValueContainer* key_;119 120 std::string errorMessage_;121 CommandState state_;122 123 bool bEvaluatedParams_;124 MultiTypeMath param_[5];125 ExecutorStatic* evaluatedExecutor_;126 };127 128 /////////////////////129 // CommandExecutor //130 /////////////////////131 42 class _CoreExport CommandExecutor 132 43 { … … 145 56 static const CommandEvaluation& getLastEvaluation(); 146 57 147 static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);148 static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);149 static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);58 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command); 59 static ConsoleCommand* getConsoleCommandShortcut(const std::string& name); 60 static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name); 150 61 151 62 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 152 static inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }63 static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; } 153 64 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 154 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }65 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); } 155 66 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 156 static inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }67 static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); } 157 68 158 69 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 159 static inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }70 static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; } 160 71 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 161 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }72 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); } 162 73 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 163 static inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }74 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 164 75 165 76 private: … … 191 102 192 103 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 193 static std::string dump(const ExecutorStatic* executor);104 static std::string dump(const ConsoleCommand* command); 194 105 static std::string dump(const ConfigValueContainer* container); 195 106 … … 197 108 198 109 static Identifier* getIdentifierOfPossibleFunctionClass(const std::string& name); 199 static ExecutorStatic* getExecutorOfPossibleShortcut(const std::string& name);200 static ExecutorStatic* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier);110 static ConsoleCommand* getExecutorOfPossibleShortcut(const std::string& name); 111 static ConsoleCommand* getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier); 201 112 static Identifier* getIdentifierOfPossibleConfigValueClass(const std::string& name); 202 113 static ConfigValueContainer* getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier); … … 205 116 CommandEvaluation evaluation_; 206 117 207 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_;208 std::map<std::string, ExecutorStatic*> consoleCommandShortcuts_LC_;118 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_; 119 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_; 209 120 }; 210 121 }
Note: See TracChangeset
for help on using the changeset viewer.