Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 27, 2010, 2:41:03 PM (14 years ago)
Author:
landauf
Message:

re-implemented CommandExecutor and CommandEvaluation. parameter evaluation is currently not implemented, will come soon.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.cc

    r7222 r7228  
    3030
    3131#include "util/Convert.h"
     32#include "util/StringUtils.h"
    3233#include "core/Language.h"
    3334#include "core/GameMode.h"
     
    398399    }
    399400
    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)
    401402    {
    402403        std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommandMap().find(group);
     
    419420    }
    420421
     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
    421446    /* static */ std::map<std::string, std::map<std::string, _ConsoleCommand*> >& _ConsoleCommand::getCommandMap()
    422447    {
    423448        static std::map<std::string, std::map<std::string, _ConsoleCommand*> > commandMap;
    424449        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;
    425456    }
    426457
     
    440471        {
    441472            _ConsoleCommand::getCommandMap()[group][name] = command;
     473            _ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command;
    442474        }
    443475    }
     
    460492                ++it_group;
    461493        }
     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        }
    462510    }
    463511
Note: See TracChangeset for help on using the changeset viewer.