Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands3/src/libraries/core/CommandEvaluation.h @ 7201

Last change on this file since 7201 was 7189, checked in by landauf, 14 years ago

changed passing of the returnvalue in the command execution pipeline:

  • Functor: operator() directly returns the returnvalue of the executed function (if any, otherwise a MultiType whose null() function evaluates to true). The returnvalue is no longer stored in the Functor.
  • Executor: The same behavior of operator() like in Functor. Additionally the parse() function returns the returnvalue of the executed function instead of a boolean status. The status can be retrieved by passing a pointer to a bool to the function.
  • CommandExecutor: execute() works like before (returns only a boolean status), but added a new function query() which returns the returnvalue of the executed command. The status of query() can be retrieved by optionally passing an pointer to a bool.
  • CommandEvaluation: same as for CommandExecutor: execute() like before, added query()
  • TclBind::eval() returns the returnvalue of the evaluated tcl command. The status can also be retrieved by passing a pointer to a bool.
  • The Shell prints the returnvalue (if available) of an executed command
  • added a constructor to MultiType to directly create it from an mbool. The mbool will be converted to a bool, so it loses it's internal state.
  • Property svn:eol-style set to native
File size: 3.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 "ArgumentCompletionListElement.h"
38#include "util/SubString.h"
39#include "util/MultiType.h"
40
41namespace orxonox
42{
43    namespace CommandState
44    {
45        enum Value
46        {
47            Uninitialized,
48            Empty,
49            ShortcutOrIdentifier,
50            Function,
51            ParamPreparation,
52            Params,
53            Finished,
54            Error
55        };
56    }
57
58    class _CoreExport CommandEvaluation
59    {
60        friend class CommandExecutor;
61
62        public:
63            CommandEvaluation();
64
65            void initialize(const std::string& command);
66
67            bool execute() const;
68            MultiType query(bool* success = 0) const;
69
70            const std::string& complete();
71            std::string hint() const;
72            void evaluateParams();
73
74            bool isValid() const;
75
76            inline ConsoleCommand* getConsoleCommand() const
77                { return this->function_; }
78            inline const std::string& getOriginalCommand() const
79                { return this->originalCommand_; }
80            inline const std::string& getCommand() const
81                { return this->command_; }
82
83            inline void setAdditionalParameter(const std::string& param)
84                { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
85            inline std::string getAdditionalParameter() const
86                { return (!this->additionalParameter_.empty()) ? (' ' + this->additionalParameter_) : ""; }
87
88            void setEvaluatedParameter(unsigned int index, MultiType param);
89            MultiType getEvaluatedParameter(unsigned int index) const;
90
91        private:
92            unsigned int getStartindex() const;
93            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
94            static std::string dump(const ArgumentCompletionList& list);
95            static std::string dump(const ConsoleCommand* command);
96
97
98            bool bNewCommand_;
99            bool bCommandChanged_;
100
101            std::string originalCommand_;
102            std::string command_;
103            SubString commandTokens_;
104            std::string additionalParameter_;
105
106            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_;
107            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
108            ArgumentCompletionList listOfPossibleArguments_;
109
110            Identifier* functionclass_;
111            ConsoleCommand* function_;
112            std::string possibleArgument_;
113            std::string argument_;
114
115            std::string errorMessage_;
116            CommandState::Value state_;
117
118            bool bEvaluatedParams_;
119            MultiType param_[5];
120    };
121}
122
123#endif /* _CommandEvaluation_H__ */
Note: See TracBrowser for help on using the repository browser.