Changeset 11071 for code/trunk/src/libraries/core/class/Identifier.h
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.