[Orxonox-commit 6087] r10745 - in code/branches/cpp11_v2/src/libraries: core/object util

landauf at orxonox.net landauf at orxonox.net
Sun Nov 1 22:06:23 CET 2015


Author: landauf
Date: 2015-11-01 22:06:23 +0100 (Sun, 01 Nov 2015)
New Revision: 10745

Modified:
   code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h
   code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h
   code/branches/cpp11_v2/src/libraries/util/SharedPtr.h
Log:
added move-constructor for StrongPtr and SharedPtr. for WeakPtr this is not useful because the weakPtr is registered in Destroyable, so a copy-constructor must be used anyway

Modified: code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h	2015-11-01 20:03:05 UTC (rev 10744)
+++ code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h	2015-11-01 21:06:23 UTC (rev 10745)
@@ -171,6 +171,13 @@
                     this->base_->incrementReferenceCount();
             }
 
+            /// Move-constructor
+            inline StrongPtr(StrongPtr&& other) : pointer_(other.pointer_), base_(other.base_)
+            {
+                other.pointer_ = nullptr;
+                other.base_ = nullptr;
+            }
+
             /// Destructor: Decrements the reference counter.
             inline ~StrongPtr()
             {
@@ -186,9 +193,9 @@
             }
 
             /// Assigns the wrapped pointer of another StrongPtr.
-            inline StrongPtr& operator=(const StrongPtr& other)
+            inline StrongPtr& operator=(StrongPtr other)
             {
-                StrongPtr(other).swap(*this);
+                other.swap(*this);
                 return *this;
             }
 

Modified: code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h	2015-11-01 20:03:05 UTC (rev 10744)
+++ code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h	2015-11-01 21:06:23 UTC (rev 10745)
@@ -136,9 +136,9 @@
             }
 
             /// Assigns the wrapped pointer of another WeakPtr.
-            inline WeakPtr& operator=(const WeakPtr& other)
+            inline WeakPtr& operator=(WeakPtr other)
             {
-                WeakPtr(other).swap(*this);
+                other.swap(*this);
                 return *this;
             }
 

Modified: code/branches/cpp11_v2/src/libraries/util/SharedPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/SharedPtr.h	2015-11-01 20:03:05 UTC (rev 10744)
+++ code/branches/cpp11_v2/src/libraries/util/SharedPtr.h	2015-11-01 21:06:23 UTC (rev 10745)
@@ -244,6 +244,13 @@
                     ++this->counter_->count_;
             }
 
+            /// Move-constructor, this SharedPtr now points to the same object like the other SharedPtr did before
+            inline SharedPtr(SharedPtr&& other) : pointer_(other.pointer_), counter_(other.counter_)
+            {
+                other.pointer_ = nullptr;
+                other.counter_ = nullptr;
+            }
+
             /// Destructor, decrements the counter and deletes the object if the counter becomes zero.
             inline ~SharedPtr()
             {
@@ -260,9 +267,9 @@
             }
 
             /// Assigns a new object, decrements the counter of the old object, increments the counter of the new object.
-            inline SharedPtr& operator=(const SharedPtr& other)
+            inline SharedPtr& operator=(SharedPtr other)
             {
-                SharedPtr(other).swap(*this);
+                other.swap(*this);
                 return *this;
             }
 




More information about the Orxonox-commit mailing list