Orxonox  0.0.5 Codename: Arcturus
CommandEvaluation.h
Go to the documentation of this file.
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 
46 #ifndef _CommandEvaluation_H__
47 #define _CommandEvaluation_H__
48 
49 #include "core/CorePrereqs.h"
50 
51 #include <string>
52 
53 #include "util/SubString.h"
54 #include "util/MultiType.h"
56 #include "Functor.h"
57 
58 namespace orxonox
59 {
81  {
82  friend class CommandExecutor;
83 
84  public:
86 
87  int execute();
88  MultiType query(int* error = nullptr);
89 
90  std::string complete();
91  std::string hint();
92 
93  std::string getCommandSuggestion() const;
94 
95  int evaluateArguments(bool bPrintError = false);
96 
98  inline bool isValid() const
99  { return (this->execCommand_ != nullptr); }
100 
102  inline const ConsoleCommand* getConsoleCommand() const
103  { return this->execCommand_; }
104 
105  void setEvaluatedArgument(unsigned int index, const MultiType& arg);
106  MultiType getEvaluatedArgument(unsigned int index) const;
107 
116  { return this->possibleArguments_; }
117 
120  { return CommandEvaluation::getSize(this->possibleArguments_); }
121 
122  private:
123  void initialize(const std::string& command);
124 
125  unsigned int getNumberOfArguments() const;
126  const std::string& getLastArgument() const;
127  const std::string& getToken(unsigned int i) const;
128 
129  void retrievePossibleArguments();
130 
131  static void strip(ArgumentCompletionList& list, const std::string& fragment);
132  static size_t getSize(const ArgumentCompletionList& list);
133 
134  static std::string dump(const ArgumentCompletionList& list);
135  static std::string dump(const ConsoleCommand* command);
136 
137  static std::string getCommonBegin(const ArgumentCompletionList& list);
138 
143  unsigned int execArgumentsOffset_;
144  unsigned int hintArgumentsOffset_;
147 
152  };
153 }
154 
155 #endif /* _CommandEvaluation_H__ */
unsigned int hintArgumentsOffset_
The index of the first argument in tokens_ used to display hints and argument lists.
Definition: CommandEvaluation.h:144
bool isValid() const
Returns true if the command evaluation contains a valid command that can be executed.
Definition: CommandEvaluation.h:98
const ConsoleCommand * execCommand_
The command that will be executed (can be nullptr if the command is not valid)
Definition: CommandEvaluation.h:139
unsigned int execArgumentsOffset_
The index of the first argument in tokens_ used to execute the command.
Definition: CommandEvaluation.h:143
void error(const std::string &text)
Prints output with error level.
Definition: ConsoleCommandCompilation.cc:145
Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functio...
The ConsoleCommand class stores all information about a console command which can be executed by Comm...
Definition: ConsoleCommand.h:88
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
SubString tokens_
The single words of the command string, split into tokens.
Definition: CommandEvaluation.h:141
const ConsoleCommand * getConsoleCommand() const
Returns the console command that was evaluated by this object.
Definition: CommandEvaluation.h:102
void strip(std::string *str)
Removes all whitespaces from a string.
Definition: StringUtils.cc:55
This class is used to execute and evaluate command-strings.
Definition: CommandExecutor.h:109
const ArgumentCompletionList & getPossibleArguments() const
Returns a list of possible arguments for the given command.
Definition: CommandEvaluation.h:115
std::string string_
The original command string, entered by the user in the shell.
Definition: CommandEvaluation.h:142
bool bTriedToEvaluatedArguments_
True if an attempt was started to evaluate the arguments (but not necessarily successful) ...
Definition: CommandEvaluation.h:149
A helper class to split a string into several tokens.
ArgumentCompletionList possibleArguments_
List of possible arguments for the command in the current state.
Definition: CommandEvaluation.h:146
A class that splits a string into multiple tokens using different options.
Definition: SubString.h:101
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Declaration of the MultiType and some helper constructs.
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI() command(const std::string &fragment)
Returns a list of commands and groups and also supports auto-completion of the arguments of these com...
Definition: ArgumentCompletionFunctions.cc:178
CommandEvaluation is used to gather information about a command and to evaluate its arguments...
Definition: CommandEvaluation.h:80
unsigned int numberOfEvaluatedArguments_
The number of evaluated arguments (ranges from 0 to MAX_FUNCTOR_ARGUMENTS)
Definition: CommandEvaluation.h:150
#define _CoreExport
Definition: CorePrereqs.h:61
The MultiType can hold a value of many possible types and convert them to other types.
Definition: MultiType.h:130
static size_t getSize(const ArgumentCompletionList &list)
Returns the size of an argument completion list - empty ("") arguments are not counted.
Definition: CommandEvaluation.cc:428
size_t getPossibleArgumentsSize() const
Returns the number of possible arguments. Empty ("") arguments are not counted.
Definition: CommandEvaluation.h:119
const ConsoleCommand * hintCommand_
The command that is used to display hints and argument lists (can be different to execCommand_ in som...
Definition: CommandEvaluation.h:140
std::list< ArgumentCompletionListElement > ArgumentCompletionList
Definition: ArgumentCompletionListElement.h:49
const unsigned int MAX_FUNCTOR_ARGUMENTS
The maximum number of parameters of a function that is supported by Functor.
Definition: Functor.h:127
bool bEvaluatedArguments_
True if the arguments of the command have been evaluated (and stored in arguments_) ...
Definition: CommandEvaluation.h:148
bool bPossibleArgumentsRetrieved_
True if the list of possible arguments was already retrieved.
Definition: CommandEvaluation.h:145
Definition of ArgumentCompletionList, which is used in argument completion functions, and its element.