Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/bugger/src/core/CommandExecutor.h @ 2560

Last change on this file since 2560 was 2344, checked in by rgrieder, 16 years ago

Completed destruction of static elements like XMLPort, Identifier, etc.
Of initially about 250 memory leaks (not in the actual meaning but the memory was never freed anyway) only 1 remains in TinyCpp.

  • Core class is now a normal Singleton that gets created and destroyed in main.
  • The same goes for Language, LuaBind, SignalHandler and PlayerManager.
  • Added a new std::set to the CommandExecutor so that the external ConsoleCommands can get destroyed too.
  • Code for destroying CommandLineArguments
  • Added destruction code for ConstructionCallbacks in Identifier
  • Moved internal identifier map (the one with the typeid(.) names) in a static function in Identifier. This was necessary in order to destroy ALL Identifiers with the static destruction function. Before it was possible to create an Identifier with having a class instance (that would call RegisterObject) for instance by simply accessing it via getIdentifier.
  • Removed a big memory leak in Button (forgot to destroy the ConfigValueContainers)
  • Added destruction code for InputBufferListenerTuples in InputBuffer destructor.
  • Added destruction code for load and save executors in both XMLPortParam and XMLPortObject
  • Added destruction code for ConsoleCommands in GSRoot, GSGraphics and GSLevel (temporary solution anyway)
  • Deleting the CEGUILua script module seems to work properly now, one memory leak less (GUIManager.cc)
  • Added global destruction calls in Main.cc
  • Property svn:eol-style set to native
File size: 5.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 _CommandExecutor_H__
30#define _CommandExecutor_H__
31
32#include "CorePrereqs.h"
33
34#include <map>
35
36#include "CommandEvaluation.h"
37
38namespace orxonox // tolua_export
39{ // tolua_export
40    class _CoreExport CommandExecutor
41    /*
42    class CommandExecutor { // tolua_export
43    */
44    {
45        public:
46            static bool execute(const std::string& command, bool useTcl = true); // tolua_export
47            static std::string complete(const std::string& command);
48            static std::string hint(const std::string& command);
49
50            static CommandEvaluation evaluate(const std::string& command);
51            static const CommandEvaluation& getLastEvaluation();
52
53            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
54            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
55            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
56
57            /** @brief Returns the map that stores all console commands. @return The const_iterator */
58            static inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_; }
59            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
60            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_.begin(); }
61            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
62            static inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_.end(); }
63
64            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
65            static inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandShortcutMap() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_; }
66            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
67            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapBegin() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.begin(); }
68            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
69            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
70
71            static void destroyExternalCommands();
72
73        private:
74            CommandExecutor() {}
75            CommandExecutor(const CommandExecutor& other);
76            ~CommandExecutor() {}
77
78            static CommandExecutor& getInstance();
79            static CommandEvaluation& getEvaluation();
80
81            static void parseIfNeeded(const std::string& command);
82            static void parse(const std::string& command, bool bInitialize = true);
83
84            static unsigned int argumentsFinished();
85            static unsigned int argumentsGiven();
86            static bool enoughArgumentsGiven(ConsoleCommand* command);
87            static std::string getArgument(unsigned int index);
88            static std::string getLastArgument();
89
90            static void createListOfPossibleIdentifiers(const std::string& fragment);
91            static void createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier = 0);
92            static void createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param);
93
94            static Identifier* getPossibleIdentifier(const std::string& name);
95            static ConsoleCommand* getPossibleCommand(const std::string& name, Identifier* identifier = 0);
96            static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
97
98            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
99            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
100            static std::string getCommonBegin(const ArgumentCompletionList& list);
101
102            CommandEvaluation evaluation_;
103            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
104            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
105            std::set<ConsoleCommand*>              consoleCommandExternals_;
106    }; // tolua_export
107} // tolua_export
108
109#endif /* _CommandExecutor_H__ */
Note: See TracBrowser for help on using the repository browser.