- Timestamp:
- Apr 26, 2015, 3:10:58 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
r10395 r10399 62 62 void IdentifierManager::addIdentifier(Identifier* identifier) 63 63 { 64 orxout(verbose, context::identifier) << "Adding identifier for " << identifier->getName() << " / " << identifier->getType idName() << endl;65 66 this->identifier ByTypeidName_[identifier->getTypeidName()] = identifier;64 orxout(verbose, context::identifier) << "Adding identifier for " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl; 65 66 this->identifiers_.insert(identifier); 67 67 this->identifierByString_[identifier->getName()] = identifier; 68 68 this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier; … … 87 87 { 88 88 Context temporaryContext(NULL); 89 for (std:: map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)89 for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it) 90 90 { 91 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << it->second->getName() << ">-Singleton." << endl; 91 Identifier* identifier = (*it); 92 93 orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << identifier->getName() << ">-Singleton." << endl; 92 94 // To initialize the identifier, we create a new object and delete it afterwards. 93 if (i t->second->hasFactory())95 if (identifier->hasFactory()) 94 96 { 95 97 this->identifierTraceOfNewObject_.clear(); 96 this->recordTraceForIdentifier_ = i t->second;97 98 Identifiable* temp = i t->second->fabricate(&temporaryContext);98 this->recordTraceForIdentifier_ = identifier; 99 100 Identifiable* temp = identifier->fabricate(&temporaryContext); 99 101 100 102 this->recordTraceForIdentifier_ = NULL; 101 103 102 if (temp->getIdentifier() != i t->second)103 orxout(internal_error) << "Newly created object of type " << i t->second->getName() << " has unexpected identifier. Did you forget to use RegisterObject(classname)?" << endl;104 105 i t->second->initializeParents(this->identifierTraceOfNewObject_[temp]);104 if (temp->getIdentifier() != identifier) 105 orxout(internal_error) << "Newly created object of type " << identifier->getName() << " has unexpected identifier. Did you forget to use RegisterObject(classname)?" << endl; 106 107 identifier->initializeParents(this->identifierTraceOfNewObject_[temp]); 106 108 107 109 delete temp; 108 110 } 109 111 110 initializedIdentifiers.insert(i t->second);112 initializedIdentifiers.insert(identifier); 111 113 } 112 114 … … 117 119 118 120 // finish the initialization of all identifiers 119 for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it) 120 { 121 if (initializedIdentifiers.find(it->second) != initializedIdentifiers.end()) 122 it->second->finishInitialization(); 121 for (std::set<Identifier*>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it) 122 { 123 Identifier* identifier = (*it); 124 125 if (initializedIdentifiers.find(identifier) != initializedIdentifiers.end()) 126 identifier->finishInitialization(); 123 127 else 124 orxout(internal_error) << "Identifier was registered late and is not initialized: " << i t->second->getName() << " / " << it->second->getTypeidName() << endl;128 orxout(internal_error) << "Identifier was registered late and is not initialized: " << identifier->getName() << " / " << identifier->getTypeInfo().name() << endl; 125 129 } 126 130 … … 139 143 { 140 144 Context temporaryContext(NULL); 141 for (std:: map<std::string, Identifier*>::const_iterator it1 = this->identifierByTypeidName_.begin(); it1 != this->identifierByTypeidName_.end(); ++it1)142 { 143 if (! it1->second->hasFactory())145 for (std::set<Identifier*>::const_iterator it1 = this->identifiers_.begin(); it1 != this->identifiers_.end(); ++it1) 146 { 147 if (!(*it1)->hasFactory()) 144 148 continue; 145 149 146 Identifiable* temp = it1->second->fabricate(&temporaryContext);147 148 for (std:: map<std::string, Identifier*>::const_iterator it2 = this->identifierByTypeidName_.begin(); it2 != this->identifierByTypeidName_.end(); ++it2)150 Identifiable* temp = (*it1)->fabricate(&temporaryContext); 151 152 for (std::set<Identifier*>::const_iterator it2 = this->identifiers_.begin(); it2 != this->identifiers_.end(); ++it2) 149 153 { 150 bool isA_AccordingToRtti = it2->second->canDynamicCastObjectToIdentifierClass(temp);151 bool isA_AccordingToClassHierarchy = temp->isA( it2->second);154 bool isA_AccordingToRtti = (*it2)->canDynamicCastObjectToIdentifierClass(temp); 155 bool isA_AccordingToClassHierarchy = temp->isA((*it2)); 152 156 153 157 if (isA_AccordingToRtti != isA_AccordingToClassHierarchy) 154 158 { 155 orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << it1->second->getName() <<156 (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << it2->second->getName() << " but RTTI says the opposite." << endl;159 orxout(internal_error) << "Class hierarchy does not match RTTI: Class hierarchy claims that " << (*it1)->getName() << 160 (isA_AccordingToClassHierarchy ? " is a " : " is not a ") << (*it2)->getName() << " but RTTI says the opposite." << endl; 157 161 } 158 162 } … … 172 176 void IdentifierManager::destroyAllIdentifiers() 173 177 { 174 for (std:: map<std::string, Identifier*>::iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)175 delete ( it->second);176 177 this->identifier ByTypeidName_.clear();178 for (std::set<Identifier*>::iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it) 179 delete (*it); 180 181 this->identifiers_.clear(); 178 182 this->identifierByString_.clear(); 179 183 this->identifierByLowercaseString_.clear(); … … 250 254 @return The Identifier 251 255 */ 252 Identifier* IdentifierManager::getIdentifierByType idName(const std::string& typeidName)253 { 254 std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName);255 if (it != this->identifierByTypeidName_.end())256 return it->second;257 else258 256 Identifier* IdentifierManager::getIdentifierByTypeInfo(const std::type_info& typeInfo) 257 { 258 // TODO: use std::type_index and a map to find identifiers by type_info (only with c++11) 259 for (std::set<Identifier*>::iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); ++it) 260 if ((*it)->getTypeInfo() == typeInfo) 261 return (*it); 262 return 0; 259 263 } 260 264
Note: See TracChangeset
for help on using the changeset viewer.