Orxonox  0.0.5 Codename: Arcturus
CommandExecutor.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 
85 #ifndef _CommandExecutor_H__
86 #define _CommandExecutor_H__
87 
88 #include "core/CorePrereqs.h"
89 
90 #include <map>
91 #include <list>
92 #include <string>
93 
94 #include "util/MultiType.h"
95 #include "CommandEvaluation.h"
96 
97 // tolua_begin
98 namespace orxonox
99 {
110  {
111 // tolua_end
112  public:
113  static int execute(const std::string& command, bool useTcl = true, bool printErrors = true); // tolua_export
114 
115  static MultiType queryMT(const std::string& command, int* error = nullptr, bool useTcl = true);
116  static std::string query(const std::string& command, int* error = NULL, bool useTcl = true); // tolua_export
117 
118  static CommandEvaluation evaluate(const std::string& command);
119 
120  static constexpr int Success = 0;
121  static constexpr int Inexistent = 1;
122  static constexpr int Incomplete = 2;
123  static constexpr int Deactivated = 3;
124  static constexpr int Denied = 4;
125  static constexpr int Error = 5;
126 
127  static std::string getErrorDescription(int error);
128 
129  static MultiType unhide(const std::string& command);
130  static void alias(const std::string& alias, const std::string& command);
131  static void _autocomplete(const std::string& group, const std::string& name) {}
132 
133  private:
134  CommandExecutor() = default;
135  ~CommandExecutor() = default;
136 
137  // non-copyable:
138  CommandExecutor(const CommandExecutor&) = delete;
139  CommandExecutor& operator=(const CommandExecutor&) = delete;
140 
141  static CommandExecutor& getInstance();
142 
143  bool getCached(const std::string& command, CommandEvaluation& evaluation);
144  void cache(const std::string& command, const CommandEvaluation& evaluation);
145 
147  struct CacheEntry
148  {
150  std::list<std::string>::iterator iterator_;
151  };
152 
153  std::map<std::string, CacheEntry> cache_;
154  std::list<std::string> cachelist_;
155  }; // tolua_export
156 } // tolua_export
157 
158 #endif /* _CommandExecutor_H__ */
void error(const std::string &text)
Prints output with error level.
Definition: ConsoleCommandCompilation.cc:145
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
CommandEvaluation evaluation_
The command evaluation which is stored in the cache.
Definition: CommandExecutor.h:149
Declaration of the orxonox::CommandEvaluation class which is returned by orxonox::CommandExecutor::ev...
This class is used to execute and evaluate command-strings.
Definition: CommandExecutor.h:109
std::map< std::string, CacheEntry > cache_
A map that connects command strings and evaluated commands in the cache.
Definition: CommandExecutor.h:153
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
#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
std::list< std::string > cachelist_
A list used to sort the elements in the cache by their age.
Definition: CommandExecutor.h:154
Helper struct, used to store cached entries.
Definition: CommandExecutor.h:147
std::list< std::string >::iterator iterator_
The iterator of the corresponding element in cachelist_, used for faster access.
Definition: CommandExecutor.h:150
static void _autocomplete(const std::string &group, const std::string &name)
Pseudo console command used whenever no real command is available. In these cases this command provid...
Definition: CommandExecutor.h:131