Changeset 10624 for code/trunk/src/libraries/core/object
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 1 deleted
- 12 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/object/CMakeLists.txt
r9667 r10624 2 2 Context.cc 3 3 Destroyable.cc 4 DestroyLaterManager.cc 4 5 Listable.cc 5 6 ObjectListBase.cc -
code/trunk/src/libraries/core/object/Context.cc
r9667 r10624 76 76 /*static*/ void Context::setRootContext(Context* context) 77 77 { 78 if (Context::rootContext_s)79 delete Context::rootContext_s;80 78 Context::rootContext_s = context; 79 } 80 81 /*static*/ void Context::destroyRootContext() 82 { 83 delete Context::rootContext_s; 84 Context::rootContext_s = NULL; 81 85 } 82 86 83 87 /*static*/ Context* Context::getRootContext() 84 88 { 85 if (!Context::rootContext_s) 86 Context::rootContext_s = new Context(NULL); 89 OrxVerify(Context::rootContext_s != NULL, "Root Context is undefined"); 87 90 return Context::rootContext_s; 88 91 } … … 97 100 return this->objectLists_[classID]; 98 101 } 102 103 void Context::destroyObjectList(const Identifier* identifier) 104 { 105 ObjectListBase* objectList = this->getObjectList(identifier); 106 delete objectList; 107 this->objectLists_[identifier->getClassID()] = NULL; 108 } 99 109 } -
code/trunk/src/libraries/core/object/Context.h
r9667 r10624 47 47 public: 48 48 static void setRootContext(Context* context); 49 static void destroyRootContext(); 49 50 static Context* getRootContext(); 50 51 … … 71 72 } 72 73 74 void destroyObjectList(const Identifier* identifier); 75 73 76 private: 74 77 Context* parentContext_; -
code/trunk/src/libraries/core/object/Destroyable.cc
r9944 r10624 33 33 34 34 #include "Destroyable.h" 35 #include "DestroyLaterManager.h" 35 36 36 37 #include <cassert> … … 60 61 61 62 /** 62 @brief Deletes the object if no @ref orxonox::S martPtr "smartpointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.63 Always call destroy() instead of using 'delete' directly, otherwise s martpointers won't work.63 @brief Deletes the object if no @ref orxonox::StrongPtr "strong pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible. 64 Always call destroy() instead of using 'delete' directly, otherwise strong pointers won't work. 64 65 */ 65 66 void Destroyable::destroy() … … 74 75 } 75 76 } 77 78 /** 79 * Works like @ref destroy() but doesn't destroy the object until the current tick has ended. 80 */ 81 void Destroyable::destroyLater() 82 { 83 // register in DestroyLaterManager - this ensures that a strongPtr points to this object and keeps it alive for a while 84 DestroyLaterManager::getInstance().retain(this); 85 86 // request destruction -> object will be deleted after all strongPtrs (including the one in DestroyLaterManager) were destroyed. 87 this->destroy(); 88 } 76 89 } -
code/trunk/src/libraries/core/object/Destroyable.h
r9944 r10624 30 30 @file 31 31 @ingroup Object 32 @brief Declaration of Destroyable, the base class of all objects which can be used with S martPtr and WeakPtr.32 @brief Declaration of Destroyable, the base class of all objects which can be used with StrongPtr and WeakPtr. 33 33 */ 34 34 … … 43 43 { 44 44 /** 45 @brief Classes must inherit from this class if they should be used with S martPtr or WeakPtr.45 @brief Classes must inherit from this class if they should be used with StrongPtr or WeakPtr. 46 46 */ 47 47 class _CoreExport Destroyable 48 48 { 49 49 template <class T> 50 friend class S martPtr;50 friend class StrongPtr; 51 51 52 52 friend class DestructionListener; … … 57 57 58 58 void destroy(); 59 void destroyLater(); 59 60 60 /// Returns the number of @ref orxonox::S martPtr "smartpointers" that point to this object.61 /// Returns the number of @ref orxonox::StrongPtr "strong pointers" that point to this object. 61 62 inline unsigned int getReferenceCount() const 62 63 { return this->referenceCount_; } 63 64 64 65 protected: 65 /// This virtual function is called if destroy() is called and no S martPtr points to this object. Used in some cases to create a new SmartPtr to66 /// This virtual function is called if destroy() is called and no StrongPtr points to this object. Used in some cases to create a new StrongPtr to 66 67 /// prevent destruction. Don't call this function directly - use destroy() instead. 67 68 virtual void preDestroy() {} 68 69 69 70 private: 70 /// Increments the reference counter (for s martpointers).71 /// Increments the reference counter (for strong pointers). 71 72 inline void incrementReferenceCount() 72 73 { ++this->referenceCount_; } 73 /// Decrements the reference counter (for s martpointers).74 /// Decrements the reference counter (for strong pointers). 74 75 inline void decrementReferenceCount() 75 76 { … … 86 87 { this->destructionListeners_.erase(pointer); } 87 88 88 int referenceCount_; //!< Counts the references from s martpointers to this object89 int referenceCount_; //!< Counts the references from strong pointers to this object 89 90 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 90 91 std::set<DestructionListener*> destructionListeners_; //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies) -
code/trunk/src/libraries/core/object/Iterator.h
r9667 r10624 76 76 @brief Constructor: Sets the element, whereon the iterator points, to zero. 77 77 */ 78 inline Iterator() : IteratorBase<T, Iterator<T> >( NULL) {}78 inline Iterator() : IteratorBase<T, Iterator<T> >() {} 79 79 80 80 /** … … 88 88 @param other The other Iterator 89 89 */ 90 inline Iterator(const Iterator <T>& other) : IteratorBase<T, Iterator<T> >(other) {}90 inline Iterator(const IteratorBase<T, Iterator<T> >& other) : IteratorBase<T, Iterator<T> >(other) {} 91 91 92 92 /** -
code/trunk/src/libraries/core/object/IteratorBase.h
r9667 r10624 37 37 38 38 #include "core/CorePrereqs.h" 39 40 #include <boost/static_assert.hpp> 41 #include <boost/type_traits/is_base_of.hpp> 39 42 40 43 #include "ObjectListBase.h" … … 49 52 class IteratorBase : public ObjectListElementRemovalListener 50 53 { 54 BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value)); 55 56 protected: 57 /** 58 @brief Constructor: Sets the element, whereon the iterator points, to the given element. 59 This constructor is protected and only for internal usage (don't mess with the BaseElements directly). 60 */ 61 inline IteratorBase(ObjectListBaseElement* element = NULL) 62 { 63 this->element_ = element; 64 this->registerIterator(); 65 } 66 67 51 68 public: 52 69 /** 53 @brief Constructor: Sets the element, whereon the iterator points, to zero. 54 */ 55 inline IteratorBase(ObjectListBaseElement* element) 56 { 70 @brief Constructor: Sets the element, whereon the iterator points, to the given element. 71 */ 72 inline IteratorBase(ObjectListElement<T>* element) 73 { 74 this->element_ = element; 75 this->registerIterator(); 76 } 77 78 /** 79 @brief Constructor: Sets the element, whereon the iterator points, to the given element of another type. 80 The element's type O must be a derivative of the Iterator's type T. 81 */ 82 template <class O> 83 inline IteratorBase(ObjectListElement<O>* element) 84 { 85 (void)static_cast<T*>((O*)NULL); // Check type: The element's type O must be a derivative of the Iterator's type T. 57 86 this->element_ = element; 58 87 this->registerIterator(); -
code/trunk/src/libraries/core/object/Listable.cc
r9667 r10624 39 39 namespace orxonox 40 40 { 41 RegisterClass(Listable) ;41 RegisterClass(Listable).virtualBase(); 42 42 43 43 /** -
code/trunk/src/libraries/core/object/ObjectList.h
r9667 r10624 47 47 #include "core/CorePrereqs.h" 48 48 49 #include <boost/static_assert.hpp> 50 #include <boost/type_traits/is_base_of.hpp> 51 49 52 #include "ObjectListBase.h" 50 53 #include "ObjectListIterator.h" … … 66 69 class ObjectList 67 70 { 71 BOOST_STATIC_ASSERT((boost::is_base_of<Listable, T>::value)); 72 68 73 public: 69 74 typedef ObjectListIterator<T> iterator; 70 75 76 /// Returns the size of the list (for the root context) 77 inline static size_t size() 78 { return size(Context::getRootContext()); } 71 79 /// Returns the size of the list 72 inline static size_t size( )80 inline static size_t size(Context* context) 73 81 { 74 return Context::getRootContext()->getObjectList<T>()->size();82 return context->getObjectList<T>()->size(); 75 83 } 76 84 85 /// Returns an Iterator to the first element in the list (for the root context). 86 inline static ObjectListElement<T>* begin() 87 { return begin(Context::getRootContext()); } 77 88 /// Returns an Iterator to the first element in the list. 78 inline static ObjectListElement<T>* begin( )89 inline static ObjectListElement<T>* begin(Context* context) 79 90 { 80 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();91 ObjectListBase* list = context->getObjectList<T>(); 81 92 return static_cast<ObjectListElement<T>*>(list->begin()); 82 93 } 83 94 95 /// Returns an Iterator to the element after the last element in the list (for the root context). 96 inline static ObjectListElement<T>* end() 97 { return end(Context::getRootContext()); } 84 98 /// Returns an Iterator to the element after the last element in the list. 85 inline static ObjectListElement<T>* end( )99 inline static ObjectListElement<T>* end(Context* context) 86 100 { 87 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();101 ObjectListBase* list = context->getObjectList<T>(); 88 102 return static_cast<ObjectListElement<T>*>(list->end()); 89 103 } 90 104 105 /// Returns an Iterator to the last element in the list (for the root context). 106 inline static ObjectListElement<T>* rbegin() 107 { return rbegin(Context::getRootContext()); } 91 108 /// Returns an Iterator to the last element in the list. 92 inline static ObjectListElement<T>* rbegin( )109 inline static ObjectListElement<T>* rbegin(Context* context) 93 110 { 94 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();111 ObjectListBase* list = context->getObjectList<T>(); 95 112 return static_cast<ObjectListElement<T>*>(list->rbegin()); 96 113 } 97 114 115 /// Returns an Iterator to the element before the first element in the list (for the root context). 116 inline static ObjectListElement<T>* rend() 117 { return rend(Context::getRootContext()); } 98 118 /// Returns an Iterator to the element before the first element in the list. 99 inline static ObjectListElement<T>* rend( )119 inline static ObjectListElement<T>* rend(Context* context) 100 120 { 101 ObjectListBase* list = Context::getRootContext()->getObjectList<T>();121 ObjectListBase* list = context->getObjectList<T>(); 102 122 return static_cast<ObjectListElement<T>*>(list->rend()); 103 123 } -
code/trunk/src/libraries/core/object/ObjectListIterator.h
r9667 r10624 74 74 @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. 75 75 */ 76 inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >( NULL) {}76 inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >() {} 77 77 78 78 /** -
code/trunk/src/libraries/core/object/WeakPtr.h
r9571 r10624 104 104 } 105 105 106 /// Constructor: Used to explicitly initialize the weak pointer with a null pointer107 inline WeakPtr(int) : pointer_(0), base_(0), callback_(0)108 {109 }110 111 106 /// Constructor: Initializes the weak pointer with a pointer to an object. 112 107 inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0) … … 132 127 { 133 128 this->unregisterAsDestructionListener(this->base_); 134 }135 136 /// Used to assign a null pointer.137 inline WeakPtr& operator=(int)138 {139 WeakPtr(0).swap(*this);140 return *this;141 129 } 142 130
Note: See TracChangeset
for help on using the changeset viewer.