Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2013, 9:07:38 PM (11 years ago)
Author:
landauf
Message:

made IdentifierManager a self-initializing singleton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/class/IdentifierManager.cc

    r9634 r9640  
    4343namespace orxonox
    4444{
    45     int IdentifierManager::hierarchyCreatingCounter_s = 0;
    46     unsigned int IdentifierManager::classIDCounter_s = 0;
     45    /* static */ IdentifierManager& IdentifierManager::getInstance()
     46    {
     47        static IdentifierManager instance;
     48        return instance;
     49    }
    4750
    48     /**
    49         @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
    50     */
    51     std::map<std::string, Identifier*>& IdentifierManager::getTypeIDIdentifierMap()
     51    IdentifierManager::IdentifierManager()
    5252    {
    53         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    54         return identifiers;
     53        this->hierarchyCreatingCounter_s = 0;
     54        this->classIDCounter_s = 0;
    5555    }
    5656
     
    6363    Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    6464    {
    65         std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     65        std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.find(name);
    6666
    67         if (it != getTypeIDIdentifierMap().end())
     67        if (it != this->identifierByTypeId_.end())
    6868        {
    6969            // There is already an entry: return it and delete the proposal
     
    7474        {
    7575            // There is no entry: put the proposal into the map and return it
    76             getTypeIDIdentifierMap()[name] = proposal;
     76            this->identifierByTypeId_[name] = proposal;
    7777            return proposal;
    7878        }
     
    8585    {
    8686        orxout(internal_status) << "Create class-hierarchy" << endl;
    87         IdentifierManager::startCreatingHierarchy();
    88         for (std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
     87        this->startCreatingHierarchy();
     88        for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
    8989        {
    9090            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    9595            }
    9696        }
    97         IdentifierManager::stopCreatingHierarchy();
     97        this->stopCreatingHierarchy();
    9898        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
    9999    }
     
    104104    void IdentifierManager::destroyAllIdentifiers()
    105105    {
    106         for (std::map<std::string, Identifier*>::iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
     106        for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
    107107            delete (it->second);
    108108
    109         IdentifierManager::getTypeIDIdentifierMap().clear();
    110         IdentifierManager::getStringIdentifierMapIntern().clear();
    111         IdentifierManager::getLowercaseStringIdentifierMapIntern().clear();
    112         IdentifierManager::getIDIdentifierMapIntern().clear();
    113     }
    114 
    115     /**
    116         @brief Returns the map that stores all Identifiers with their names.
    117         @return The map
    118     */
    119     std::map<std::string, Identifier*>& IdentifierManager::getStringIdentifierMapIntern()
    120     {
    121         static std::map<std::string, Identifier*> identifierMap;
    122         return identifierMap;
    123     }
    124 
    125     /**
    126         @brief Returns the map that stores all Identifiers with their names in lowercase.
    127         @return The map
    128     */
    129     std::map<std::string, Identifier*>& IdentifierManager::getLowercaseStringIdentifierMapIntern()
    130     {
    131         static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    132         return lowercaseIdentifierMap;
    133     }
    134 
    135     /**
    136         @brief Returns the map that stores all Identifiers with their network IDs.
    137         @return The map
    138     */
    139     std::map<uint32_t, Identifier*>& IdentifierManager::getIDIdentifierMapIntern()
    140     {
    141         static std::map<uint32_t, Identifier*> identifierMap;
    142         return identifierMap;
     109        this->identifierByTypeId_.clear();
     110        this->identifierByString_.clear();
     111        this->identifierByLowercaseString_.clear();
     112        this->identifierByNetworkId_.clear();
    143113    }
    144114
     
    150120    Identifier* IdentifierManager::getIdentifierByString(const std::string& name)
    151121    {
    152         std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapIntern().find(name);
    153         if (it != IdentifierManager::getStringIdentifierMapIntern().end())
     122        std::map<std::string, Identifier*>::const_iterator it = this->identifierByString_.find(name);
     123        if (it != this->identifierByString_.end())
    154124            return it->second;
    155125        else
     
    164134    Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name)
    165135    {
    166         std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getLowercaseStringIdentifierMapIntern().find(name);
    167         if (it != IdentifierManager::getLowercaseStringIdentifierMapIntern().end())
     136        std::map<std::string, Identifier*>::const_iterator it = this->identifierByLowercaseString_.find(name);
     137        if (it != this->identifierByLowercaseString_.end())
    168138            return it->second;
    169139        else
     
    178148    Identifier* IdentifierManager::getIdentifierByID(const uint32_t id)
    179149    {
    180         std::map<uint32_t, Identifier*>::const_iterator it = IdentifierManager::getIDIdentifierMapIntern().find(id);
    181         if (it != IdentifierManager::getIDIdentifierMapIntern().end())
     150        std::map<uint32_t, Identifier*>::const_iterator it = this->identifierByNetworkId_.find(id);
     151        if (it != this->identifierByNetworkId_.end())
    182152            return it->second;
    183153        else
     
    190160    void IdentifierManager::clearNetworkIDs()
    191161    {
    192         IdentifierManager::getIDIdentifierMapIntern().clear();
     162        this->identifierByNetworkId_.clear();
    193163    }
    194164}
Note: See TracChangeset for help on using the changeset viewer.