mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-05-11 10:10:56 +08:00
175 lines
5.5 KiB
Plaintext
Executable File
175 lines
5.5 KiB
Plaintext
Executable File
// Created on: 2000-05-26
|
|
// Created by: Peter KURNEV
|
|
// Copyright (c) 2000-2012 OPEN CASCADE SAS
|
|
//
|
|
// The content of this file is subject to the Open CASCADE Technology Public
|
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
|
// except in compliance with the License. Please obtain a copy of the License
|
|
// at http://www.opencascade.org and read it completely before using this file.
|
|
//
|
|
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
|
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
|
//
|
|
// The Original Code and all software distributed under the License is
|
|
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
|
// Initial Developer hereby disclaims all such warranties, including without
|
|
// limitation, any warranties of merchantability, fitness for a particular
|
|
// purpose or non-infringement. Please see the License for the specific terms
|
|
// and conditions governing the rights and limitations under the License.
|
|
|
|
|
|
//=======================================================================
|
|
//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];
|
|
}
|
|
|