Changeset 10346
- Timestamp:
- Apr 5, 2015, 8:25:11 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/Core.cc
r10345 r10346 254 254 safeObjectDelete(&languageInstance_); 255 255 safeObjectDelete(&configFileManager_); 256 ConsoleCommand ::destroyAll();256 ConsoleCommandManager::destroyAll(); 257 257 Context::setRootContext(NULL); 258 258 IdentifierManager::getInstance().destroyAllIdentifiers(); -
code/branches/core7/src/libraries/core/CorePrereqs.h
r10342 r10346 212 212 class CommandEvaluation; 213 213 class ConsoleCommand; 214 class ConsoleCommandManager; 214 215 class Executor; 215 216 template <class T> -
code/branches/core7/src/libraries/core/command/ArgumentCompletionFunctions.cc
r9667 r10346 98 98 99 99 // get all the groups that are visible (except the shortcut group "") 100 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommand ::getCommands();100 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommandManager::getCommands(); 101 101 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 102 102 if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0)) … … 137 137 138 138 // find the iterator of the given group 139 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand ::getCommands().begin();140 for ( ; it_group != ConsoleCommand ::getCommands().end(); ++it_group)139 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommands().begin(); 140 for ( ; it_group != ConsoleCommandManager::getCommands().end(); ++it_group) 141 141 if (getLowercase(it_group->first) == groupLC) 142 142 break; 143 143 144 144 // add all commands in the group to the list 145 if (it_group != ConsoleCommand ::getCommands().end())145 if (it_group != ConsoleCommandManager::getCommands().end()) 146 146 { 147 147 for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) … … 206 206 return detail::_groupsandcommands(fragment, true); 207 207 208 if (ConsoleCommand ::getCommandLC(getLowercase(tokens[0])))208 if (ConsoleCommandManager::getCommandLC(getLowercase(tokens[0]))) 209 209 return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment); 210 210 211 211 if (tokens.size() == 1) 212 212 { 213 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand ::getCommands().find(tokens[0]);214 if (it_group != ConsoleCommand ::getCommands().end())213 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommands().find(tokens[0]); 214 if (it_group != ConsoleCommandManager::getCommands().end()) 215 215 return detail::_subcommands(fragment, tokens[0], true); 216 216 else … … 218 218 } 219 219 220 if (ConsoleCommand ::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))220 if (ConsoleCommandManager::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1]))) 221 221 return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment); 222 222 -
code/branches/core7/src/libraries/core/command/CMakeLists.txt
r7284 r10346 4 4 ConsoleCommand.cc 5 5 ConsoleCommandCompilation.cc 6 ConsoleCommandManager.cc 6 7 Executor.cc 7 8 IOConsole.cc -
code/branches/core7/src/libraries/core/command/CommandEvaluation.cc
r9550 r10346 305 305 // the user typed 1-2 arguments, check what he tried to type and print a suitable error 306 306 std::string groupLC = getLowercase(this->getToken(0)); 307 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand ::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group)307 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommandsLC().begin(); it_group != ConsoleCommandManager::getCommandsLC().end(); ++it_group) 308 308 if (it_group->first == groupLC) 309 309 return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\"."; … … 327 327 328 328 // iterate through all groups and their commands and calculate the distance to the current command. keep the best. 329 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand ::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group)329 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommandsLC().begin(); it_group != ConsoleCommandManager::getCommandsLC().end(); ++it_group) 330 330 { 331 331 if (it_group->first != "") … … 345 345 346 346 // now also iterate through all shortcuts and keep the best if it's better than the one found above. 347 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand ::getCommandsLC().find("");348 if (it_group != ConsoleCommand ::getCommandsLC().end())347 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommandManager::getCommandsLC().find(""); 348 if (it_group != ConsoleCommandManager::getCommandsLC().end()) 349 349 { 350 350 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
r9550 r10346 155 155 156 156 // assign the fallback-command to get hints about the possible commands and groups 157 evaluation.hintCommand_ = ConsoleCommand ::getCommand(__CC_CommandExecutor_name, __CC_autocomplete_name);157 evaluation.hintCommand_ = ConsoleCommandManager::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_ = ConsoleCommand ::getCommandLC(evaluation.getToken(0));163 evaluation.execCommand_ = ConsoleCommandManager::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_ = ConsoleCommand ::getCommandLC(evaluation.getToken(0), evaluation.getToken(1));169 evaluation.execCommand_ = ConsoleCommandManager::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 && ConsoleCommand ::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommand::getCommand(tokens[0], tokens[1])))290 if ((tokens.size() == 1 && ConsoleCommandManager::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommandManager::getCommand(tokens[0], tokens[1]))) 291 291 { 292 292 orxout(user_error) << "A command with name \"" << alias << "\" already exists." << endl; -
code/branches/core7/src/libraries/core/command/ConsoleCommand.cc
r9348 r10346 35 35 36 36 #include "util/Convert.h" 37 #include "util/StringUtils.h"38 37 #include "core/Language.h" 39 38 #include "core/GameMode.h" … … 68 67 this->executor_ = executor; 69 68 70 ConsoleCommand ::registerCommand(group, name, this);69 ConsoleCommandManager::registerCommand(group, name, this); 71 70 } 72 71 … … 76 75 ConsoleCommand::~ConsoleCommand() 77 76 { 78 ConsoleCommand ::unregisterCommand(this);77 ConsoleCommandManager::unregisterCommand(this); 79 78 } 80 79 … … 84 83 ConsoleCommand& ConsoleCommand::addShortcut() 85 84 { 86 ConsoleCommand ::registerCommand("", this->baseName_, this);85 ConsoleCommandManager::registerCommand("", this->baseName_, this); 87 86 return *this; 88 87 } … … 93 92 ConsoleCommand& ConsoleCommand::addShortcut(const std::string& name) 94 93 { 95 ConsoleCommand ::registerCommand("", name, this);94 ConsoleCommandManager::registerCommand("", name, this); 96 95 return *this; 97 96 } … … 102 101 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group) 103 102 { 104 ConsoleCommand ::registerCommand(group, this->baseName_, this);103 ConsoleCommandManager::registerCommand(group, this->baseName_, this); 105 104 return *this; 106 105 } … … 111 110 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string& name) 112 111 { 113 ConsoleCommand ::registerCommand(group, name, this);112 ConsoleCommandManager::registerCommand(group, name, this); 114 113 return *this; 115 114 } … … 587 586 return *this; 588 587 } 589 590 /**591 @brief Returns the command with given group an name.592 @param group The group of the requested command593 @param name The group of the requested command594 @param bPrintError If true, an error is printed if the command doesn't exist595 */596 /* static */ ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)597 {598 // find the group599 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMap().find(group);600 if (it_group != ConsoleCommand::getCommandMap().end())601 {602 // find the name603 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(name);604 if (it_name != it_group->second.end())605 {606 // return the pointer607 return it_name->second;608 }609 }610 if (bPrintError)611 {612 if (group == "")613 orxout(internal_error, context::commands) << "Couldn't find console command with shortcut \"" << name << "\"" << endl;614 else615 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl;616 }617 return 0;618 }619 620 /**621 @brief Returns the command with given group an name in lowercase.622 @param group The group of the requested command in lowercase623 @param name The group of the requested command in lowercase624 @param bPrintError If true, an error is printed if the command doesn't exist625 */626 /* static */ ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError)627 {628 std::string groupLC = getLowercase(group);629 std::string nameLC = getLowercase(name);630 631 // find the group632 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMapLC().find(groupLC);633 if (it_group != ConsoleCommand::getCommandMapLC().end())634 {635 // find the name636 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC);637 if (it_name != it_group->second.end())638 {639 // return the pointer640 return it_name->second;641 }642 }643 if (bPrintError)644 {645 if (group == "")646 orxout(internal_error, context::commands) << "Couldn't find console command with shortcut \"" << name << "\"" << endl;647 else648 orxout(internal_error, context::commands) << "Couldn't find console command with group \"" << group << "\" and name \"" << name << "\"" << endl;649 }650 return 0;651 }652 653 /**654 @brief Returns the static map that stores all console commands.655 */656 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMap()657 {658 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMap;659 return commandMap;660 }661 662 /**663 @brief Returns the static map that stores all console commands in lowercase.664 */665 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMapLC()666 {667 static std::map<std::string, std::map<std::string, ConsoleCommand*> > commandMapLC;668 return commandMapLC;669 }670 671 /**672 @brief Registers a new command with given group an name by adding it to the command map.673 */674 /* static */ void ConsoleCommand::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command)675 {676 if (name == "")677 return;678 679 // check if a command with this name already exists680 if (ConsoleCommand::getCommand(group, name) != 0)681 {682 if (group == "")683 orxout(internal_warning, context::commands) << "A console command with shortcut \"" << name << "\" already exists." << endl;684 else685 orxout(internal_warning, context::commands) << "A console command with name \"" << name << "\" already exists in group \"" << group << "\"." << endl;686 }687 else688 {689 // add the command to the map690 ConsoleCommand::getCommandMap()[group][name] = command;691 ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command;692 }693 }694 695 /**696 @brief Removes the command from the command map.697 */698 /* static */ void ConsoleCommand::unregisterCommand(ConsoleCommand* command)699 {700 // iterate through all groups701 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMap().begin(); it_group != ConsoleCommand::getCommandMap().end(); )702 {703 // iterate through all commands of each group704 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )705 {706 // erase the command707 if (it_name->second == command)708 it_group->second.erase(it_name++);709 else710 ++it_name;711 }712 713 // erase the group if it is empty now714 if (it_group->second.empty())715 ConsoleCommand::getCommandMap().erase(it_group++);716 else717 ++it_group;718 }719 720 // now the same for the lowercase-map:721 722 // iterate through all groups723 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMapLC().begin(); it_group != ConsoleCommand::getCommandMapLC().end(); )724 {725 // iterate through all commands of each group726 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )727 {728 // erase the command729 if (it_name->second == command)730 it_group->second.erase(it_name++);731 else732 ++it_name;733 }734 735 // erase the group if it is empty now736 if (it_group->second.empty())737 ConsoleCommand::getCommandMapLC().erase(it_group++);738 else739 ++it_group;740 }741 }742 743 /**744 @brief Deletes all commands745 */746 /* static */ void ConsoleCommand::destroyAll()747 {748 // delete entries until the map is empty749 while (!ConsoleCommand::getCommandMap().empty() && !ConsoleCommand::getCommandMap().begin()->second.empty())750 delete ConsoleCommand::getCommandMap().begin()->second.begin()->second;751 }752 588 } -
code/branches/core7/src/libraries/core/command/ConsoleCommand.h
r9983 r10346 226 226 #include "ArgumentCompletionFunctions.h" 227 227 #include "Executor.h" 228 #include "ConsoleCommandManager.h" 228 229 229 230 … … 655 656 LanguageEntryLabel descriptionReturnvalue_; ///< A description of the return-value 656 657 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; ///< A description for each argument 657 658 public:659 /// Returns the map with all groups and commands.660 static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands()661 { return ConsoleCommand::getCommandMap(); }662 /// Returns the map with all groups and commands in lowercase.663 static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC()664 { return ConsoleCommand::getCommandMapLC(); }665 666 /// 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 exist667 static inline ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false)668 { return ConsoleCommand::getCommand("", name, bPrintError); }669 /// 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 exist670 static inline ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false)671 { return ConsoleCommand::getCommandLC("", name, bPrintError); }672 673 static ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);674 static ConsoleCommand* getCommandLC(const std::string& group, const std::string& name, bool bPrintError = false);675 676 static void destroyAll();677 678 private:679 static std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMap();680 static std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandMapLC();681 682 static void registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command);683 static void unregisterCommand(ConsoleCommand* command);684 658 }; 685 659 … … 711 685 */ 712 686 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& name) 713 { return ConsoleCommand ::getCommand(name, true); }687 { return ConsoleCommandManager::getCommand(name, true); } 714 688 /** 715 689 @brief Returns a manipulator for a command with the given group and name. … … 720 694 */ 721 695 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& group, const std::string& name) 722 { return ConsoleCommand ::getCommand(group, name, true); }696 { return ConsoleCommandManager::getCommand(group, name, true); } 723 697 } 724 698
Note: See TracChangeset
for help on using the changeset viewer.