- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/class/IdentifierManager.cc
r10624 r11071 44 44 namespace orxonox 45 45 { 46 IdentifierManager* IdentifierManager::singletonPtr_s = 0;46 IdentifierManager* IdentifierManager::singletonPtr_s = nullptr; 47 47 48 48 IdentifierManager::IdentifierManager() 49 49 { 50 50 this->hierarchyCreatingCounter_s = 0; 51 this->recordTraceForIdentifier_ = NULL;51 this->recordTraceForIdentifier_ = nullptr; 52 52 } 53 53 … … 60 60 61 61 this->identifiers_.insert(identifier); 62 this->identifierByTypeIndex_[identifier->getTypeInfo()] = identifier; 62 63 this->identifierByString_[identifier->getName()] = identifier; 63 64 this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier; … … 71 72 { 72 73 this->identifiers_.erase(identifier); 74 this->identifierByTypeIndex_.erase(identifier->getTypeInfo()); 73 75 this->identifierByString_.erase(identifier->getName()); 74 76 this->identifierByLowercaseString_.erase(getLowercase(identifier->getName())); … … 92 94 // iterate over all identifiers, create one instance of each class and initialize the identifiers 93 95 { 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_) 96 98 { 97 Identifier* identifier = (*it);98 99 if (identifier->isInitialized()) 99 100 continue; … … 108 109 Identifiable* temp = identifier->fabricate(&temporaryContext); 109 110 110 this->recordTraceForIdentifier_ = NULL;111 this->recordTraceForIdentifier_ = nullptr; 111 112 112 113 if (temp->getIdentifier() != identifier) … … 127 128 128 129 // 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(); 131 132 132 133 // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway. … … 144 145 { 145 146 // 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; 149 150 150 151 // 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) 153 154 { 154 if (! (*it1)->hasFactory())155 if (!initializedIdentifier->hasFactory()) 155 156 continue; 156 157 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_) 160 161 { 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); 163 164 164 165 if (isA_AccordingToRtti != isA_AccordingToClassHierarchy) 165 166 { 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; 168 169 } 169 170 } … … 184 185 { 185 186 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(); 188 189 } 189 190 … … 221 222 return it->second; 222 223 else 223 return 0;224 return nullptr; 224 225 } 225 226 … … 235 236 return it->second; 236 237 else 237 return 0;238 return nullptr; 238 239 } 239 240 … … 249 250 return it->second; 250 251 else 251 return 0;252 return nullptr; 252 253 } 253 254 … … 259 260 Identifier* IdentifierManager::getIdentifierByTypeInfo(const std::type_info& typeInfo) 260 261 { 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; 266 267 } 267 268
Note: See TracChangeset
for help on using the changeset viewer.