- Timestamp:
- May 25, 2015, 10:56:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/command/ConsoleCommandManager.cc
r10354 r10484 39 39 namespace orxonox 40 40 { 41 /* static */ ConsoleCommandManager& ConsoleCommandManager::getInstance() 42 { 43 static ConsoleCommandManager instance; 44 return instance; 45 } 46 41 47 /** 42 48 @brief Returns the command with given group an name. … … 45 51 @param bPrintError If true, an error is printed if the command doesn't exist 46 52 */ 47 /* static */ConsoleCommand* ConsoleCommandManager::getCommand(const std::string& group, const std::string& name, bool bPrintError)53 ConsoleCommand* ConsoleCommandManager::getCommand(const std::string& group, const std::string& name, bool bPrintError) 48 54 { 49 55 // find the group 50 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommandMap().find(group);51 if (it_group != ConsoleCommandManager::getCommandMap().end())56 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = this->commandMap_.find(group); 57 if (it_group != this->commandMap_.end()) 52 58 { 53 59 // find the name … … 75 81 @param bPrintError If true, an error is printed if the command doesn't exist 76 82 */ 77 /* static */ConsoleCommand* ConsoleCommandManager::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)83 ConsoleCommand* ConsoleCommandManager::getCommandLC(const std::string& group, const std::string& name, bool bPrintError) 78 84 { 79 85 std::string groupLC = getLowercase(group); … … 81 87 82 88 // find the group 83 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommandMapLC().find(groupLC);84 if (it_group != ConsoleCommandManager::getCommandMapLC().end())89 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = this->commandMapLC_.find(groupLC); 90 if (it_group != this->commandMapLC_.end()) 85 91 { 86 92 // find the name … … 103 109 104 110 /** 105 @brief Returns the static map that stores all console commands.106 */107 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommandManager::getCommandMap()108 {109 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap;110 return commandMap;111 }112 113 /**114 @brief Returns the static map that stores all console commands in lowercase.115 */116 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommandManager::getCommandMapLC()117 {118 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC;119 return commandMapLC;120 }121 122 /**123 111 @brief Registers a new command with the groups and names that are defined by ConsoleCommand::getNames(). 124 112 */ 125 /* static */void ConsoleCommandManager::registerCommand(ConsoleCommand* command)113 void ConsoleCommandManager::registerCommand(ConsoleCommand* command) 126 114 { 127 115 for (size_t i = 0; i < command->getNames().size(); ++i) 128 116 { 129 117 const ConsoleCommand::CommandName& name = command->getNames()[i]; 130 ConsoleCommandManager::registerCommand(name.group_, name.name_, command);118 this->registerCommand(name.group_, name.name_, command); 131 119 } 132 120 } … … 135 123 @brief Registers a new command with given group an name by adding it to the command map. 136 124 */ 137 /* static */void ConsoleCommandManager::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command)125 void ConsoleCommandManager::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command) 138 126 { 139 127 if (name == "") … … 141 129 142 130 // check if a command with this name already exists 143 if ( ConsoleCommandManager::getCommand(group, name) != 0)131 if (this->getCommand(group, name) != 0) 144 132 { 145 133 if (group == "") … … 151 139 { 152 140 // add the command to the map 153 ConsoleCommandManager::getCommandMap()[group][name] = command;154 ConsoleCommandManager::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command;141 this->commandMap_[group][name] = command; 142 this->commandMapLC_[getLowercase(group)][getLowercase(name)] = command; 155 143 } 156 144 } … … 159 147 @brief Removes the command from the command map. 160 148 */ 161 /* static */void ConsoleCommandManager::unregisterCommand(ConsoleCommand* command)149 void ConsoleCommandManager::unregisterCommand(ConsoleCommand* command) 162 150 { 163 151 // iterate through all groups 164 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommandManager::getCommandMap().begin(); it_group != ConsoleCommandManager::getCommandMap().end(); )152 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = this->commandMap_.begin(); it_group != this->commandMap_.end(); ) 165 153 { 166 154 // iterate through all commands of each group … … 176 164 // erase the group if it is empty now 177 165 if (it_group->second.empty()) 178 ConsoleCommandManager::getCommandMap().erase(it_group++);166 this->commandMap_.erase(it_group++); 179 167 else 180 168 ++it_group; … … 184 172 185 173 // iterate through all groups 186 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommandManager::getCommandMapLC().begin(); it_group != ConsoleCommandManager::getCommandMapLC().end(); )174 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = this->commandMapLC_.begin(); it_group != this->commandMapLC_.end(); ) 187 175 { 188 176 // iterate through all commands of each group … … 198 186 // erase the group if it is empty now 199 187 if (it_group->second.empty()) 200 ConsoleCommandManager::getCommandMapLC().erase(it_group++);188 this->commandMapLC_.erase(it_group++); 201 189 else 202 190 ++it_group; … … 207 195 @brief Deletes all commands 208 196 */ 209 /* static */void ConsoleCommandManager::destroyAll()197 void ConsoleCommandManager::destroyAll() 210 198 { 211 199 // delete entries until the map is empty 212 while (! ConsoleCommandManager::getCommandMap().empty() && !ConsoleCommandManager::getCommandMap().begin()->second.empty())213 delete ConsoleCommandManager::getCommandMap().begin()->second.begin()->second;200 while (!this->commandMap_.empty() && !this->commandMap_.begin()->second.empty()) 201 delete this->commandMap_.begin()->second.begin()->second; 214 202 } 215 203 }
Note: See TracChangeset
for help on using the changeset viewer.