[10346] | 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 | /** |
---|
| 30 | @defgroup ConsoleCommand Console commands |
---|
| 31 | @ingroup Command |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #ifndef _ConsoleCommandManager_H__ |
---|
| 35 | #define _ConsoleCommandManager_H__ |
---|
| 36 | |
---|
| 37 | #include "core/CorePrereqs.h" |
---|
| 38 | |
---|
[10542] | 39 | #include "util/Singleton.h" |
---|
| 40 | |
---|
[10346] | 41 | namespace orxonox |
---|
| 42 | { |
---|
| 43 | /** |
---|
[10484] | 44 | * A singleton that stores all existing ConsoleCommands. |
---|
[10346] | 45 | */ |
---|
[10542] | 46 | class _CoreExport ConsoleCommandManager : public Singleton<ConsoleCommandManager> |
---|
[10346] | 47 | { |
---|
[10542] | 48 | friend class Singleton<ConsoleCommandManager>; |
---|
| 49 | |
---|
[10346] | 50 | public: |
---|
[10484] | 51 | void registerCommand(ConsoleCommand* command); |
---|
| 52 | void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command); |
---|
| 53 | void unregisterCommand(ConsoleCommand* command); |
---|
| 54 | |
---|
[10346] | 55 | /// Returns the map with all groups and commands. |
---|
[10484] | 56 | inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands() |
---|
| 57 | { return this->commandMap_; } |
---|
[10346] | 58 | /// Returns the map with all groups and commands in lowercase. |
---|
[10484] | 59 | inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC() |
---|
| 60 | { return this->commandMapLC_; } |
---|
[10346] | 61 | |
---|
| 62 | /// Returns a command (shortcut) with given name. @param name The name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist |
---|
[10484] | 63 | inline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false) |
---|
| 64 | { return this->getCommand("", name, bPrintError); } |
---|
[10346] | 65 | /// Returns a command (shortcut) with given name in lowercase. @param name The lowercase name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist |
---|
[10484] | 66 | inline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false) |
---|
| 67 | { return this->getCommandLC("", name, bPrintError); } |
---|
[10346] | 68 | |
---|
[10484] | 69 | ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false); |
---|
| 70 | ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false); |
---|
[10346] | 71 | |
---|
| 72 | private: |
---|
[10484] | 73 | std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap_; |
---|
| 74 | std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC_; |
---|
[10542] | 75 | |
---|
| 76 | static ConsoleCommandManager* singletonPtr_s; |
---|
[10346] | 77 | }; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | #endif /* _ConsoleCommandManager_H__ */ |
---|