1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// File: IntTools_CArray1.gxx
// Created: Fri May 26 11:00:00 2000
// Author: Peter KURNEV
// <pkv@irinox>
//=======================================================================
//function : IntTools_CArray1
//purpose :
//=======================================================================
IntTools_CArray1::IntTools_CArray1 (const Standard_Integer Length):
myStart(NULL),
myLength(0),
myIsAllocated(Standard_False)
{
Resize(Length);
}
//=======================================================================
//function : IntTools_CArray1
//purpose :
//=======================================================================
IntTools_CArray1::IntTools_CArray1 (const Array1Item& Item,
const Standard_Integer Length):
myLength(Length),
myIsAllocated(Standard_False)
{
Standard_ConstructionError_Raise_if(Length < 0,"IntTools_CArray1:: Length < 0");
myStart = (void*)(&Item);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void IntTools_CArray1::Init (const Array1Item& V)
{
Array1Item* p = (Array1Item*) myStart;
for(Standard_Integer i = 0; i < Length() ; i++) {
*p++ = V;
}
}
//=======================================================================
//function : Destroy
//purpose :
//=======================================================================
void IntTools_CArray1::Destroy()
{
if (myIsAllocated) {
delete [] (Array1Item *)myStart;
myIsAllocated = Standard_False;
}
myStart = NULL;
}
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
Standard_Boolean IntTools_CArray1::IsEqual(const IntTools_CArray1& Other) const
{
if (&Other == this)
return Standard_True;
else if (Length() != Other.Length())
return Standard_False;
else if (Length() == 0)
return Standard_True;
//
return Standard_False;
}
//=======================================================================
//function : Resize
//purpose :
//=======================================================================
void IntTools_CArray1::Resize(const Standard_Integer theNewLength)
{
Standard_ConstructionError_Raise_if(theNewLength < 0,"IntTools_CArray1: length < 0");
Array1Item* p = NULL;
Destroy();
myLength = theNewLength;
if (theNewLength > 0) {
// default creator called for each item of the array
p = new Array1Item[theNewLength];
if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
myIsAllocated = Standard_True;
}
myStart = (void*) p;
}
//=======================================================================
//function : Append
//purpose :
//=======================================================================
void IntTools_CArray1::Append (const Array1Item& Value)
{
const Standard_Integer theNewLength=myLength+1;
Array1Item* p = NULL;
if (theNewLength > 0) {
// default creator called for each item of the array
p = new Array1Item[theNewLength];
if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
if (myLength!=0) {
Standard_Integer aBytesPerItem=sizeof(Array1Item);
memcpy (p, myStart, myLength*aBytesPerItem);
}
*(p+myLength)=Value;
Destroy();
myLength = theNewLength;
myIsAllocated = Standard_True;
}
myStart = (void*) p;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
const Array1Item& IntTools_CArray1::Value(const Standard_Integer Index) const
{
if (myLength <1 || Index < 0 || Index >= myLength)
Standard_OutOfRange::Raise("IntTools_CArray1::Value");
return ((Array1Item *)myStart)[Index];
}
//=======================================================================
//function : SetValue
//purpose :
//=======================================================================
void IntTools_CArray1::SetValue (const Standard_Integer Index,
const Array1Item& Value)
{
ChangeValue(Index) = Value;
}
//=======================================================================
//function : ChangeValue
//purpose :
//=======================================================================
Array1Item& IntTools_CArray1::ChangeValue(const Standard_Integer Index)
{
if (myLength < 1 || Index < 0 || Index >= myLength)
Standard_OutOfRange::Raise("IntTools_CArray1::ChangeValue");
return ((Array1Item *)myStart)[Index];
}
|