]> OCCT Git - occt-copy.git/commitdiff
math_Vector, math_IntegerVector - added move constructors. CR30552_1
authorkgv <kgv@opencascade.com>
Tue, 12 Mar 2019 08:14:15 +0000 (11:14 +0300)
committerkgv <kgv@opencascade.com>
Tue, 12 Mar 2019 10:50:22 +0000 (13:50 +0300)
src/NCollection/NCollection_LocalArray.hxx
src/math/math_IntegerVector.hxx
src/math/math_Vector.hxx

index 06050493f729888137f4e3570e850a9c3b7a20b6..cadfe2817a0d079bde7a38da6e065e367d224ef1 100644 (file)
@@ -59,6 +59,32 @@ public:
     return myPtr;
   }
 
+  //! Move assignment.
+  //! This array will borrow all the data from theOther.
+  NCollection_LocalArray& Move (NCollection_LocalArray& theOther)
+  {
+    if (&theOther == this)
+    {
+      return *this;
+    }
+
+    Deallocate();
+    mySize = theOther.mySize;
+    if (theOther.myPtr == theOther.myBuffer)
+    {
+      // deep copy
+      myPtr = myBuffer;
+      memcpy (myPtr, theOther.myPtr, sizeof(theItem) * theOther.mySize);
+      memset (theOther.myPtr,     0, sizeof(theItem) * theOther.mySize);
+    }
+    else
+    {
+      myPtr = theOther.myPtr;
+      theOther.myPtr = theOther.myBuffer;
+    }
+    return *this;
+  }
+
 private:
 
   NCollection_LocalArray (const NCollection_LocalArray& );
index 5241fc18200ebfe92daf9f0cbf2eddb6f7764811..40e1e0e370ee4a7c4a77231194e34ce80244bc01 100644 (file)
@@ -256,6 +256,37 @@ public:
     return theO;
   }
 
+#ifndef OCCT_NO_RVALUE_REFERENCE
+  //! Move constructor
+  math_IntegerVector (math_IntegerVector&& theOther)
+  {
+    Move (theOther);
+  }
+
+  //! Move assignment operator; @sa Move()
+  math_IntegerVector& operator= (math_IntegerVector&& theOther)
+  {
+    return Move (theOther);
+  }
+#endif
+
+  //! Move assignment.
+  //! This array will borrow all the data from theOther, so that theOther should not be used anymore.
+  math_IntegerVector& Move (math_IntegerVector& theOther)
+  {
+    if (&theOther == this)
+    {
+      return *this;
+    }
+
+    myLocArray.Move (theOther.myLocArray);
+    NCollection_Array1<Standard_Integer> aNewArray (myLocArray[0], theOther.Array.Lower(), theOther.Array.Upper());
+    Array.Move (aNewArray);
+    NCollection_Array1<Standard_Integer> anEmptyArray;
+    theOther.Array.Move (anEmptyArray);
+    return *this;
+  }
+
 protected:
 
   //! is used internally to set the Lower value of the IntegerVector.
index 308d889880df3552ab6063f3ab6694a984aa8ab1..91c666ed6b557a4e6de7e21768075a5ac2f3bf8d 100644 (file)
@@ -331,6 +331,37 @@ public:
 
   friend class math_Matrix;
 
+#ifndef OCCT_NO_RVALUE_REFERENCE
+  //! Move constructor
+  math_Vector (math_Vector&& theOther)
+  {
+    Move (theOther);
+  }
+
+  //! Move assignment operator; @sa Move()
+  math_Vector& operator= (math_Vector&& theOther)
+  {
+    return Move (theOther);
+  }
+#endif
+
+  //! Move assignment.
+  //! This array will borrow all the data from theOther, so that theOther should not be used anymore.
+  math_Vector& Move (math_Vector& theOther)
+  {
+    if (&theOther == this)
+    {
+      return *this;
+    }
+
+    myLocArray.Move (theOther.myLocArray);
+    NCollection_Array1<Standard_Real> aNewArray (myLocArray[0], theOther.Array.Lower(), theOther.Array.Upper());
+    Array.Move (aNewArray);
+    NCollection_Array1<Standard_Real> anEmptyArray;
+    theOther.Array.Move (anEmptyArray);
+    return *this;
+  }
+
 protected:
 
   //! Is used internally to set the "theLower" value of the vector.