Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-11-14 |
2 | // Created by: Peter KURNEV | |
3 | // Copyright (c) 2000-2012 OPEN CASCADE SAS | |
4 | // | |
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. | |
9 | // | |
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. | |
12 | // | |
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. | |
19 | ||
7fd59977 | 20 | |
21 | //======================================================================= | |
22 | //function : BOPTools_CArray1::BOPTools_CArray1 | |
23 | //purpose : | |
24 | //======================================================================= | |
251450e5 P |
25 | BOPTColStd_CArray1::BOPTColStd_CArray1 (const Standard_Integer aLength, |
26 | const Standard_Integer aBlockLength) | |
7fd59977 | 27 | : |
28 | myStart(NULL), | |
29 | myLength(0), | |
30 | myFactLength(0), | |
31 | myBlockLength(aBlockLength), | |
32 | myIsAllocated(Standard_False) | |
33 | { | |
34 | Resize(aLength); | |
35 | } | |
36 | //======================================================================= | |
37 | //function : Resize | |
38 | //purpose : | |
39 | //======================================================================= | |
251450e5 | 40 | void BOPTColStd_CArray1::Resize(const Standard_Integer aNL) |
7fd59977 | 41 | { |
42 | Array1Item* p = NULL; | |
43 | if (aNL>0) { | |
44 | Destroy(); | |
45 | ||
46 | p=new Array1Item[aNL]; | |
47 | ||
48 | if (!p) { | |
49 | Standard_OutOfMemory::Raise | |
251450e5 | 50 | ("BOPTools_CArray1 : Allocation failed."); |
7fd59977 | 51 | } |
52 | ||
53 | else { | |
54 | myIsAllocated=Standard_True; | |
55 | myLength=aNL; | |
56 | myFactLength=myLength; | |
57 | myStart = (void*) p; | |
58 | } | |
59 | } | |
60 | } | |
61 | //======================================================================= | |
62 | //function : Remove | |
63 | //purpose : | |
64 | //======================================================================= | |
251450e5 | 65 | void BOPTColStd_CArray1::Remove(const Standard_Integer anInd) |
7fd59977 | 66 | { |
251450e5 P |
67 | if (!myIsAllocated) { |
68 | return; | |
69 | } | |
7fd59977 | 70 | |
251450e5 P |
71 | if (IsInvalidIndex(anInd)) { |
72 | Standard_OutOfMemory::Raise | |
73 | ("BOPTools_CArray1 : Attempt to remove inexisting Item."); | |
74 | } | |
7fd59977 | 75 | |
251450e5 P |
76 | const Standard_Integer aNFL=myFactLength-1; |
77 | Array1Item *p=NULL; | |
78 | p = new Array1Item[aNFL]; | |
79 | ||
80 | if (!p) { | |
81 | Standard_OutOfMemory::Raise | |
82 | ("BOPTools_CArray1::Append: Allocation failed."); | |
7fd59977 | 83 | } |
251450e5 P |
84 | |
85 | Standard_Integer i, j, anIndx, iLength; | |
86 | ||
87 | iLength=myLength; | |
88 | ||
89 | anIndx=anInd-1; | |
90 | for (i=0, j=0; i<myLength; ++i) { | |
91 | if (i!=anIndx) { | |
92 | p[j]= ((Array1Item *)myStart)[i]; | |
93 | j++; | |
7fd59977 | 94 | } |
7fd59977 | 95 | } |
251450e5 P |
96 | |
97 | Destroy(); | |
98 | ||
99 | myFactLength=aNFL; | |
100 | myLength=iLength-1; | |
101 | myIsAllocated=Standard_True; | |
102 | myStart = (void*) p; | |
7fd59977 | 103 | } |
104 | //======================================================================= | |
105 | //function : Append | |
106 | //purpose : | |
107 | //======================================================================= | |
108 | Standard_Integer BOPTColStd_CArray1::Append(const Array1Item& aV) | |
109 | { | |
110 | Standard_Integer i, aNL; | |
111 | ||
112 | aNL=myLength+1; | |
113 | if (aNL > myFactLength) { | |
114 | ||
115 | const Standard_Integer iLengthToAllocate=myLength+myBlockLength; | |
116 | ||
117 | Array1Item *p=NULL; | |
118 | p = new Array1Item[iLengthToAllocate]; | |
119 | ||
120 | if (!p) { | |
121 | Standard_OutOfMemory::Raise | |
122 | ("IntBOPTools_CArray1::Append: Allocation failed."); | |
123 | } | |
124 | ||
125 | for (i=0; i<myLength; i++) { | |
126 | p[i]=((Array1Item *)myStart)[i]; | |
127 | } | |
128 | p[myLength]=aV; | |
129 | ||
130 | Destroy(); | |
131 | ||
251450e5 | 132 | |
7fd59977 | 133 | myFactLength=iLengthToAllocate; |
134 | myIsAllocated=Standard_True; | |
135 | myStart = (void*) p; | |
136 | } | |
137 | ||
138 | else { | |
139 | ((Array1Item *)myStart)[myLength]=aV; | |
140 | } | |
141 | ||
142 | myLength=aNL; | |
143 | return myLength; | |
144 | } | |
145 | //======================================================================= | |
146 | //function : IsInvalidIndex | |
147 | //purpose : | |
148 | //======================================================================= | |
251450e5 P |
149 | Standard_Boolean BOPTColStd_CArray1::IsInvalidIndex |
150 | (const Standard_Integer anInd)const | |
7fd59977 | 151 | { |
152 | Standard_Boolean aFlag; | |
153 | Standard_Integer anIndx=anInd-1; | |
154 | aFlag=!(anIndx > -1 && anIndx < myLength); | |
155 | return aFlag; | |
156 | } | |
157 | //======================================================================= | |
158 | //function : Destroy | |
159 | //purpose : | |
160 | //======================================================================= | |
251450e5 | 161 | void BOPTColStd_CArray1::Destroy() |
7fd59977 | 162 | { |
163 | if (myIsAllocated) { | |
164 | delete [] (Array1Item *)myStart; | |
165 | myIsAllocated=Standard_False; | |
166 | myFactLength=0; | |
167 | myLength=0; | |
168 | myStart=NULL; | |
169 | } | |
7fd59977 | 170 | } |
251450e5 | 171 | |
7fd59977 | 172 | //======================================================================= |
173 | //function : Length | |
174 | //purpose : | |
175 | //======================================================================= | |
251450e5 | 176 | Standard_Integer BOPTColStd_CArray1::Length() const |
7fd59977 | 177 | { |
178 | return myLength; | |
179 | } | |
180 | //======================================================================= | |
181 | //function : Extent | |
182 | //purpose : | |
183 | //======================================================================= | |
251450e5 | 184 | Standard_Integer BOPTColStd_CArray1::Extent() const |
7fd59977 | 185 | { |
186 | return myLength; | |
187 | } | |
188 | //======================================================================= | |
189 | //function : FactLength | |
190 | //purpose : | |
191 | //======================================================================= | |
251450e5 | 192 | Standard_Integer BOPTColStd_CArray1::FactLength() const |
7fd59977 | 193 | { |
194 | return myFactLength; | |
195 | } | |
196 | //======================================================================= | |
197 | //function : BlockLength | |
198 | //purpose : | |
199 | //======================================================================= | |
200 | Standard_Integer BOPTColStd_CArray1::BlockLength() const | |
201 | { | |
202 | return myBlockLength; | |
203 | } | |
204 | //======================================================================= | |
205 | //function : SetBlockLength | |
206 | //purpose : | |
207 | //======================================================================= | |
251450e5 | 208 | void BOPTColStd_CArray1::SetBlockLength(const Standard_Integer aBL) |
7fd59977 | 209 | { |
251450e5 | 210 | if (aBL > 0) { |
7fd59977 | 211 | myBlockLength=aBL; |
251450e5 | 212 | } |
7fd59977 | 213 | } |
214 | //======================================================================= | |
215 | //function : Value | |
216 | //purpose : | |
217 | //======================================================================= | |
251450e5 | 218 | const Array1Item& BOPTColStd_CArray1::Value |
7fd59977 | 219 | (const Standard_Integer Index) const |
220 | { | |
221 | if (IsInvalidIndex(Index)) { | |
222 | Standard_OutOfRange::Raise("BOPTools_CArray1::Value"); | |
223 | } | |
224 | return ((Array1Item *)myStart)[Index-1]; | |
225 | } | |
226 | //======================================================================= | |
227 | //function : ChangeValue | |
228 | //purpose : | |
229 | //======================================================================= | |
251450e5 | 230 | Array1Item& BOPTColStd_CArray1::ChangeValue |
7fd59977 | 231 | (const Standard_Integer Index) |
232 | { | |
233 | if (IsInvalidIndex(Index)) { | |
234 | Standard_OutOfRange::Raise("BOPTools_CArray1::ChangeValue"); | |
235 | } | |
236 | return ((Array1Item *)myStart)[Index-1]; | |
237 | } | |
251450e5 P |
238 | //modified by NIZNHY-PKV Wed Nov 09 10:03:01 2011f |
239 | //======================================================================= | |
240 | //function : Purge | |
241 | //purpose : | |
242 | //======================================================================= | |
243 | void BOPTColStd_CArray1::Purge() | |
244 | { | |
245 | if (!myIsAllocated) { | |
246 | return; | |
247 | } | |
248 | // | |
249 | if (myLength>0 && myLength<myFactLength) { | |
250 | Standard_Integer i, aLength; | |
251 | Array1Item *p = NULL; | |
252 | // | |
253 | p=new Array1Item[myLength]; | |
254 | if (!p) { | |
255 | Standard_OutOfMemory::Raise | |
256 | ("BOPTools_CArray1 : Allocation failed."); | |
257 | } | |
258 | // | |
259 | for (i=0; i<myLength; i++) { | |
260 | p[i]=((Array1Item *)myStart)[i]; | |
261 | } | |
262 | // | |
263 | aLength=myLength; | |
264 | // | |
265 | Destroy(); | |
266 | // | |
267 | myIsAllocated=Standard_True; | |
268 | myLength=aLength; | |
269 | myFactLength=myLength; | |
270 | myStart = (void*) p; | |
271 | } | |
272 | } | |
273 | //modified by NIZNHY-PKV Wed Nov 09 10:03:07 2011t | |
274 | /* | |
275 | //======================================================================= | |
276 | //function : Dump | |
277 | //purpose : | |
278 | //======================================================================= | |
279 | void BOPTColStd_CArray1::Dump() const | |
280 | { | |
281 | printf("\n-- BOPTColStd_CArray1::Dump --\n"); | |
282 | printf("myIsAllocated =%d\n", myIsAllocated); | |
283 | printf("myLength =%d\n", myLength); | |
284 | printf("myFactLength =%d\n", myFactLength); | |
285 | printf("myBlockLength =%d\n", myBlockLength); | |
286 | } | |
287 | */ |