Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/class/IdentifierManager.cc

    r10624 r11071  
    4444namespace orxonox
    4545{
    46     IdentifierManager* IdentifierManager::singletonPtr_s = 0;
     46    IdentifierManager* IdentifierManager::singletonPtr_s = nullptr;
    4747
    4848    IdentifierManager::IdentifierManager()
    4949    {
    5050        this->hierarchyCreatingCounter_s = 0;
    51         this->recordTraceForIdentifier_ = NULL;
     51        this->recordTraceForIdentifier_ = nullptr;
    5252    }
    5353
     
    6060
    6161        this->identifiers_.insert(identifier);
     62        this->identifierByTypeIndex_[identifier->getTypeInfo()] = identifier;
    6263        this->identifierByString_[identifier->getName()] = identifier;
    6364        this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier;
     
    7172    {
    7273        this->identifiers_.erase(identifier);
     74        this->identifierByTypeIndex_.erase(identifier->getTypeInfo());
    7375        this->identifierByString_.erase(identifier->getName());
    7476        this->identifierByLowercaseString_.erase(getLowercase(identifier->getName()));
     
    9294        // iterate over all identifiers, create one instance of each class and initialize the identifiers
    9395        {
    94             Context temporaryContext(NULL);
    95             for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
     96            Context temporaryContext(nullptr);
     97            for (Identifier* identifier : this->identifiers_)
    9698            {
    97                 Identifier* identifier = (*it);
    9899                if (identifier->isInitialized())
    99100                    continue;
     
    108109                    Identifiable* temp = identifier->fabricate(&temporaryContext);
    109110
    110                     this->recordTraceForIdentifier_ = NULL;
     111                    this->recordTraceForIdentifier_ = nullptr;
    111112
    112113                    if (temp->getIdentifier() != identifier)
     
    127128
    128129        // finish the initialization of all identifiers
    129         for (std::set<Identifier*>::const_iterator it = initializedIdentifiers.begin(); it != initializedIdentifiers.end(); ++it)
    130             (*it)->finishInitialization();
     130        for (Identifier* initializedIdentifier : initializedIdentifiers)
     131            initializedIdentifier->finishInitialization();
    131132
    132133        // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway.
     
    144145    {
    145146        // check if there are any uninitialized identifiers remaining
    146         for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    147             if (!(*it)->isInitialized())
    148                 orxout(internal_error) << "Identifier was registered late and is not initialized: " << (*it)->getName() << " / " << (*it)->getTypeInfo().name() << endl;
     147        for (Identifier* identifier : this->identifiers_)
     148            if (!identifier->isInitialized())
     149                orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl;
    149150
    150151        // for all initialized identifiers, check if a sample instance behaves as expected according to the class hierarchy
    151         Context temporaryContext(NULL);
    152         for (std::set<Identifier*>::const_iterator it1 = initializedIdentifiers.begin(); it1 != initializedIdentifiers.end(); ++it1)
     152        Context temporaryContext(nullptr);
     153        for (Identifier* initializedIdentifier : initializedIdentifiers)
    153154        {
    154             if (!(*it1)->hasFactory())
     155            if (!initializedIdentifier->hasFactory())
    155156                continue;
    156157
    157             Identifiable* temp = (*it1)->fabricate(&temporaryContext);
    158 
    159             for (std::set<Identifier*>::const_iterator it2 = this->identifiers_.begin(); it2 != this->identifiers_.end(); ++it2)
     158            Identifiable* temp = initializedIdentifier->fabricate(&temporaryContext);
     159
     160            for (Identifier* identifier : this->identifiers_)
    160161            {
    161                 bool isA_AccordingToRtti = (*it2)->canDynamicCastObjectToIdentifierClass(temp);
    162                 bool isA_AccordingToClassHierarchy = temp->isA((*it2));
     162                bool isA_AccordingToRtti = identifier->canDynamicCastObjectToIdentifierClass(temp);
     163                bool isA_AccordingToClassHierarchy = temp->isA(identifier);
    163164
    164165                if (isA_AccordingToRtti != isA_AccordingToClassHierarchy)
    165166                {
    166                     orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << (*it1)->getName() <<
    167                         (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << (*it2)->getName() << " but RTTI says the opposite." << endl;
     167                    orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << initializedIdentifier->getName() <<
     168                        (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << identifier->getName() << " but RTTI says the opposite." << endl;
    168169                }
    169170            }
     
    184185    {
    185186        orxout(internal_status) << "Destroy class-hierarchy" << endl;
    186         for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    187             (*it)->reset();
     187        for (Identifier* identifier : this->identifiers_)
     188            identifier->reset();
    188189    }
    189190
     
    221222            return it->second;
    222223        else
    223             return 0;
     224            return nullptr;
    224225    }
    225226
     
    235236            return it->second;
    236237        else
    237             return 0;
     238            return nullptr;
    238239    }
    239240
     
    249250            return it->second;
    250251        else
    251             return 0;
     252            return nullptr;
    252253    }
    253254
     
    259260    Identifier* IdentifierManager::getIdentifierByTypeInfo(const std::type_info& typeInfo)
    260261    {
    261         // TODO: use std::type_index and a map to find identifiers by type_info (only with c++11)
    262         for (std::set<Identifier*>::iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it)
    263             if ((*it)->getTypeInfo() == typeInfo)
    264                 return (*it);
    265         return 0;
     262        auto it = this->identifierByTypeIndex_.find(typeInfo);
     263        if (it != this->identifierByTypeIndex_.end())
     264            return it->second;
     265        else
     266            return nullptr;
    266267    }
    267268
Note: See TracChangeset for help on using the changeset viewer.