- Timestamp:
- Jan 10, 2016, 1:54:11 PM (9 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/libraries/core/class/Identifier.h
r10624 r11054 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); … … 269 270 class ClassIdentifier : public Identifier 270 271 { 271 BOOST_STATIC_ASSERT((boost::is_base_of<Identifiable, T>::value));272 static_assert(std::is_base_of<Identifiable, T>::value, "ClassIdentifier can only be used with Identifiables"); 272 273 273 274 #ifndef DOXYGEN_SHOULD_SKIP_THIS … … 279 280 ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable) 280 281 { 281 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name());282 OrxVerify(ClassIdentifier<T>::classIdentifier_s == nullptr, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 282 283 ClassIdentifier<T>::classIdentifier_s = this; 283 284 … … 291 292 bool initializeObject(T* object); 292 293 293 virtual void updateConfigValues(bool updateChildren = true) const ;294 295 virtual const std::type_info& getTypeInfo() 294 virtual void updateConfigValues(bool updateChildren = true) const override; 295 296 virtual const std::type_info& getTypeInfo() override 296 297 { return typeid(T); } 297 298 298 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 299 { return dynamic_cast<T*>(object) != 0; }300 301 virtual void destroyObjects() ;299 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const override 300 { return dynamic_cast<T*>(object) != nullptr; } 301 302 virtual void destroyObjects() override; 302 303 303 304 static ClassIdentifier<T>* getIdentifier(); 304 305 305 306 private: 306 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 307 // non-copyable: 308 ClassIdentifier(const ClassIdentifier<T>&) = delete; 309 ClassIdentifier& operator=(const ClassIdentifier<T>&) = delete; 307 310 308 311 void setConfigValues(T* object, Configurable*) const; … … 321 324 void updateConfigValues(bool updateChildren, Identifiable*) const; 322 325 323 static WeakPtr<ClassIdentifier<T> 326 static WeakPtr<ClassIdentifier<T>> classIdentifier_s; 324 327 }; 325 328 326 329 template <class T> 327 WeakPtr<ClassIdentifier<T> 330 WeakPtr<ClassIdentifier<T>> ClassIdentifier<T>::classIdentifier_s; 328 331 329 332 /** … … 334 337 /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 335 338 { 336 if (ClassIdentifier<T>::classIdentifier_s == NULL)339 if (ClassIdentifier<T>::classIdentifier_s == nullptr) 337 340 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeInfo(typeid(T)); 338 341 339 OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Did you forget to register the class of type " << typeid(T).name() << "?");342 OrxVerify(ClassIdentifier<T>::classIdentifier_s != nullptr, "Did you forget to register the class of type " << typeid(T).name() << "?"); 340 343 return ClassIdentifier<T>::classIdentifier_s; 341 344 } … … 365 368 366 369 // 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)));370 object->objectPointers_.emplace_back(this->getClassID(), static_cast<void*>(object)); 368 371 return false; 369 372 } … … 408 411 void ClassIdentifier<T>::destroyObjects() 409 412 { 410 this->destroyObjects((T*) 0);413 this->destroyObjects((T*)nullptr); 411 414 } 412 415 … … 417 420 void ClassIdentifier<T>::destroyObjects(Listable*) 418 421 { 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; ) 422 ObjectList<T> list(Context::getRootContext()->getObjectList(this)); 423 for (typename ObjectList<T>::iterator it = list.begin(); it != list.end(); ) 423 424 this->destroyObject(*(it++)); 424 425 } … … 451 452 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 452 453 { 453 this->updateConfigValues(updateChildren, static_cast<T*>( NULL));454 this->updateConfigValues(updateChildren, static_cast<T*>(nullptr)); 454 455 } 455 456 … … 460 461 return; 461 462 462 for ( ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)463 this->setConfigValues( *it, *it);463 for (T* object : ObjectList<T>()) 464 this->setConfigValues(object, object); 464 465 465 466 if (updateChildren) 466 for ( std::set<const Identifier*>::const_iterator it = this->getChildren().begin(); it != this->getChildren().end(); ++it)467 (*it)->updateConfigValues(false);467 for (const Identifier* child : this->getChildren()) 468 child->updateConfigValues(false); 468 469 } 469 470 … … 483 484 registered in the class hierarchy. 484 485 @return 485 Returns NULLif the cast is not possible486 Returns nullptr if the cast is not possible 486 487 @note 487 In case of NULLreturn (and using MSVC), a dynamic_cast might still be possible if488 In case of nullptr return (and using MSVC), a dynamic_cast might still be possible if 488 489 a class forgot to register its objects. 489 490 Also note that the function is implemented differently for GCC/MSVC. … … 494 495 #ifdef ORXONOX_COMPILER_MSVC 495 496 typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType; 496 if (source != NULL)497 if (source != nullptr) 497 498 return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID()); 498 499 else 499 return NULL;500 return nullptr; 500 501 #else 501 502 return dynamic_cast<T>(source);
Note: See TracChangeset
for help on using the changeset viewer.