Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/CommandEvaluation.h @ 1390

Last change on this file since 1390 was 1390, checked in by landauf, 16 years ago

only girls sleep at this time :P

(started new implementation of ConsoleExecutor parser, but it's still buggy)

File size: 5.8 KB
Line 
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
40namespace orxonox
41{
42    enum CommandState
43    {
44        CS_Uninitialized,
45        CS_Empty,
46        CS_ShortcutOrIdentifier,
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
60            void initialize(const std::string& command);
61
62            bool execute() const;
63            std::string complete() const;
64            std::string hint() const;
65            void evaluateParams();
66
67            bool isValid() const;
68
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& getOriginalTokens()
89                { return this->originalCommandTokens_; }
90            inline SubString& getTokens()
91                { return this->commandTokens_; }
92            inline void setTokens(const std::string& command)
93                { this->commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); }
94            inline const std::string& getError() const
95                { return this->errorMessage_; }
96            inline void setError(const std::string& error)
97                { this->errorMessage_ = error; }
98            inline bool isNewCommand() const
99                { return this->bNewCommand_; }
100            inline void setNewCommand(bool bNewCommand)
101                { this->bNewCommand_ = bNewCommand; }
102
103            inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleIdentifiers()
104                { return this->listOfPossibleIdentifiers_; }
105            inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleFunctions()
106                { return this->listOfPossibleFunctions_; }
107            inline std::list<std::pair<const std::string*, const std::string*> >& getListOfPossibleArguments()
108                { return this->listOfPossibleArguments_; }
109
110            inline void setAdditionalParameter(const std::string& param)
111                { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
112            inline std::string getAdditionalParameter() const
113                { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
114
115            void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
116            MultiTypeMath getEvaluatedParameter(unsigned int index) const;
117
118            bool hasReturnvalue() const;
119            MultiTypeMath getReturnvalue() const;
120
121        private:
122            unsigned int getStartindex() const;
123            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
124            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
125            static std::string dump(const ConsoleCommand* command);
126
127
128            bool bNewCommand_;
129
130            std::string originalCommand_;
131            std::string command_;
132            SubString originalCommandTokens_;
133            SubString commandTokens_;
134            std::string additionalParameter_;
135
136            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_;
137            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
138            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleArguments_;
139
140            Identifier* functionclass_;
141            ConsoleCommand* function_;
142
143            std::string errorMessage_;
144            CommandState state_;
145
146            bool bEvaluatedParams_;
147            MultiTypeMath param_[5];
148    };
149}
150
151#endif /* _CommandEvaluation_H__ */
Note: See TracBrowser for help on using the repository browser.