- Timestamp:
- Aug 27, 2010, 2:41:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc
r7222 r7228 30 30 31 31 #include "util/Convert.h" 32 #include "util/StringUtils.h" 32 33 #include "core/Language.h" 33 34 #include "core/GameMode.h" … … 398 399 } 399 400 400 /* static */ const_ConsoleCommand* _ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)401 /* static */ _ConsoleCommand* _ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError) 401 402 { 402 403 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMap().find(group); … … 419 420 } 420 421 422 /* static */ _ConsoleCommand* _ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError) 423 { 424 std::string groupLC = getLowercase(group); 425 std::string nameLC = getLowercase(name); 426 427 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMapLC().find(groupLC); 428 if (it_group != _ConsoleCommand::getCommandMapLC().end()) 429 { 430 std::map<std::string, _ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC); 431 if (it_name != it_group->second.end()) 432 { 433 return it_name->second; 434 } 435 } 436 if (bPrintError) 437 { 438 if (group == "") 439 COUT(1) << "Error: Couldn't find console command with shortcut \"" << name << "\"" << std::endl; 440 else 441 COUT(1) << "Error: Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << std::endl; 442 } 443 return 0; 444 } 445 421 446 /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMap() 422 447 { 423 448 static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMap; 424 449 return commandMap; 450 } 451 452 /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMapLC() 453 { 454 static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMapLC; 455 return commandMapLC; 425 456 } 426 457 … … 440 471 { 441 472 _ConsoleCommand::getCommandMap()[group][name] = command; 473 _ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command; 442 474 } 443 475 } … … 460 492 ++it_group; 461 493 } 494 495 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::iterator it_group = _ConsoleCommand::getCommandMapLC().begin(); it_group != _ConsoleCommand::getCommandMapLC().end(); ) 496 { 497 for (std::map<std::string, _ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ) 498 { 499 if (it_name->second == command) 500 it_group->second.erase(it_name++); 501 else 502 ++it_name; 503 } 504 505 if (it_group->second.empty()) 506 _ConsoleCommand::getCommandMapLC().erase(it_group++); 507 else 508 ++it_group; 509 } 462 510 } 463 511
Note: See TracChangeset
for help on using the changeset viewer.