1 // Created on: 2000-05-26
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //=======================================================================
17 //function : IntTools_CArray1
19 //=======================================================================
20 IntTools_CArray1::IntTools_CArray1 (const Standard_Integer Length):
23 myIsAllocated(Standard_False)
28 //=======================================================================
29 //function : IntTools_CArray1
31 //=======================================================================
32 IntTools_CArray1::IntTools_CArray1 (const Array1Item& Item,
33 const Standard_Integer Length):
35 myIsAllocated(Standard_False)
37 Standard_ConstructionError_Raise_if(Length < 0,"IntTools_CArray1:: Length < 0");
38 myStart = (void*)(&Item);
41 //=======================================================================
44 //=======================================================================
45 void IntTools_CArray1::Init (const Array1Item& V)
47 Array1Item* p = (Array1Item*) myStart;
48 for(Standard_Integer i = 0; i < Length() ; i++) {
53 //=======================================================================
56 //=======================================================================
57 void IntTools_CArray1::Destroy()
60 delete [] (Array1Item *)myStart;
61 myIsAllocated = Standard_False;
66 //=======================================================================
69 //=======================================================================
70 Standard_Boolean IntTools_CArray1::IsEqual(const IntTools_CArray1& Other) const
74 else if (Length() != Other.Length())
75 return Standard_False;
76 else if (Length() == 0)
79 return Standard_False;
83 //=======================================================================
86 //=======================================================================
87 void IntTools_CArray1::Resize(const Standard_Integer theNewLength)
89 Standard_ConstructionError_Raise_if(theNewLength < 0,"IntTools_CArray1: length < 0");
95 myLength = theNewLength;
97 if (theNewLength > 0) {
98 // default creator called for each item of the array
99 p = new Array1Item[theNewLength];
100 if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
101 myIsAllocated = Standard_True;
107 //=======================================================================
110 //=======================================================================
111 void IntTools_CArray1::Append (const Array1Item& Value)
113 const Standard_Integer theNewLength=myLength+1;
115 Array1Item* p = NULL;
117 if (theNewLength > 0) {
118 // default creator called for each item of the array
119 p = new Array1Item[theNewLength];
120 if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
123 Standard_Integer aBytesPerItem=sizeof(Array1Item);
124 memcpy (p, myStart, myLength*aBytesPerItem);
129 myLength = theNewLength;
130 myIsAllocated = Standard_True;
135 //=======================================================================
138 //=======================================================================
139 const Array1Item& IntTools_CArray1::Value(const Standard_Integer Index) const
141 if (myLength <1 || Index < 0 || Index >= myLength)
142 Standard_OutOfRange::Raise("IntTools_CArray1::Value");
144 return ((Array1Item *)myStart)[Index];
147 //=======================================================================
148 //function : SetValue
150 //=======================================================================
151 void IntTools_CArray1::SetValue (const Standard_Integer Index,
152 const Array1Item& Value)
154 ChangeValue(Index) = Value;
158 //=======================================================================
159 //function : ChangeValue
161 //=======================================================================
162 Array1Item& IntTools_CArray1::ChangeValue(const Standard_Integer Index)
164 if (myLength < 1 || Index < 0 || Index >= myLength)
165 Standard_OutOfRange::Raise("IntTools_CArray1::ChangeValue");
167 return ((Array1Item *)myStart)[Index];