Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 28, 2008, 10:13:58 PM (17 years ago)
Author:
landauf
Message:
  • added CommandExecutor
  • added ConsoleCommand macros
  • added getTypename to all MultiTypes
  • added 2 static maps to Identifier that contain all existing Identifiers with their names and lowercase names respectively.
  • added 2 maps to each Identifier that contain all console commands of the Identifier with their names and lowercase names respectively
  • using tolower(.) and toupper(.) instead of selfmade hacks in String.h
  • added AccessLevel enum
  • added some test-console-commands to OutputHandler, Ambient and SpaceShip
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/Identifier.cc

    r876 r947  
    3535#include "Identifier.h"
    3636#include "Factory.h"
     37#include "Executor.h"
     38#include "CommandExecutor.h"
    3739
    3840namespace orxonox
     
    5052        this->bCreatedOneObject_ = false;
    5153        this->factory_ = 0;
     54
     55        this->bHasConfigValues_ = false;
     56        this->bHasConsoleCommands_ = false;
    5257
    5358        this->children_ = new std::set<const Identifier*>();
     
    198203
    199204    /**
     205        @brief Returns the map that stores all Identifiers.
     206        @return The map
     207    */
     208    std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
     209    {
     210        static std::map<std::string, Identifier*> identifierMap;
     211        return identifierMap;
     212    }
     213
     214    /**
     215        @brief Returns the map that stores all Identifiers.
     216        @return The map
     217    */
     218    std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
     219    {
     220        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
     221        return lowercaseIdentifierMap;
     222    }
     223
     224    /**
     225        @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
     226        @param varname The name of the variablee
     227        @param container The container
     228    */
     229    void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
     230    {
     231        this->bHasConfigValues_ = true;
     232        this->configValues_[varname] = container;
     233        this->configValues_LC_[getLowercase(varname)] = container;
     234    }
     235
     236    /**
    200237        @brief Returns the ConfigValueContainer of a variable, given by the string of its name.
    201238        @param varname The name of the variable
     
    212249
    213250    /**
    214         @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
    215         @param varname The name of the variablee
    216         @param container The container
    217     */
    218     void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    219     {
    220         this->configValues_[varname] = container;
    221     }
    222 
     251        @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.
     252        @param varname The name of the variable in lowercase
     253        @return The ConfigValueContainer
     254    */
     255    ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)
     256    {
     257        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
     258        if (it != configValues_LC_.end())
     259            return ((*it).second);
     260        else
     261            return 0;
     262    }
     263
     264    /**
     265        @brief Adds a new console command of this class.
     266        @param executor The executor of the command
     267        @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command
     268        @return The executor of the command
     269    */
     270    ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut)
     271    {
     272        this->bHasConsoleCommands_ = true;
     273        this->consoleCommands_[executor->getName()] = executor;
     274        this->consoleCommands_LC_[getLowercase(executor->getName())] = executor;
     275
     276        if (bCreateShortcut)
     277            CommandExecutor::addConsoleCommandShortcut(executor);
     278
     279        return (*executor);
     280    }
     281
     282    /**
     283        @brief Returns the executor of a console command with given name.
     284        @brief name The name of the requested console command
     285        @return The executor of the requested console command
     286    */
     287    ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const
     288    {
     289        std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name);
     290        if (it != this->consoleCommands_.end())
     291            return (*it).second;
     292        else
     293            return 0;
     294    }
     295
     296    /**
     297        @brief Returns the executor of a console command with given name in lowercase.
     298        @brief name The name of the requested console command in lowercae
     299        @return The executor of the requested console command
     300    */
     301    ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const
     302    {
     303        std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name);
     304        if (it != this->consoleCommands_LC_.end())
     305            return (*it).second;
     306        else
     307            return 0;
     308    }
     309
     310    /**
     311        @brief Lists the names of all Identifiers in a std::set<const Identifier*>.
     312        @param out The outstream
     313        @param list The list (or set) of Identifiers
     314        @return The outstream
     315    */
    223316    std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
    224317    {
Note: See TracChangeset for help on using the changeset viewer.