[Orxonox-commit 1630] r6348 - code/branches/presentation2/src/libraries/core

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Dec 14 00:50:22 CET 2009


Author: rgrieder
Date: 2009-12-14 00:50:22 +0100 (Mon, 14 Dec 2009)
New Revision: 6348

Modified:
   code/branches/presentation2/src/libraries/core/OrxonoxClass.cc
   code/branches/presentation2/src/libraries/core/OrxonoxClass.h
Log:
Adding OrxonoxClass::preDestroy(). This method gets called when an object is about to be destroyed. The only way to prevent that is by overriding preDestroy() and then creating a SmartPtr to 'this'. This allows us to delay the destruction of an object, for instance when destroyed by the loader.

Modified: code/branches/presentation2/src/libraries/core/OrxonoxClass.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/OrxonoxClass.cc	2009-12-13 19:45:30 UTC (rev 6347)
+++ code/branches/presentation2/src/libraries/core/OrxonoxClass.cc	2009-12-13 23:50:22 UTC (rev 6348)
@@ -77,7 +77,11 @@
         assert(this); // Just in case someone tries to delete a NULL pointer
         this->requestedDestruction_ = true;
         if (this->referenceCount_ == 0)
-            delete this;
+        {
+            this->preDestroy();
+            if (this->referenceCount_ == 0)
+                delete this;
+        }
     }
 
     void OrxonoxClass::unregisterObject()

Modified: code/branches/presentation2/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/presentation2/src/libraries/core/OrxonoxClass.h	2009-12-13 19:45:30 UTC (rev 6347)
+++ code/branches/presentation2/src/libraries/core/OrxonoxClass.h	2009-12-13 23:50:22 UTC (rev 6348)
@@ -134,13 +134,20 @@
             template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
             {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
 
+        protected:
+            virtual void preDestroy() {}
+
         private:
             /** @brief Increments the reference counter (for smart pointers). */
             inline void incrementReferenceCount()
                 { ++this->referenceCount_; }
             /** @brief Decrements the reference counter (for smart pointers). */
             inline void decrementReferenceCount()
-                { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } }
+            {
+                --this->referenceCount_;
+                if (this->referenceCount_ == 0 && this->requestedDestruction_)
+                    this->destroy();
+            }
                 
             /** @brief Register a weak pointer which points to this object. */
             template <class T>




More information about the Orxonox-commit mailing list