Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 5, 2015, 8:25:11 PM (9 years ago)
Author:
landauf
Message:

moved static contents from ConsoleCommand to ConsoleCommandManager

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  
    254254        safeObjectDelete(&languageInstance_);
    255255        safeObjectDelete(&configFileManager_);
    256         ConsoleCommand::destroyAll();
     256        ConsoleCommandManager::destroyAll();
    257257        Context::setRootContext(NULL);
    258258        IdentifierManager::getInstance().destroyAllIdentifiers();
  • code/branches/core7/src/libraries/core/CorePrereqs.h

    r10342 r10346  
    212212    class CommandEvaluation;
    213213    class ConsoleCommand;
     214    class ConsoleCommandManager;
    214215    class Executor;
    215216    template <class T>
  • code/branches/core7/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r9667 r10346  
    9898
    9999                // 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();
    101101                for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
    102102                    if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find(fragmentLC) == 0))
     
    137137
    138138                // 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)
    141141                    if (getLowercase(it_group->first) == groupLC)
    142142                        break;
    143143
    144144                // add all commands in the group to the list
    145                 if (it_group != ConsoleCommand::getCommands().end())
     145                if (it_group != ConsoleCommandManager::getCommands().end())
    146146                {
    147147                    for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
     
    206206                return detail::_groupsandcommands(fragment, true);
    207207
    208             if (ConsoleCommand::getCommandLC(getLowercase(tokens[0])))
     208            if (ConsoleCommandManager::getCommandLC(getLowercase(tokens[0])))
    209209                return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment);
    210210
    211211            if (tokens.size() == 1)
    212212            {
    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())
    215215                    return detail::_subcommands(fragment, tokens[0], true);
    216216                else
     
    218218            }
    219219
    220             if (ConsoleCommand::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))
     220            if (ConsoleCommandManager::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))
    221221                return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment);
    222222
  • code/branches/core7/src/libraries/core/command/CMakeLists.txt

    r7284 r10346  
    44  ConsoleCommand.cc
    55  ConsoleCommandCompilation.cc
     6  ConsoleCommandManager.cc
    67  Executor.cc
    78  IOConsole.cc
  • code/branches/core7/src/libraries/core/command/CommandEvaluation.cc

    r9550 r10346  
    305305                // the user typed 1-2 arguments, check what he tried to type and print a suitable error
    306306                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)
    308308                    if (it_group->first == groupLC)
    309309                        return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\".";
     
    327327
    328328        // 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)
    330330        {
    331331            if (it_group->first != "")
     
    345345
    346346        // 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())
    349349        {
    350350            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  
    155155
    156156        // 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);
    158158
    159159        // check if there's at least one argument
     
    161161        {
    162162            // 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));
    164164            if (evaluation.execCommand_)
    165165                evaluation.execArgumentsOffset_ = 1;
     
    167167            {
    168168                // 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));
    170170                if (evaluation.execCommand_)
    171171                    evaluation.execArgumentsOffset_ = 2;
     
    288288
    289289            // 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])))
    291291            {
    292292                orxout(user_error) << "A command with name \"" << alias << "\" already exists." << endl;
  • code/branches/core7/src/libraries/core/command/ConsoleCommand.cc

    r9348 r10346  
    3535
    3636#include "util/Convert.h"
    37 #include "util/StringUtils.h"
    3837#include "core/Language.h"
    3938#include "core/GameMode.h"
     
    6867            this->executor_ = executor;
    6968
    70         ConsoleCommand::registerCommand(group, name, this);
     69        ConsoleCommandManager::registerCommand(group, name, this);
    7170    }
    7271
     
    7675    ConsoleCommand::~ConsoleCommand()
    7776    {
    78         ConsoleCommand::unregisterCommand(this);
     77        ConsoleCommandManager::unregisterCommand(this);
    7978    }
    8079
     
    8483    ConsoleCommand& ConsoleCommand::addShortcut()
    8584    {
    86         ConsoleCommand::registerCommand("", this->baseName_, this);
     85        ConsoleCommandManager::registerCommand("", this->baseName_, this);
    8786        return *this;
    8887    }
     
    9392    ConsoleCommand& ConsoleCommand::addShortcut(const std::string&  name)
    9493    {
    95         ConsoleCommand::registerCommand("", name, this);
     94        ConsoleCommandManager::registerCommand("", name, this);
    9695        return *this;
    9796    }
     
    102101    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group)
    103102    {
    104         ConsoleCommand::registerCommand(group, this->baseName_, this);
     103        ConsoleCommandManager::registerCommand(group, this->baseName_, this);
    105104        return *this;
    106105    }
     
    111110    ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string&  name)
    112111    {
    113         ConsoleCommand::registerCommand(group, name, this);
     112        ConsoleCommandManager::registerCommand(group, name, this);
    114113        return *this;
    115114    }
     
    587586        return *this;
    588587    }
    589 
    590     /**
    591         @brief Returns the command with given group an name.
    592         @param group The group of the requested command
    593         @param name The group of the requested command
    594         @param bPrintError If true, an error is printed if the command doesn't exist
    595     */
    596     /* static */ ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError)
    597     {
    598         // find the group
    599         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 name
    603             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 pointer
    607                 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             else
    615                 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 lowercase
    623         @param name The group of the requested command in lowercase
    624         @param bPrintError If true, an error is printed if the command doesn't exist
    625     */
    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 group
    632         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 name
    636             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 pointer
    640                 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             else
    648                 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 exists
    680         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             else
    685                 orxout(internal_warning, context::commands) << "A console command with name \"" << name << "\" already exists in group \"" << group << "\"." << endl;
    686         }
    687         else
    688         {
    689             // add the command to the map
    690             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 groups
    701         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 group
    704             for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )
    705             {
    706                 // erase the command
    707                 if (it_name->second == command)
    708                     it_group->second.erase(it_name++);
    709                 else
    710                     ++it_name;
    711             }
    712 
    713             // erase the group if it is empty now
    714             if (it_group->second.empty())
    715                 ConsoleCommand::getCommandMap().erase(it_group++);
    716             else
    717                 ++it_group;
    718         }
    719 
    720         // now the same for the lowercase-map:
    721 
    722         // iterate through all groups
    723         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 group
    726             for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); )
    727             {
    728                 // erase the command
    729                 if (it_name->second == command)
    730                     it_group->second.erase(it_name++);
    731                 else
    732                     ++it_name;
    733             }
    734 
    735             // erase the group if it is empty now
    736             if (it_group->second.empty())
    737                 ConsoleCommand::getCommandMapLC().erase(it_group++);
    738             else
    739                 ++it_group;
    740         }
    741     }
    742 
    743     /**
    744         @brief Deletes all commands
    745     */
    746     /* static */ void ConsoleCommand::destroyAll()
    747     {
    748         // delete entries until the map is empty
    749         while (!ConsoleCommand::getCommandMap().empty() && !ConsoleCommand::getCommandMap().begin()->second.empty())
    750             delete ConsoleCommand::getCommandMap().begin()->second.begin()->second;
    751     }
    752588}
  • code/branches/core7/src/libraries/core/command/ConsoleCommand.h

    r9983 r10346  
    226226#include "ArgumentCompletionFunctions.h"
    227227#include "Executor.h"
     228#include "ConsoleCommandManager.h"
    228229
    229230
     
    655656            LanguageEntryLabel descriptionReturnvalue_;                     ///< A description of the return-value
    656657            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 exist
    667             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 exist
    670             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);
    684658    };
    685659
     
    711685    */
    712686    inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& name)
    713         { return ConsoleCommand::getCommand(name, true); }
     687        { return ConsoleCommandManager::getCommand(name, true); }
    714688    /**
    715689        @brief Returns a manipulator for a command with the given group and name.
     
    720694    */
    721695    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); }
    723697}
    724698
Note: See TracChangeset for help on using the changeset viewer.