Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

finally got a good approach for the CommandExecutor parser. more to come.

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