Changeset 11071 for code/trunk/src/libraries/core/class
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/class/Identifiable.cc
r10624 r11071 48 48 Identifiable::Identifiable() 49 49 { 50 this->identifier_ = 0;50 this->identifier_ = nullptr; 51 51 this->objectPointers_.reserve(6); // Optimisation 52 52 -
code/trunk/src/libraries/core/class/Identifiable.h
r9667 r11071 98 98 registered in the class hierarchy. 99 99 @return 100 Returns NULLif the no pointer was found.100 Returns nullptr if the no pointer was found. 101 101 */ 102 102 ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID) … … 107 107 return this->objectPointers_[i].second; 108 108 } 109 return NULL;109 return nullptr; 110 110 } 111 111 … … 121 121 122 122 /// 'Fast map' that holds this-pointers of all derived types 123 std::vector<std::pair<unsigned int, void*> 123 std::vector<std::pair<unsigned int, void*>> objectPointers_; 124 124 }; 125 125 } -
code/trunk/src/libraries/core/class/Identifier.cc
r10624 r11071 79 79 delete this->factory_; 80 80 81 for ( std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)82 delete (*it);81 for (const InheritsFrom* manualDirectParent : this->manualDirectParents_) 82 delete manualDirectParent; 83 83 84 84 // erase this Identifier from all related identifiers 85 for ( std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)86 const_cast<Identifier*>( *it)->children_.erase(this);87 for ( std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)88 const_cast<Identifier*>( *it)->directChildren_.erase(this);89 for ( std::set<const Identifier*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)90 const_cast<Identifier*>( *it)->parents_.remove(this);91 for ( std::set<const Identifier*>::const_iterator it = this->directChildren_.begin(); it != this->directChildren_.end(); ++it)92 const_cast<Identifier*>( *it)->directParents_.remove(this);93 94 for ( std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)95 delete ( it->second);96 for ( std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)97 delete ( it->second);98 for ( std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)99 delete ( it->second);85 for (const Identifier* parent : this->parents_) 86 const_cast<Identifier*>(parent)->children_.erase(this); 87 for (const Identifier* directParent : this->directParents_) 88 const_cast<Identifier*>(directParent)->directChildren_.erase(this); 89 for (const Identifier* child : this->children_) 90 const_cast<Identifier*>(child)->parents_.remove(this); 91 for (const Identifier* directChild : this->directChildren_) 92 const_cast<Identifier*>(directChild)->directParents_.remove(this); 93 94 for (const auto& mapEntry : this->configValues_) 95 delete (mapEntry.second); 96 for (const auto& mapEntry : this->xmlportParamContainers_) 97 delete (mapEntry.second); 98 for (const auto& mapEntry : this->xmlportObjectContainers_) 99 delete (mapEntry.second); 100 100 } 101 101 … … 117 117 orxout(user_error) << "Aborting..." << endl; 118 118 abort(); 119 return 0;119 return nullptr; 120 120 } 121 121 } … … 157 157 if (this->directParents_.empty()) 158 158 { 159 for ( std::list<const Identifier*>::const_iterator it = initializationTrace.begin(); it != initializationTrace.end(); ++it)160 if ( *it!= this)161 this->parents_.push_back( *it);159 for (const Identifier* identifier : initializationTrace) 160 if (identifier != this) 161 this->parents_.push_back(identifier); 162 162 } 163 163 else … … 184 184 185 185 // initialize all parents 186 for ( std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)187 const_cast<Identifier*>( *it)->finishInitialization(); // initialize parent186 for (const Identifier* parent : this->parents_) 187 const_cast<Identifier*>(parent)->finishInitialization(); // initialize parent 188 188 189 189 // parents of parents are no direct parents of this identifier 190 190 this->directParents_ = this->parents_; 191 for ( std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)192 for ( std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)193 this->directParents_.remove( *it_parent_parent);191 for (const Identifier* parent : this->parents_) 192 for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_) 193 this->directParents_.remove(parent_parent); 194 194 195 195 this->verifyIdentifierTrace(); … … 200 200 201 201 // initialize all direct parents 202 for ( std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)202 for (const InheritsFrom* manualDirectParent : this->manualDirectParents_) 203 203 { 204 Identifier* directParent = (*it)->getParent();204 Identifier* directParent = manualDirectParent->getParent(); 205 205 this->directParents_.push_back(directParent); 206 206 directParent->finishInitialization(); // initialize parent … … 208 208 209 209 // direct parents and their parents are also parents of this identifier (but only add them once) 210 for ( std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)210 for (const Identifier* parent : this->directParents_) 211 211 { 212 for ( std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)213 this->addIfNotExists(this->parents_, *it_parent_parent);214 this->addIfNotExists(this->parents_, *it_parent);212 for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_) 213 this->addIfNotExists(this->parents_, parent_parent); 214 this->addIfNotExists(this->parents_, parent); 215 215 } 216 216 } … … 224 224 225 225 // tell all parents that this identifier is a child 226 for ( std::list<const Identifier*>::const_iterator it = this->parents_.begin(); it != this->parents_.end(); ++it)227 const_cast<Identifier*>( *it)->children_.insert(this);226 for (const Identifier* parent : this->parents_) 227 const_cast<Identifier*>(parent)->children_.insert(this); 228 228 229 229 // tell all direct parents that this identifier is a direct child 230 for ( std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)231 { 232 const_cast<Identifier*>( *it)->directChildren_.insert(this);230 for (const Identifier* directChild : this->directParents_) 231 { 232 const_cast<Identifier*>(directChild)->directChildren_.insert(this); 233 233 234 234 // Create the super-function dependencies 235 (*it)->createSuperFunctionCaller();235 directChild->createSuperFunctionCaller(); 236 236 } 237 237 … … 261 261 262 262 // if any parent class is virtual, it will be instantiated first, so we need to add them first. 263 for ( std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)264 { 265 if ( (*it_parent)->isVirtualBase())263 for (const Identifier* parent : this->parents_) 264 { 265 if (parent->isVirtualBase()) 266 266 { 267 for ( std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)268 this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);269 this->addIfNotExists(expectedIdentifierTrace, *it_parent);267 for (const Identifier* parent_parent : const_cast<Identifier*>(parent)->parents_) 268 this->addIfNotExists(expectedIdentifierTrace, parent_parent); 269 this->addIfNotExists(expectedIdentifierTrace, parent); 270 270 } 271 271 } 272 272 273 273 // now all direct parents get created recursively. already added identifiers (e.g. virtual base classes) are not added again. 274 for ( std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)275 { 276 for ( std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)277 this->addIfNotExists(expectedIdentifierTrace, *it_parent_parent);278 this->addIfNotExists(expectedIdentifierTrace, *it_parent);274 for (const Identifier* directParent : this->directParents_) 275 { 276 for (const Identifier* parent_parent : const_cast<Identifier*>(directParent)->parents_) 277 this->addIfNotExists(expectedIdentifierTrace, parent_parent); 278 this->addIfNotExists(expectedIdentifierTrace, directParent); 279 279 } 280 280 … … 285 285 286 286 orxout(internal_warning) << " Actual trace (after creating a sample instance):" << endl << " "; 287 for ( std::list<const Identifier*>::const_iterator it_parent = this->parents_.begin(); it_parent != this->parents_.end(); ++it_parent)288 orxout(internal_warning) << " " << (*it_parent)->getName();287 for (const Identifier* parent : this->parents_) 288 orxout(internal_warning) << " " << parent->getName(); 289 289 orxout(internal_warning) << endl; 290 290 291 291 orxout(internal_warning) << " Expected trace (according to class hierarchy definitions):" << endl << " "; 292 for ( std::list<const Identifier*>::const_iterator it_parent = expectedIdentifierTrace.begin(); it_parent != expectedIdentifierTrace.end(); ++it_parent)293 orxout(internal_warning) << " " << (*it_parent)->getName();292 for (const Identifier* parent : expectedIdentifierTrace) 293 orxout(internal_warning) << " " << parent->getName(); 294 294 orxout(internal_warning) << endl; 295 295 296 296 orxout(internal_warning) << " Direct parents (according to class hierarchy definitions):" << endl << " "; 297 for ( std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)298 orxout(internal_warning) << " " << (*it_parent)->getName();297 for (const Identifier* directParent : this->directParents_) 298 orxout(internal_warning) << " " << directParent->getName(); 299 299 orxout(internal_warning) << endl; 300 300 } … … 393 393 return it->second; 394 394 else 395 return 0;395 return nullptr; 396 396 } 397 397 … … 407 407 return it->second; 408 408 else 409 return 0;409 return nullptr; 410 410 } 411 411 … … 438 438 return it->second; 439 439 else 440 return 0;440 return nullptr; 441 441 } 442 442 -
code/trunk/src/libraries/core/class/Identifier.h
r10624 r11071 56 56 object->getIdentifier()->getName(); // returns "MyClass" 57 57 58 Identifiable* other = object->getIdentifier()->fabricate( 0); // fabricates a new instance of MyClass58 Identifiable* other = object->getIdentifier()->fabricate(nullptr); // fabricates a new instance of MyClass 59 59 60 60 … … 80 80 #include <typeinfo> 81 81 #include <loki/TypeTraits.h> 82 #include <boost/static_assert.hpp>83 #include <boost/type_traits/is_base_of.hpp>84 82 85 83 #include "util/Output.h" … … 120 118 public: 121 119 Identifier(const std::string& name, Factory* factory, bool bLoadable); 122 Identifier(const Identifier& identifier); // don't copy123 120 virtual ~Identifier(); 121 122 // non-copyable: 123 Identifier(const Identifier&) = delete; 124 Identifier& operator=(const Identifier&) = delete; 124 125 125 126 /// Returns the name of the class the Identifier belongs to. … … 137 138 138 139 /// Returns true if the Identifier has a Factory. 139 inline bool hasFactory() const { return (this->factory_ != 0); }140 inline bool hasFactory() const { return (this->factory_ != nullptr); } 140 141 141 142 Identifiable* fabricate(Context* context); … … 203 204 /// Returns the map that stores all XMLPort params. 204 205 inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; } 205 /// Returns a const_iterator to the beginning of the map that stores all XMLPort params.206 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); }207 /// Returns a const_iterator to the end of the map that stores all XMLPort params.208 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); }209 206 210 207 /// Returns the map that stores all XMLPort objects. 211 208 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; } 212 /// Returns a const_iterator to the beginning of the map that stores all XMLPort objects.213 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); }214 /// Returns a const_iterator to the end of the map that stores all XMLPort objects.215 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }216 209 217 210 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); … … 269 262 class ClassIdentifier : public Identifier 270 263 { 271 BOOST_STATIC_ASSERT((boost::is_base_of<Identifiable, T>::value));264 static_assert(std::is_base_of<Identifiable, T>::value, "ClassIdentifier can only be used with Identifiables"); 272 265 273 266 #ifndef DOXYGEN_SHOULD_SKIP_THIS … … 279 272 ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable) 280 273 { 281 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());274 OrxVerify(ClassIdentifier<T>::classIdentifier_s == nullptr, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 282 275 ClassIdentifier<T>::classIdentifier_s = this; 283 276 … … 291 284 bool initializeObject(T* object); 292 285 293 virtual void updateConfigValues(bool updateChildren = true) const ;294 295 virtual const std::type_info& getTypeInfo() 286 virtual void updateConfigValues(bool updateChildren = true) const override; 287 288 virtual const std::type_info& getTypeInfo() override 296 289 { return typeid(T); } 297 290 298 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 299 { return dynamic_cast<T*>(object) != 0; }300 301 virtual void destroyObjects() ;291 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const override 292 { return dynamic_cast<T*>(object) != nullptr; } 293 294 virtual void destroyObjects() override; 302 295 303 296 static ClassIdentifier<T>* getIdentifier(); 304 297 305 298 private: 306 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 299 // non-copyable: 300 ClassIdentifier(const ClassIdentifier<T>&) = delete; 301 ClassIdentifier& operator=(const ClassIdentifier<T>&) = delete; 307 302 308 303 void setConfigValues(T* object, Configurable*) const; … … 321 316 void updateConfigValues(bool updateChildren, Identifiable*) const; 322 317 323 static WeakPtr<ClassIdentifier<T> 318 static WeakPtr<ClassIdentifier<T>> classIdentifier_s; 324 319 }; 325 320 326 321 template <class T> 327 WeakPtr<ClassIdentifier<T> 322 WeakPtr<ClassIdentifier<T>> ClassIdentifier<T>::classIdentifier_s; 328 323 329 324 /** … … 334 329 /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 335 330 { 336 if (ClassIdentifier<T>::classIdentifier_s == NULL)331 if (ClassIdentifier<T>::classIdentifier_s == nullptr) 337 332 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeInfo(typeid(T)); 338 333 339 OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Did you forget to register the class of type " << typeid(T).name() << "?");334 OrxVerify(ClassIdentifier<T>::classIdentifier_s != nullptr, "Did you forget to register the class of type " << typeid(T).name() << "?"); 340 335 return ClassIdentifier<T>::classIdentifier_s; 341 336 } … … 365 360 366 361 // Add pointer of type T to the map in the Identifiable instance that enables "dynamic_casts" 367 object->objectPointers_. push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));362 object->objectPointers_.emplace_back(this->getClassID(), static_cast<void*>(object)); 368 363 return false; 369 364 } … … 408 403 void ClassIdentifier<T>::destroyObjects() 409 404 { 410 this->destroyObjects((T*) 0);405 this->destroyObjects((T*)nullptr); 411 406 } 412 407 … … 417 412 void ClassIdentifier<T>::destroyObjects(Listable*) 418 413 { 419 ObjectListBase* objectList = Context::getRootContext()->getObjectList(this); 420 ObjectListElement<T>* begin = static_cast<ObjectListElement<T>*>(objectList->begin()); 421 ObjectListElement<T>* end = static_cast<ObjectListElement<T>*>(objectList->end()); 422 for (typename ObjectList<T>::iterator it = begin; it != end; ) 414 ObjectList<T> list(Context::getRootContext()->getObjectList(this)); 415 for (typename ObjectList<T>::iterator it = list.begin(); it != list.end(); ) 423 416 this->destroyObject(*(it++)); 424 417 } … … 451 444 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 452 445 { 453 this->updateConfigValues(updateChildren, static_cast<T*>( NULL));446 this->updateConfigValues(updateChildren, static_cast<T*>(nullptr)); 454 447 } 455 448 … … 460 453 return; 461 454 462 for ( ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)463 this->setConfigValues( *it, *it);455 for (T* object : ObjectList<T>()) 456 this->setConfigValues(object, object); 464 457 465 458 if (updateChildren) 466 for ( std::set<const Identifier*>::const_iterator it = this->getChildren().begin(); it != this->getChildren().end(); ++it)467 (*it)->updateConfigValues(false);459 for (const Identifier* child : this->getChildren()) 460 child->updateConfigValues(false); 468 461 } 469 462 … … 483 476 registered in the class hierarchy. 484 477 @return 485 Returns NULLif the cast is not possible478 Returns nullptr if the cast is not possible 486 479 @note 487 In case of NULLreturn (and using MSVC), a dynamic_cast might still be possible if480 In case of nullptr return (and using MSVC), a dynamic_cast might still be possible if 488 481 a class forgot to register its objects. 489 482 Also note that the function is implemented differently for GCC/MSVC. … … 494 487 #ifdef ORXONOX_COMPILER_MSVC 495 488 typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType; 496 if (source != NULL)489 if (source != nullptr) 497 490 return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID()); 498 491 else 499 return NULL;492 return nullptr; 500 493 #else 501 494 return dynamic_cast<T>(source); -
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 -
code/trunk/src/libraries/core/class/IdentifierManager.h
r10624 r11071 37 37 #include "core/CorePrereqs.h" 38 38 39 #include <typeindex> 39 40 #include <map> 41 #include <unordered_map> 40 42 #include <set> 41 43 #include <list> … … 52 54 public: 53 55 IdentifierManager(); 54 ~IdentifierManager() {}56 ~IdentifierManager() = default; 55 57 56 58 void addIdentifier(Identifier* identifier); … … 93 95 94 96 private: 95 IdentifierManager(const IdentifierManager&); // not implemented 97 // non-copyable: 98 IdentifierManager(const IdentifierManager&) = delete; 99 IdentifierManager& operator=(const IdentifierManager&) = delete; 96 100 97 101 /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. … … 102 106 { hierarchyCreatingCounter_s--; } 103 107 104 std::set<Identifier*> identifiers_; //!< All identifiers. This is only used internally. 105 std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. 106 std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. 107 std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. 108 std::set<Identifier*> identifiers_; //!< All identifiers. This is only used internally. 109 std::unordered_map<std::type_index, Identifier*> identifierByTypeIndex_; //!< Map that stores all Identifiers with their type_index. 110 std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names. 111 std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase. 112 std::map<uint32_t, Identifier*> identifierByNetworkId_; //!< Returns the map that stores all Identifiers with their network IDs. 108 113 109 114 int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) … … 111 116 /// Used while creating the object hierarchy to keep track of the identifiers of a newly created object (and all other objects that get created as 112 117 /// a consequence of this, e.g. nested member objects). 113 std::map<Identifiable*, std::list<const Identifier*> 118 std::map<Identifiable*, std::list<const Identifier*>> identifierTraceOfNewObject_; 114 119 Identifier* recordTraceForIdentifier_; //!< The identifier for which we want to record the trace of identifiers during object creation. If null, no trace is recorded. 115 120 -
code/trunk/src/libraries/core/class/SubclassIdentifier.h
r9667 r11071 127 127 else 128 128 { 129 orxout(internal_error) << "Can't assign NULLidentifier" << endl;129 orxout(internal_error) << "Can't assign nullptr identifier" << endl; 130 130 } 131 131 } … … 189 189 orxout(user_error) << "Aborting..." << endl; 190 190 abort(); 191 return 0;191 return nullptr; 192 192 } 193 193 } -
code/trunk/src/libraries/core/class/Super.h
r10624 r11071 94 94 static void superCheck() \ 95 95 { \ 96 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>( 0)); \96 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(nullptr)); \ 97 97 SuperFunctionCondition<functionnumber + 1, T, 0, templatehack2>::superCheck(); \ 98 98 } \ … … 103 103 { \ 104 104 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); \ 105 for ( std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it) \105 for (const Identifier* child : identifier->getDirectChildren()) \ 106 106 { \ 107 if (((ClassIdentifier<T>*) (*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \107 if (((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) \ 108 108 { \ 109 delete ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_; \110 ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_ = 0; \111 ((ClassIdentifier<T>*) (*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \109 delete ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_; \ 110 ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = nullptr; \ 111 ((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ = false; \ 112 112 } \ 113 113 \ 114 if (!((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_) \114 if (!((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) \ 115 115 { \ 116 orxout(verbose, context::super) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*) (*it))->getName() << endl; \117 ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \116 orxout(verbose, context::super) << "Added SuperFunctionCaller for " << #functionname << ": " << ClassIdentifier<T>::getIdentifier()->getName() << " <- " << ((ClassIdentifier<T>*)child)->getName() << endl; \ 117 ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; \ 118 118 } \ 119 else if (((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier()) \120 orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*) (*it))->getName() << " calls function of " << ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl; \119 else if (((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier()) \ 120 orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)child)->getName() << " calls function of " << ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl; \ 121 121 } \ 122 122 } \ … … 154 154 // This call to the apply-function is the whole check. By calling the function with 155 155 // a T* pointer, the right function get's called. 156 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>( 0));156 SuperFunctionCondition<functionnumber, T, 0, templatehack2>::apply(static_cast<T*>(nullptr)); 157 157 158 158 // Go go the superCheck for of next super-function (functionnumber + 1) … … 171 171 172 172 // Iterate through all children 173 for ( std::set<const Identifier*>::iterator it = identifier->getDirectChildren().begin(); it != identifier->getDirectChildren().end(); ++it)173 for (const Identifier* child : identifier->getDirectChildren()) 174 174 { 175 175 // Check if the caller is a fallback-caller 176 if (((ClassIdentifier<T>*) (*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)176 if (((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) 177 177 { 178 178 // Delete the fallback caller an prepare to get a real caller 179 delete ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_;180 ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_ = 0;181 ((ClassIdentifier<T>*) (*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false;179 delete ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_; 180 ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = nullptr; 181 ((ClassIdentifier<T>*)child)->bSuperFunctionCaller_##functionname##_isFallback_ = false; 182 182 } 183 183 184 184 // Check if there's not already a caller 185 if (!((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_)185 if (!((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_) 186 186 { 187 187 // Add the SuperFunctionCaller 188 orxout(verbose, context::super) << "adding functionpointer to " << ((ClassIdentifier<T>*) (*it))->getName() << endl;189 ((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>;188 orxout(verbose, context::super) << "adding functionpointer to " << ((ClassIdentifier<T>*)child)->getName() << endl; 189 ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_##functionname <T>; 190 190 } 191 191 192 192 // If there is already a caller, but for another parent, print a warning 193 else if (((ClassIdentifier<T>*) (*it))->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier())194 orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*) (*it))->getName() << " calls function of " << ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl;193 else if (((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier() != ClassIdentifier<T>::getIdentifier()) 194 orxout(internal_warning, context::super) << "SuperFunctionCaller for " << #functionname << " in " << ((ClassIdentifier<T>*)child)->getName() << " calls function of " << ((ClassIdentifier<T>*)child)->superFunctionCaller_##functionname##_->getParentIdentifier()->getName() << " but " << ClassIdentifier<T>::getIdentifier()->getName() << " is also possible (do you use multiple inheritance?)" << endl; 195 195 } 196 196 } … … 584 584 // Creates the super-function-callers by calling the first SuperFunctionCondition check 585 585 // This get's called within the initialization of an Identifier 586 virtual void createSuperFunctionCaller() const 586 virtual void createSuperFunctionCaller() const override 587 587 { 588 588 SuperFunctionCondition<0, T, 0, 0>::superCheck();
Note: See TracChangeset
for help on using the changeset viewer.