Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

CommandExecutor seems to work very well right now. yet to come: autocompletion lists

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_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 ConsoleCommand* command);
85
86
87            bool bNewCommand_;
88            bool bCommandChanged_;
89
90            std::string originalCommand_;
91            std::string command_;
92            SubString commandTokens_;
93            std::string additionalParameter_;
94
95            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_;
96            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
97            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleArguments_;
98
99            Identifier* functionclass_;
100            ConsoleCommand* function_;
101            std::string possibleArgument_;
102            std::string argument_;
103
104            std::string errorMessage_;
105            CommandState state_;
106
107            bool bEvaluatedParams_;
108            MultiTypeMath param_[5];
109    };
110}
111
112#endif /* _CommandEvaluation_H__ */
Note: See TracBrowser for help on using the repository browser.