Changeset 10399
- Timestamp:
- Apr 26, 2015, 3:10:58 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core/class
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/class/Identifier.cc
r10396 r10399 197 197 { 198 198 // only Identifiable is allowed to have no parents (even tough it's currently not abstract) 199 orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getType idName() << " is marked as abstract but has no direct parents defined" << endl;199 orxout(internal_error) << "Identifier " << this->getName() << " / " << this->getTypeInfo().name() << " is marked as abstract but has no direct parents defined" << endl; 200 200 orxout(internal_error) << " If this class is not abstract, use RegisterClass(ThisClass);" << endl; 201 201 orxout(internal_error) << " If this class is abstract, use RegisterAbstractClass(ThisClass).inheritsFrom(Class(BaseClass));" << endl; -
code/branches/core7/src/libraries/core/class/Identifier.h
r10395 r10399 117 117 inline const std::string& getName() const { return this->name_; } 118 118 119 /// Returns the name of the class as it is returned by typeid(T).name()120 virtual const std:: string& getTypeidName() = 0;119 /// Returns the type_info of the class as it is returned by typeid(T) 120 virtual const std::type_info& getTypeInfo() = 0; 121 121 122 122 /// Returns the network ID to identify a class through the network. … … 265 265 ClassIdentifier<T>::classIdentifier_s = this; 266 266 267 this->typeidName_ = typeid(T).name();268 267 SuperFunctionInitialization<0, T>::initialize(this); 269 268 } … … 283 282 virtual void updateConfigValues(bool updateChildren = true) const; 284 283 285 virtual const std:: string& getTypeidName()286 { return t his->typeidName_; }284 virtual const std::type_info& getTypeInfo() 285 { return typeid(T); } 287 286 288 287 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const … … 297 296 void updateConfigValues(bool updateChildren, Identifiable*) const; 298 297 299 std::string typeidName_;300 298 static WeakPtr<ClassIdentifier<T> > classIdentifier_s; 301 299 }; … … 312 310 { 313 311 if (ClassIdentifier<T>::classIdentifier_s == NULL) 314 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByType idName(typeid(T).name());312 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeInfo(typeid(T)); 315 313 316 314 OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); -
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 -
code/branches/core7/src/libraries/core/class/IdentifierManager.h
r10395 r10399 38 38 39 39 #include <map> 40 #include <set> 40 41 #include <list> 41 42 #include <string> … … 74 75 Identifier* getIdentifierByLowercaseString(const std::string& name); 75 76 Identifier* getIdentifierByID(uint32_t id); 76 Identifier* getIdentifierByType idName(const std::string& typeidName);77 Identifier* getIdentifierByTypeInfo(const std::type_info& typeInfo); 77 78 78 79 void clearNetworkIDs(); … … 100 101 { hierarchyCreatingCounter_s--; } 101 102 102 std::map<std::string, Identifier*> identifierByTypeidName_; //!< Map with the names as received by typeid(). This is only used internally. 103 103 std::set<Identifier*> identifiers_; //!< All identifiers. This is only used internally. 104 104 std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. 105 105 std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
Note: See TracChangeset
for help on using the changeset viewer.