0024971: Incomplete interface of NCollection classes

NCollection classes amended to be compatible with TCollection equivalents:

- List and Maps: copy constructor is used for placement of new items in collection instead of assignment operator, thus default constructor is not necessary any more for the item class
- Constructors with additional argument of element type added in array classes operated by Handle, defined by NCollection_DefineHArray*.hxx, allowing to initialize array immediately by specified value
- Non-const methods First() and Last() are added in List class, and method Value() in TListIterator class
- Method Append() accepting Handle(HSequence) provided in NCollection_DefineHSequence.hxx
- Default implementation of global function IsEqual() is provided as template (using operator ==)

Code using lists and maps of sequences is refactored to operate sequence by Handle (since Sequence does not to have public copy constructor).

In addition, error checking code is simplified to use macros _Raise_if instead of custom #ifdefs with the same meaning.
Comments within declaration of instances of generic classes in CDL removed.

Fixed bug in copy constructor of NCollection_BaseVector leading to corrupt data if original vector is empty; simplistic test command for vectors is added.
This commit is contained in:
abv
2014-06-11 10:43:27 +04:00
committed by apn
parent 655fddc854
commit e3a6386d18
31 changed files with 322 additions and 494 deletions

View File

@@ -16,11 +16,9 @@
#ifndef NCollection_Array2_HeaderFile
#define NCollection_Array2_HeaderFile
#ifndef No_Exception
#include <Standard_DimensionMismatch.hxx>
#include <Standard_OutOfMemory.hxx>
#include <Standard_OutOfRange.hxx>
#endif
#include <NCollection_DefineAlloc.hxx>
@@ -171,10 +169,7 @@ public:
{
if (&theOther == this)
return *this;
#if !defined No_Exception && !defined No_Standard_DimensionMismatch
if (Length() != theOther.Length())
Standard_DimensionMismatch::Raise ("NCollection_Array2::operator=");
#endif
Standard_DimensionMismatch_Raise_if (Length() != theOther.Length(), "NCollection_Array2::operator=");
TheItemType * pMyItem = myStart;
TheItemType * pItem = theOther.myStart;
const Standard_Integer iSize = Length();
@@ -193,11 +188,8 @@ public:
const TheItemType& Value (const Standard_Integer theRow,
const Standard_Integer theCol) const
{
#if !defined No_Exception && !defined No_Standard_OutOfRange
if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol)
Standard_OutOfRange::Raise ("NCollection_Array2::Value");
#endif
Standard_OutOfRange_Raise_if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol, "NCollection_Array2::Value");
return myData[theRow][theCol];
}
@@ -210,11 +202,8 @@ public:
TheItemType& ChangeValue (const Standard_Integer theRow,
const Standard_Integer theCol)
{
#if !defined No_Exception && !defined No_Standard_OutOfRange
if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol)
Standard_OutOfRange::Raise ("NCollection_Array2::ChangeValue");
#endif
Standard_OutOfRange_Raise_if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol, "NCollection_Array2::ChangeValue");
return myData[theRow][theCol];
}
@@ -228,11 +217,8 @@ public:
const Standard_Integer theCol,
const TheItemType& theItem)
{
#if !defined No_Exception && !defined No_Standard_OutOfRange
if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol)
Standard_OutOfRange::Raise ("NCollection_Array2::SetValue");
#endif
Standard_OutOfRange_Raise_if (theRow < myLowerRow || theRow > myUpperRow ||
theCol < myLowerCol || theCol > myUpperCol, "NCollection_Array2::SetValue");
myData[theRow][theCol] = theItem;
}
@@ -251,24 +237,15 @@ public:
{
const Standard_Integer iRowSize = myUpperCol - myLowerCol + 1;
const Standard_Integer iColSize = myUpperRow - myLowerRow + 1;
#if !defined No_Exception && !defined No_Standard_RangeError
if (iRowSize <= 0 || iColSize <= 0)
Standard_RangeError::Raise ("NCollection_Array2::Allocate");
#endif
Standard_RangeError_Raise_if (iRowSize <= 0 || iColSize <= 0, "NCollection_Array2::Allocate");
if (myDeletable) {
// allocation of the data in the array
myStart = new TheItemType[iRowSize * iColSize];
#if !defined No_Exception && !defined No_Standard_OutOfMemory
if (!myStart)
Standard_OutOfMemory::Raise ("NCollection_Array2 : Allocation failed");
#endif
Standard_OutOfMemory_Raise_if (!myStart, "NCollection_Array2 : Allocation failed");
}
// else myStart is set to the beginning of the given array
TheItemType** pTable = new TheItemType* [iColSize];
#if !defined No_Exception && !defined No_Standard_OutOfMemory
if (!pTable)
Standard_OutOfMemory::Raise ("NCollection_Array2 : Allocation failed");
#endif
Standard_OutOfMemory_Raise_if (!pTable, "NCollection_Array2 : Allocation failed");
// Items of pTable point to the '0'th items in the rows of the array
TheItemType* pRow = myStart - myLowerCol;