- Timestamp:
- May 25, 2015, 10:56:26 PM (9 years ago)
- Location:
- code/branches/core7/src/libraries/core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/Core.cc
r10483 r10484 250 250 safeObjectDelete(&languageInstance_); 251 251 safeObjectDelete(&configFileManager_); 252 ConsoleCommandManager:: destroyAll();252 ConsoleCommandManager::getInstance().destroyAll(); 253 253 Context::setRootContext(NULL); 254 254 IdentifierManager::getInstance().destroyAllIdentifiers(); -
code/branches/core7/src/libraries/core/command/ArgumentCompletionFunctions.cc
r10347 r10484 99 99 100 100 // get all the groups that are visible (except the shortcut group "") 101 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommandManager::get Commands();101 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommandManager::getInstance().getCommands(); 102 102 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 103 103 if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0)) … … 138 138 139 139 // find the iterator of the given group 140 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::get Commands().begin();141 for ( ; it_group != ConsoleCommandManager::get Commands().end(); ++it_group)140 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().begin(); 141 for ( ; it_group != ConsoleCommandManager::getInstance().getCommands().end(); ++it_group) 142 142 if (getLowercase(it_group->first) == groupLC) 143 143 break; 144 144 145 145 // add all commands in the group to the list 146 if (it_group != ConsoleCommandManager::get Commands().end())146 if (it_group != ConsoleCommandManager::getInstance().getCommands().end()) 147 147 { 148 148 for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) … … 207 207 return detail::_groupsandcommands(fragment, true); 208 208 209 if (ConsoleCommandManager::get CommandLC(getLowercase(tokens[0])))209 if (ConsoleCommandManager::getInstance().getCommandLC(getLowercase(tokens[0]))) 210 210 return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment); 211 211 212 212 if (tokens.size() == 1) 213 213 { 214 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::get Commands().find(tokens[0]);215 if (it_group != ConsoleCommandManager::get Commands().end())214 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommands().find(tokens[0]); 215 if (it_group != ConsoleCommandManager::getInstance().getCommands().end()) 216 216 return detail::_subcommands(fragment, tokens[0], true); 217 217 else … … 219 219 } 220 220 221 if (ConsoleCommandManager::get CommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))221 if (ConsoleCommandManager::getInstance().getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1]))) 222 222 return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment); 223 223 -
code/branches/core7/src/libraries/core/command/CommandEvaluation.cc
r10347 r10484 306 306 // the user typed 1-2 arguments, check what he tried to type and print a suitable error 307 307 std::string groupLC = getLowercase(this->getToken(0)); 308 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::get CommandsLC().begin(); it_group != ConsoleCommandManager::getCommandsLC().end(); ++it_group)308 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group) 309 309 if (it_group->first == groupLC) 310 310 return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\"."; … … 328 328 329 329 // iterate through all groups and their commands and calculate the distance to the current command. keep the best. 330 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::get CommandsLC().begin(); it_group != ConsoleCommandManager::getCommandsLC().end(); ++it_group)330 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().begin(); it_group != ConsoleCommandManager::getInstance().getCommandsLC().end(); ++it_group) 331 331 { 332 332 if (it_group->first != "") … … 346 346 347 347 // now also iterate through all shortcuts and keep the best if it's better than the one found above. 348 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::get CommandsLC().find("");349 if (it_group != ConsoleCommandManager::get CommandsLC().end())348 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getInstance().getCommandsLC().find(""); 349 if (it_group != ConsoleCommandManager::getInstance().getCommandsLC().end()) 350 350 { 351 351 for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name) -
code/branches/core7/src/libraries/core/command/CommandExecutor.cc
r10355 r10484 155 155 156 156 // assign the fallback-command to get hints about the possible commands and groups 157 evaluation.hintCommand_ = ConsoleCommandManager::get Command(__CC_CommandExecutor_name, __CC_autocomplete_name);157 evaluation.hintCommand_ = ConsoleCommandManager::getInstance().getCommand(__CC_CommandExecutor_name, __CC_autocomplete_name); 158 158 159 159 // check if there's at least one argument … … 161 161 { 162 162 // try to get a command from the first token 163 evaluation.execCommand_ = ConsoleCommandManager::get CommandLC(evaluation.getToken(0));163 evaluation.execCommand_ = ConsoleCommandManager::getInstance().getCommandLC(evaluation.getToken(0)); 164 164 if (evaluation.execCommand_) 165 165 evaluation.execArgumentsOffset_ = 1; … … 167 167 { 168 168 // try to get a command from the first two tokens 169 evaluation.execCommand_ = ConsoleCommandManager::get CommandLC(evaluation.getToken(0), evaluation.getToken(1));169 evaluation.execCommand_ = ConsoleCommandManager::getInstance().getCommandLC(evaluation.getToken(0), evaluation.getToken(1)); 170 170 if (evaluation.execCommand_) 171 171 evaluation.execArgumentsOffset_ = 2; … … 288 288 289 289 // check if the alias already exists - print an error and return if it does 290 if ((tokens.size() == 1 && ConsoleCommandManager::get Command(tokens[0])) || (tokens.size() == 2 && ConsoleCommandManager::getCommand(tokens[0], tokens[1])))290 if ((tokens.size() == 1 && ConsoleCommandManager::getInstance().getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommandManager::getInstance().getCommand(tokens[0], tokens[1]))) 291 291 { 292 292 orxout(user_error) << "A command with name \"" << alias << "\" already exists." << endl; … … 296 296 // create a new console command with the given alias as its name 297 297 if (tokens.size() == 1) 298 ConsoleCommandManager:: registerCommand(new ConsoleCommand(tokens[0], executor));298 ConsoleCommandManager::getInstance().registerCommand(new ConsoleCommand(tokens[0], executor)); 299 299 else if (tokens.size() == 2) 300 ConsoleCommandManager:: registerCommand(new ConsoleCommand(tokens[0], tokens[1], executor));300 ConsoleCommandManager::getInstance().registerCommand(new ConsoleCommand(tokens[0], tokens[1], executor)); 301 301 else 302 302 orxout(user_error) << "\"" << alias << "\" is not a valid alias name (must have one or two words)." << endl; -
code/branches/core7/src/libraries/core/command/ConsoleCommand.cc
r10352 r10484 92 92 ConsoleCommand::~ConsoleCommand() 93 93 { 94 ConsoleCommandManager:: unregisterCommand(this);94 ConsoleCommandManager::getInstance().unregisterCommand(this); 95 95 } 96 96 -
code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.cc
r10404 r10484 35 35 void StaticallyInitializedConsoleCommand::load() 36 36 { 37 ConsoleCommandManager:: registerCommand(this->command_);37 ConsoleCommandManager::getInstance().registerCommand(this->command_); 38 38 } 39 39 40 40 void StaticallyInitializedConsoleCommand::unload() 41 41 { 42 ConsoleCommandManager:: unregisterCommand(this->command_);42 ConsoleCommandManager::getInstance().unregisterCommand(this->command_); 43 43 } 44 44 } -
code/branches/core7/src/libraries/core/command/ConsoleCommandIncludes.h
r10404 r10484 332 332 */ 333 333 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& name) 334 { return ConsoleCommandManager::get Command(name, true); }334 { return ConsoleCommandManager::getInstance().getCommand(name, true); } 335 335 /** 336 336 @brief Returns a manipulator for a command with the given group and name. … … 341 341 */ 342 342 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& group, const std::string& name) 343 { return ConsoleCommandManager::get Command(group, name, true); }343 { return ConsoleCommandManager::getInstance().getCommand(group, name, true); } 344 344 } 345 345 -
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 } -
code/branches/core7/src/libraries/core/command/ConsoleCommandManager.h
r10354 r10484 40 40 { 41 41 /** 42 * A s tatic classthat stores all existing ConsoleCommands.42 * A singleton that stores all existing ConsoleCommands. 43 43 */ 44 44 class _CoreExport ConsoleCommandManager 45 45 { 46 46 public: 47 static void registerCommand(ConsoleCommand* command); 48 static void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command); 49 static void unregisterCommand(ConsoleCommand* command); 47 static ConsoleCommandManager& getInstance(); 48 49 void registerCommand(ConsoleCommand* command); 50 void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command); 51 void unregisterCommand(ConsoleCommand* command); 50 52 51 53 /// Returns the map with all groups and commands. 52 staticinline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands()53 { return ConsoleCommandManager::getCommandMap(); }54 inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands() 55 { return this->commandMap_; } 54 56 /// Returns the map with all groups and commands in lowercase. 55 staticinline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC()56 { return ConsoleCommandManager::getCommandMapLC(); }57 inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC() 58 { return this->commandMapLC_; } 57 59 58 60 /// 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 59 staticinline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)60 { return ConsoleCommandManager::getCommand("", name, bPrintError); }61 inline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false) 62 { return this->getCommand("", name, bPrintError); } 61 63 /// 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 62 staticinline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false)63 { return ConsoleCommandManager::getCommandLC("", name, bPrintError); }64 inline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false) 65 { return this->getCommandLC("", name, bPrintError); } 64 66 65 staticConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);66 staticConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false);67 ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false); 68 ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false); 67 69 68 staticvoid destroyAll();70 void destroyAll(); 69 71 70 72 private: 71 st atic std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMap();72 st atic std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMapLC();73 std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap_; 74 std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC_; 73 75 }; 74 76 }
Note: See TracChangeset
for help on using the changeset viewer.