Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

changes in CommandExecutor and CommandEvaluation

File size: 3.5 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        friend class CommandExecutor;
58
59        public:
60            CommandEvaluation();
61
62            void initialize(const std::string& command);
63
64            bool execute() const;
65            std::string complete() const;
66            std::string hint() const;
67            void evaluateParams();
68
69            bool isValid() const;
70
71            inline void setAdditionalParameter(const std::string& param)
72                { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
73            inline std::string getAdditionalParameter() const
74                { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
75
76            void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
77            MultiTypeMath getEvaluatedParameter(unsigned int index) const;
78
79            bool hasReturnvalue() const;
80            MultiTypeMath getReturnvalue() const;
81
82        private:
83            unsigned int getStartindex() const;
84            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
85            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
86            static std::string dump(const ConsoleCommand* command);
87
88
89            bool bNewCommand_;
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<const std::string*, const std::string*> > listOfPossibleArguments_;
99
100            Identifier* functionclass_;
101            ConsoleCommand* function_;
102
103            std::string errorMessage_;
104            CommandState state_;
105
106            bool bEvaluatedParams_;
107            MultiTypeMath param_[5];
108    };
109}
110
111#endif /* _CommandEvaluation_H__ */
Note: See TracBrowser for help on using the repository browser.