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, |
---|
46 | CS_ShortcutOrIdentifier, |
---|
47 | CS_Function, |
---|
48 | CS_ParamPreparation, |
---|
49 | CS_Params, |
---|
50 | CS_Finished, |
---|
51 | CS_Error |
---|
52 | }; |
---|
53 | |
---|
54 | class _CoreExport CommandEvaluation |
---|
55 | { |
---|
56 | friend class CommandExecutor; |
---|
57 | |
---|
58 | public: |
---|
59 | CommandEvaluation(); |
---|
60 | |
---|
61 | void initialize(const std::string& command); |
---|
62 | |
---|
63 | bool execute() const; |
---|
64 | std::string complete(); |
---|
65 | std::string hint() const; |
---|
66 | void evaluateParams(); |
---|
67 | |
---|
68 | bool isValid() const; |
---|
69 | |
---|
70 | inline void setAdditionalParameter(const std::string& param) |
---|
71 | { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; } |
---|
72 | inline std::string getAdditionalParameter() const |
---|
73 | { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } |
---|
74 | |
---|
75 | void setEvaluatedParameter(unsigned int index, MultiTypeMath param); |
---|
76 | MultiTypeMath getEvaluatedParameter(unsigned int index) const; |
---|
77 | |
---|
78 | bool hasReturnvalue() const; |
---|
79 | MultiTypeMath getReturnvalue() const; |
---|
80 | |
---|
81 | private: |
---|
82 | unsigned int getStartindex() const; |
---|
83 | static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); |
---|
84 | static std::string dump(const std::list<std::pair<std::string, std::string> >& list); |
---|
85 | static std::string dump(const ConsoleCommand* command); |
---|
86 | |
---|
87 | |
---|
88 | bool bNewCommand_; |
---|
89 | bool bCommandChanged_; |
---|
90 | |
---|
91 | std::string originalCommand_; |
---|
92 | std::string command_; |
---|
93 | SubString commandTokens_; |
---|
94 | std::string additionalParameter_; |
---|
95 | |
---|
96 | std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_; |
---|
97 | std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_; |
---|
98 | std::list<std::pair<std::string, std::string> > listOfPossibleArguments_; |
---|
99 | |
---|
100 | Identifier* functionclass_; |
---|
101 | ConsoleCommand* function_; |
---|
102 | std::string possibleArgument_; |
---|
103 | std::string argument_; |
---|
104 | |
---|
105 | std::string errorMessage_; |
---|
106 | CommandState state_; |
---|
107 | |
---|
108 | bool bEvaluatedParams_; |
---|
109 | MultiTypeMath param_[5]; |
---|
110 | }; |
---|
111 | } |
---|
112 | |
---|
113 | #endif /* _CommandEvaluation_H__ */ |
---|