1 // Created on: 2000-05-26
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 //=======================================================================
22 //function : IntTools_CArray1
24 //=======================================================================
25 IntTools_CArray1::IntTools_CArray1 (const Standard_Integer Length):
28 myIsAllocated(Standard_False)
33 //=======================================================================
34 //function : IntTools_CArray1
36 //=======================================================================
37 IntTools_CArray1::IntTools_CArray1 (const Array1Item& Item,
38 const Standard_Integer Length):
40 myIsAllocated(Standard_False)
42 Standard_ConstructionError_Raise_if(Length < 0,"IntTools_CArray1:: Length < 0");
43 myStart = (void*)(&Item);
46 //=======================================================================
49 //=======================================================================
50 void IntTools_CArray1::Init (const Array1Item& V)
52 Array1Item* p = (Array1Item*) myStart;
53 for(Standard_Integer i = 0; i < Length() ; i++) {
58 //=======================================================================
61 //=======================================================================
62 void IntTools_CArray1::Destroy()
65 delete [] (Array1Item *)myStart;
66 myIsAllocated = Standard_False;
71 //=======================================================================
74 //=======================================================================
75 Standard_Boolean IntTools_CArray1::IsEqual(const IntTools_CArray1& Other) const
79 else if (Length() != Other.Length())
80 return Standard_False;
81 else if (Length() == 0)
84 return Standard_False;
88 //=======================================================================
91 //=======================================================================
92 void IntTools_CArray1::Resize(const Standard_Integer theNewLength)
94 Standard_ConstructionError_Raise_if(theNewLength < 0,"IntTools_CArray1: length < 0");
100 myLength = theNewLength;
102 if (theNewLength > 0) {
103 // default creator called for each item of the array
104 p = new Array1Item[theNewLength];
105 if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
106 myIsAllocated = Standard_True;
112 //=======================================================================
115 //=======================================================================
116 void IntTools_CArray1::Append (const Array1Item& Value)
118 const Standard_Integer theNewLength=myLength+1;
120 Array1Item* p = NULL;
122 if (theNewLength > 0) {
123 // default creator called for each item of the array
124 p = new Array1Item[theNewLength];
125 if (!p) Standard_OutOfMemory::Raise("IntTools_CArray1 : Allocation failed.");
128 Standard_Integer aBytesPerItem=sizeof(Array1Item);
129 memcpy (p, myStart, myLength*aBytesPerItem);
134 myLength = theNewLength;
135 myIsAllocated = Standard_True;
140 //=======================================================================
143 //=======================================================================
144 const Array1Item& IntTools_CArray1::Value(const Standard_Integer Index) const
146 if (myLength <1 || Index < 0 || Index >= myLength)
147 Standard_OutOfRange::Raise("IntTools_CArray1::Value");
149 return ((Array1Item *)myStart)[Index];
152 //=======================================================================
153 //function : SetValue
155 //=======================================================================
156 void IntTools_CArray1::SetValue (const Standard_Integer Index,
157 const Array1Item& Value)
159 ChangeValue(Index) = Value;
163 //=======================================================================
164 //function : ChangeValue
166 //=======================================================================
167 Array1Item& IntTools_CArray1::ChangeValue(const Standard_Integer Index)
169 if (myLength < 1 || Index < 0 || Index >= myLength)
170 Standard_OutOfRange::Raise("IntTools_CArray1::ChangeValue");
172 return ((Array1Item *)myStart)[Index];