[Orxonox-commit 3157] r7850 - code/trunk/src/libraries/core

landauf at orxonox.net landauf at orxonox.net
Thu Feb 10 22:26:46 CET 2011


Author: landauf
Date: 2011-02-10 22:26:46 +0100 (Thu, 10 Feb 2011)
New Revision: 7850

Modified:
   code/trunk/src/libraries/core/OrxonoxClass.h
   code/trunk/src/libraries/core/WeakPtr.h
Log:
moved if(object) condition from WeakPtr to DestructionListener

Modified: code/trunk/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/trunk/src/libraries/core/OrxonoxClass.h	2011-02-10 20:52:23 UTC (rev 7849)
+++ code/trunk/src/libraries/core/OrxonoxClass.h	2011-02-10 21:26:46 UTC (rev 7850)
@@ -194,9 +194,9 @@
 
         protected:
             inline void registerAsDestructionListener(OrxonoxClass* object)
-                { object->registerDestructionListener(this); }
+                { if (object) { object->registerDestructionListener(this); } }
             inline void unregisterAsDestructionListener(OrxonoxClass* object)
-                { object->unregisterDestructionListener(this); }
+                { if (object) { object->unregisterDestructionListener(this); } }
 
             virtual void objectDeleted() = 0;
     };

Modified: code/trunk/src/libraries/core/WeakPtr.h
===================================================================
--- code/trunk/src/libraries/core/WeakPtr.h	2011-02-10 20:52:23 UTC (rev 7849)
+++ code/trunk/src/libraries/core/WeakPtr.h	2011-02-10 21:26:46 UTC (rev 7850)
@@ -111,31 +111,26 @@
             /// Constructor: Initializes the weak pointer with a pointer to an object.
             inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0)
             {
-                if (this->base_)
-                    this->registerAsDestructionListener(this->base_);
+                this->registerAsDestructionListener(this->base_);
             }
 
             /// Copy-constructor
             inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0)
             {
-                if (this->base_)
-                    this->registerAsDestructionListener(this->base_);
+                this->registerAsDestructionListener(this->base_);
             }
 
             /// Copy-constructor for weak pointers to objects of another class.
             template <class O>
             inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0)
             {
-                if (this->base_)
-                    this->registerAsDestructionListener(this->base_);
+                this->registerAsDestructionListener(this->base_);
             }
 
             /// Destructor
             inline ~WeakPtr()
             {
-                if (this->base_)
-                    this->unregisterAsDestructionListener(this->base_);
-
+                this->unregisterAsDestructionListener(this->base_);
             }
 
             /// Used to assign a null pointer.
@@ -208,10 +203,8 @@
             /// Swaps the contents of two weak pointers.
             inline void swap(WeakPtr& other)
             {
-                if (this->base_)
-                    this->unregisterAsDestructionListener(this->base_);
-                if (other.base_)
-                    other.unregisterAsDestructionListener(other.base_);
+                this->unregisterAsDestructionListener(this->base_);
+                other.unregisterAsDestructionListener(other.base_);
 
                 {
                     T* temp = this->pointer_;
@@ -224,10 +217,8 @@
                     other.base_ = temp;
                 }
 
-                if (this->base_)
-                    this->registerAsDestructionListener(this->base_);
-                if (other.base_)
-                    other.registerAsDestructionListener(other.base_);
+                this->registerAsDestructionListener(this->base_);
+                other.registerAsDestructionListener(other.base_);
             }
 
             /// Resets the weak pointer (equivalent to assigning a NULL pointer).




More information about the Orxonox-commit mailing list