Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 5, 2009, 9:22:22 PM (14 years ago)
Author:
rgrieder
Message:

Synchronised sandbox with current code trunk. There should be a few bug fixes.

Location:
sandbox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sandbox

  • sandbox/src/libraries/core/Identifier.cc

    r5782 r6038  
    3737
    3838#include "util/StringUtils.h"
     39#include "BaseObject.h"
    3940#include "ConfigValueContainer.h"
    40 #include "Factory.h"
     41#include "ClassFactory.h"
    4142
    4243namespace orxonox
     
    6263        this->bHasConfigValues_ = false;
    6364
    64         this->children_ = new std::set<const Identifier*>();
    65         this->directChildren_ = new std::set<const Identifier*>();
    6665    }
    6766
     
    7170    Identifier::~Identifier()
    7271    {
    73         delete this->children_;
    74         delete this->directChildren_;
    7572        delete this->objects_;
    7673
     
    105102            // There is already an entry: return it and delete the proposal
    106103            delete proposal;
    107             return (*it).second;
     104            return it->second;
    108105        }
    109106        else
     
    152149            {
    153150                // Tell the parent we're one of it's children
    154                 (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     151                (*it)->children_.insert((*it)->children_.end(), this);
    155152
    156153                // Erase all parents of our parent from our direct-parent-list
     
    174171            {
    175172                // Tell the parent we're one of it's direct children
    176                 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     173                (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
    177174            }
    178175        }
     176    }
     177
     178    /**
     179        @brief Creates the class-hierarchy by creating and destroying one object of each type.
     180    */
     181    void Identifier::createClassHierarchy()
     182    {
     183        COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl;
     184        Identifier::startCreatingHierarchy();
     185        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
     186        {
     187            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     188            if (it->second->hasFactory())
     189            {
     190                BaseObject* temp = it->second->fabricate(0);
     191                delete temp;
     192            }
     193        }
     194        Identifier::stopCreatingHierarchy();
     195        COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl;
    179196    }
    180197
     
    198215            this->name_ = name;
    199216            this->bSetName_ = true;
    200             Identifier::getIdentifierMapIntern()[name] = this;
    201             Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
     217            Identifier::getStringIdentifierMapIntern()[name] = this;
     218            Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
    202219        }
    203220    }
     
    219236            COUT(1) << "Aborting..." << std::endl;
    220237            abort();
    221             return NULL;
     238            return 0;
    222239        }
    223240    }
     
    265282    bool Identifier::isParentOf(const Identifier* identifier) const
    266283    {
    267         return (this->children_->find(identifier) != this->children_->end());
     284        return (this->children_.find(identifier) != this->children_.end());
    268285    }
    269286
     
    274291    bool Identifier::isDirectParentOf(const Identifier* identifier) const
    275292    {
    276         return (this->directChildren_->find(identifier) != this->directChildren_->end());
    277     }
    278 
    279     /**
    280         @brief Returns the map that stores all Identifiers.
     293        return (this->directChildren_.find(identifier) != this->directChildren_.end());
     294    }
     295
     296    /**
     297        @brief Returns the map that stores all Identifiers with their names.
    281298        @return The map
    282299    */
    283     std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
     300    std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
    284301    {
    285302        static std::map<std::string, Identifier*> identifierMap;
     
    288305
    289306    /**
    290         @brief Returns the map that stores all Identifiers.
     307        @brief Returns the map that stores all Identifiers with their names in lowercase.
    291308        @return The map
    292309    */
    293     std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
     310    std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
    294311    {
    295312        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    296313        return lowercaseIdentifierMap;
     314    }
     315
     316    /**
     317        @brief Returns the map that stores all Identifiers with their network IDs.
     318        @return The map
     319    */
     320    std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
     321    {
     322        static std::map<uint32_t, Identifier*> identifierMap;
     323        return identifierMap;
     324    }
     325
     326    /**
     327        @brief Returns the Identifier with a given name.
     328        @param name The name of the wanted Identifier
     329        @return The Identifier
     330    */
     331    Identifier* Identifier::getIdentifierByString(const std::string& name)
     332    {
     333        std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
     334        if (it != Identifier::getStringIdentifierMapIntern().end())
     335            return it->second;
     336        else
     337            return 0;
     338    }
     339
     340    /**
     341        @brief Returns the Identifier with a given name in lowercase.
     342        @param name The name of the wanted Identifier
     343        @return The Identifier
     344    */
     345    Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
     346    {
     347        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
     348        if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
     349            return it->second;
     350        else
     351            return 0;
    297352    }
    298353
     
    325380        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
    326381        if (it != configValues_.end())
    327             return ((*it).second);
     382            return it->second;
    328383        else
    329384            return 0;
     
    339394        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
    340395        if (it != configValues_LC_.end())
    341             return ((*it).second);
     396            return it->second;
    342397        else
    343398            return 0;
     
    353408    {
    354409        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    355             out << (*it)->getName() << " ";
     410        {
     411            if (it != list.begin())
     412                out << " ";
     413            out << (*it)->getName();
     414        }
    356415
    357416        return out;
Note: See TracChangeset for help on using the changeset viewer.