// File: IntTools_CArray1.gxx // Created: Fri May 26 11:00:00 2000 // Author: Peter KURNEV // //======================================================================= //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]; }