1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029258: Foundation Classes - provide move constructors for string classes

New macro OCCT_NO_RVALUE_REFERENCE is introduced to disable methods using move semantics on obsolete compilers that do not support rvalue references.

TCollection_AsciiString, TCollection_ExtendedString, NCollection_UtfString - added method Swap(), move constructor, and move assignment operator.

Draw command QATestArrayMove is added to test for memory corruption if NCollection_Array1<> bound to local C buffer is returned from function by value.
This commit is contained in:
kgv
2017-10-15 16:08:01 +03:00
committed by bugmaster
parent 4ecf34cce7
commit 6286195cff
9 changed files with 209 additions and 22 deletions

View File

@@ -90,6 +90,23 @@ NCollection_UtfString<Type>::NCollection_UtfString (const NCollection_UtfString&
strCopy ((Standard_Byte* )myString, (const Standard_Byte* )theCopy.myString, mySize);
}
#ifndef OCCT_NO_RVALUE_REFERENCE
// =======================================================================
// function : NCollection_UtfString
// purpose :
// =======================================================================
template<typename Type> inline
NCollection_UtfString<Type>::NCollection_UtfString (NCollection_UtfString&& theOther)
: myString(theOther.myString),
mySize (theOther.mySize),
myLength(theOther.myLength)
{
theOther.myString = NULL;
theOther.mySize = 0;
theOther.myLength = 0;
}
#endif
// =======================================================================
// function : NCollection_UtfString
// purpose :
@@ -159,11 +176,11 @@ NCollection_UtfString<Type>::~NCollection_UtfString()
}
// =======================================================================
// function : operator=
// function : Assign
// purpose :
// =======================================================================
template<typename Type> inline
const NCollection_UtfString<Type>& NCollection_UtfString<Type>::operator= (const NCollection_UtfString<Type>& theOther)
const NCollection_UtfString<Type>& NCollection_UtfString<Type>::Assign (const NCollection_UtfString<Type>& theOther)
{
if (this == &theOther)
{
@@ -178,6 +195,26 @@ const NCollection_UtfString<Type>& NCollection_UtfString<Type>::operator= (const
return (*this);
}
// =======================================================================
// function : Swap
// purpose :
// =======================================================================
template<typename Type> inline
void NCollection_UtfString<Type>::Swap (NCollection_UtfString<Type>& theOther)
{
// Note: we could use std::swap() here, but prefer to not
// have dependency on <algorithm> header at that level
Type* aString = myString;
const Standard_Integer aSize = mySize;
const Standard_Integer aLength = myLength;
myString = theOther.myString;
mySize = theOther.mySize;
myLength = theOther.myLength;
theOther.myString = aString;
theOther.mySize = aSize;
theOther.myLength = aLength;
}
#if !defined(__ANDROID__)
//! Auxiliary convertion tool.
class NCollection_UtfStringTool