Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File:
1 edited

Legend:

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

    r871 r1052  
    3535#include "Identifier.h"
    3636#include "Factory.h"
     37#include "Executor.h"
     38#include "CommandExecutor.h"
    3739
    3840namespace orxonox
     
    5153        this->factory_ = 0;
    5254
    53         this->children_ = new std::list<const Identifier*>();
    54         this->directChildren_ = new std::list<const Identifier*>();
     55        this->bHasConfigValues_ = false;
     56        this->bHasConsoleCommands_ = false;
     57
     58        this->children_ = new std::set<const Identifier*>();
     59        this->directChildren_ = new std::set<const Identifier*>();
    5560
    5661        // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables
     
    7277        @param parents A list containing all parents
    7378    */
    74     void Identifier::initialize(std::list<const Identifier*>* parents)
     79    void Identifier::initialize(std::set<const Identifier*>* parents)
    7580    {
    7681        COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl;
     
    8388
    8489            // Iterate through all parents
    85             for (std::list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
     90            for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    8691            {
    8792                // Tell the parent we're one of it's children
     
    8994
    9095                // Erase all parents of our parent from our direct-parent-list
    91                 for (std::list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
     96                for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
    9297                {
    9398                    // Search for the parent's parent in our direct-parent-list
    94                     for (std::list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
     99                    for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
    95100                    {
    96101                        if ((*it1) == (*it2))
     
    105110
    106111            // Now iterate through all direct parents
    107             for (std::list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
     112            for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    108113            {
    109114                // Tell the parent we're one of it's direct children
     
    149154    bool Identifier::isA(const Identifier* identifier) const
    150155    {
    151         return (identifier == this || this->identifierIsInList(identifier, this->parents_));
     156        return (identifier == this || (this->parents_.find(identifier) != this->children_->end()));
    152157    }
    153158
     
    167172    bool Identifier::isChildOf(const Identifier* identifier) const
    168173    {
    169         return this->identifierIsInList(identifier, this->parents_);
     174        return (this->parents_.find(identifier) != this->children_->end());
    170175    }
    171176
     
    176181    bool Identifier::isDirectChildOf(const Identifier* identifier) const
    177182    {
    178         return this->identifierIsInList(identifier, this->directParents_);
     183        return (this->directParents_.find(identifier) != this->children_->end());
    179184    }
    180185
     
    185190    bool Identifier::isParentOf(const Identifier* identifier) const
    186191    {
    187         return this->identifierIsInList(identifier, *this->children_);
     192        return (this->children_->find(identifier) != this->children_->end());
    188193    }
    189194
     
    194199    bool Identifier::isDirectParentOf(const Identifier* identifier) const
    195200    {
    196         return this->identifierIsInList(identifier, *this->directChildren_);
     201        return (this->directChildren_->find(identifier) != this->children_->end());
     202    }
     203
     204    /**
     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;
    197234    }
    198235
     
    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 
    223     /**
    224         @brief Searches for a given identifier in a list and returns whether the identifier is in the list or not.
    225         @param identifier The identifier to look for
    226         @param list The list
    227         @return True = the identifier is in the list
    228     */
    229     bool Identifier::identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list)
    230     {
    231         for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    232             if (identifier == (*it))
    233                 return true;
    234 
    235         return false;
    236     }
    237 
    238     std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list)
    239     {
    240         for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
     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    */
     316    std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
     317    {
     318        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    241319            out << (*it)->getName() << " ";
    242320
Note: See TracChangeset for help on using the changeset viewer.