[1341] | 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 _CommandEvaluation_H__ |
---|
| 30 | #define _CommandEvaluation_H__ |
---|
| 31 | |
---|
| 32 | #include "CorePrereqs.h" |
---|
| 33 | |
---|
| 34 | #include <string> |
---|
| 35 | #include <list> |
---|
| 36 | |
---|
| 37 | #include "util/SubString.h" |
---|
| 38 | #include "util/MultiTypeMath.h" |
---|
| 39 | |
---|
| 40 | namespace orxonox |
---|
| 41 | { |
---|
| 42 | enum CommandState |
---|
| 43 | { |
---|
| 44 | CS_Uninitialized, |
---|
| 45 | CS_Empty, |
---|
[1390] | 46 | CS_ShortcutOrIdentifier, |
---|
[1341] | 47 | CS_Shortcut_Params, |
---|
| 48 | CS_Shortcut_Finished, |
---|
| 49 | CS_Function, |
---|
| 50 | CS_Function_Params, |
---|
| 51 | CS_Function_Finished, |
---|
| 52 | CS_Error |
---|
| 53 | }; |
---|
| 54 | |
---|
| 55 | class _CoreExport CommandEvaluation |
---|
| 56 | { |
---|
| 57 | public: |
---|
| 58 | CommandEvaluation(); |
---|
| 59 | |
---|
[1351] | 60 | void initialize(const std::string& command); |
---|
| 61 | |
---|
[1390] | 62 | bool execute() const; |
---|
[1351] | 63 | std::string complete() const; |
---|
| 64 | std::string hint() const; |
---|
| 65 | void evaluateParams(); |
---|
| 66 | |
---|
[1341] | 67 | bool isValid() const; |
---|
| 68 | |
---|
[1351] | 69 | inline Identifier* getIdentifier() const |
---|
| 70 | { return this->functionclass_; } |
---|
| 71 | inline void setIdentifier(Identifier* identifier) |
---|
| 72 | { this->functionclass_ = identifier; } |
---|
| 73 | inline ConsoleCommand* getFunction() const |
---|
| 74 | { return this->function_; } |
---|
| 75 | inline void setFunction(ConsoleCommand* command) |
---|
| 76 | { this->function_ = command; } |
---|
| 77 | |
---|
| 78 | inline const std::string& getOriginalCommand() const |
---|
| 79 | { return this->originalCommand_; } |
---|
| 80 | inline const std::string& getCommand() const |
---|
| 81 | { return this->command_; } |
---|
| 82 | inline void setCommand(const std::string& command) |
---|
| 83 | { this->command_ = command; } |
---|
| 84 | inline const CommandState& getState() const |
---|
| 85 | { return this->state_; } |
---|
| 86 | inline void setState(CommandState state) |
---|
| 87 | { this->state_ = state; } |
---|
| 88 | inline SubString& getTokens() |
---|
| 89 | { return this->commandTokens_; } |
---|
| 90 | inline void setTokens(const std::string& command) |
---|
| 91 | { this->commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); } |
---|
| 92 | inline const std::string& getError() const |
---|
| 93 | { return this->errorMessage_; } |
---|
| 94 | inline void setError(const std::string& error) |
---|
| 95 | { this->errorMessage_ = error; } |
---|
| 96 | inline bool isNewCommand() const |
---|
| 97 | { return this->bNewCommand_; } |
---|
| 98 | inline void setNewCommand(bool bNewCommand) |
---|
| 99 | { this->bNewCommand_ = bNewCommand; } |
---|
| 100 | |
---|
[1390] | 101 | inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleIdentifiers() |
---|
| 102 | { return this->listOfPossibleIdentifiers_; } |
---|
[1351] | 103 | inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleFunctions() |
---|
| 104 | { return this->listOfPossibleFunctions_; } |
---|
[1390] | 105 | inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleArguments() |
---|
| 106 | { return this->listOfPossibleArguments_; } |
---|
[1351] | 107 | |
---|
[1341] | 108 | inline void setAdditionalParameter(const std::string& param) |
---|
| 109 | { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; } |
---|
| 110 | inline std::string getAdditionalParameter() const |
---|
| 111 | { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } |
---|
| 112 | |
---|
| 113 | void setEvaluatedParameter(unsigned int index, MultiTypeMath param); |
---|
| 114 | MultiTypeMath getEvaluatedParameter(unsigned int index) const; |
---|
| 115 | |
---|
| 116 | bool hasReturnvalue() const; |
---|
| 117 | MultiTypeMath getReturnvalue() const; |
---|
| 118 | |
---|
| 119 | private: |
---|
[1351] | 120 | unsigned int getStartindex() const; |
---|
| 121 | static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); |
---|
| 122 | static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); |
---|
| 123 | static std::string dump(const ConsoleCommand* command); |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | bool bNewCommand_; |
---|
| 127 | |
---|
| 128 | std::string originalCommand_; |
---|
| 129 | std::string command_; |
---|
| 130 | SubString commandTokens_; |
---|
[1341] | 131 | std::string additionalParameter_; |
---|
| 132 | |
---|
[1390] | 133 | std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_; |
---|
[1341] | 134 | std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_; |
---|
[1390] | 135 | std::list<std::pair<const std::string*, const std::string*> > listOfPossibleArguments_; |
---|
[1341] | 136 | |
---|
| 137 | Identifier* functionclass_; |
---|
| 138 | ConsoleCommand* function_; |
---|
| 139 | |
---|
| 140 | std::string errorMessage_; |
---|
| 141 | CommandState state_; |
---|
| 142 | |
---|
| 143 | bool bEvaluatedParams_; |
---|
| 144 | MultiTypeMath param_[5]; |
---|
| 145 | }; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | #endif /* _CommandEvaluation_H__ */ |
---|