b311480e |
1 | -- Created on: 1992-09-11 |
2 | -- Created by: Mireille MERCIEN |
3 | -- Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | -- Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | -- |
973c2be1 |
6 | -- This file is part of Open CASCADE Technology software library. |
b311480e |
7 | -- |
d5f74e42 |
8 | -- This library is free software; you can redistribute it and/or modify it under |
9 | -- the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | -- by the Free Software Foundation, with special exception defined in the file |
11 | -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | -- distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | -- |
973c2be1 |
14 | -- Alternatively, this file may be used under the terms of Open CASCADE |
15 | -- commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | generic class HSequence from PCollection (Item as Storable) inherits Persistent |
18 | |
19 | ---Purpose: Definition of a sequence of elements indexed by |
20 | -- an Integer in range of 1..n |
21 | |
22 | raises |
23 | NoSuchObject from Standard, |
24 | OutOfRange from Standard |
25 | |
26 | |
27 | private class SeqNode inherits PManaged |
28 | is |
29 | |
30 | ---Purpose: This class provides tools to manipulate a Sequence node. |
31 | |
32 | Create( TheLast: SeqNode ; TheItem: Item) |
6e33d3ce |
33 | returns SeqNode from PCollection; |
7fd59977 |
34 | |
35 | Create( TheItem: Item ; TheFirst: SeqNode ) |
6e33d3ce |
36 | returns SeqNode from PCollection; |
7fd59977 |
37 | |
38 | Create( ThePrevious: SeqNode ; TheNext: SeqNode ; TheItem: Item ) |
6e33d3ce |
39 | returns SeqNode from PCollection; |
7fd59977 |
40 | |
41 | Value(me) returns any Item; |
42 | ---Level: Internal |
43 | ---Purpose: Returns MyItem. |
44 | |
6e33d3ce |
45 | Next(me) returns SeqNode; |
7fd59977 |
46 | ---Level: Internal |
47 | ---Purpose: Returns MyNext. |
48 | |
6e33d3ce |
49 | Previous(me) returns SeqNode; |
7fd59977 |
50 | ---Level: Internal |
51 | ---Purpose: Returns MyPrevious. |
52 | |
53 | SetValue( me:mutable; AnItem: Item); |
54 | ---Level: Internal |
55 | ---Purpose: Modifies the value of MyItem. |
56 | |
57 | SetNext( me:mutable; ANode: SeqNode); |
58 | ---Level: Internal |
59 | ---Purpose: Modifies the value of MyNext. |
60 | |
61 | SetPrevious( me:mutable; ANode: SeqNode); |
62 | ---Level: Internal |
63 | ---Purpose: Modifies the value of MyPrevious. |
64 | |
65 | fields |
66 | MyPrevious : SeqNode; |
67 | MyItem : Item; |
68 | MyNext : SeqNode; |
69 | |
70 | friends class HSequence from PCollection, |
71 | class SeqExplorer from PCollection |
72 | |
73 | end; |
74 | |
75 | class SeqExplorer |
76 | |
77 | ---Purpose: To explore a Sequence in an optimized way. |
78 | |
79 | raises NoSuchObject from Standard, |
80 | OutOfRange from Standard |
81 | |
82 | is |
83 | Create(S : HSequence from PCollection) |
84 | returns SeqExplorer from PCollection; |
85 | ---Purpose: Creates an explorer on the sequence S. |
86 | -- Sets the explorer at the BEGINNING(index 1) |
87 | -- of the sequence S. |
88 | |
89 | Value(me : in out ; Index : Integer) |
90 | returns any Item |
91 | raises OutOfRange from Standard; |
92 | ---Level: Public |
93 | ---Purpose: Value of the element indexed by Index in the |
94 | -- sequence <S>. |
95 | |
96 | Contains(me : in out ; T : Item) returns Boolean; |
97 | ---Level: Public |
98 | ---Purpose: Returns True if the sequence <S> contains the element T. |
99 | |
100 | Location(me : in out ; N : Integer; |
101 | T : Item; FromIndex : Integer; |
102 | ToIndex : Integer) |
103 | returns Integer |
104 | raises OutOfRange from Standard; |
105 | ---Level: Public |
106 | ---Purpose: Returns the index of the nth occurence of the element T |
107 | -- in the sequence <S>. The search starts from the index |
108 | -- FromIndex to the index ToIndex. |
109 | -- Returns 0 if the element is not present in the sub-sequence. |
110 | -- Raises an exception if the index is out of bounds. |
111 | |
112 | Location(me : in out ; N : Integer; T : Item) |
113 | returns Integer |
114 | raises OutOfRange from Standard; |
115 | ---Level: Public |
116 | ---Purpose: Returns the index of the nth occurence of the element T |
117 | -- in the sequence <S>. The search starts from the beginning |
118 | -- to the end of the sequence. |
119 | -- Returns 0 if the element is not present in the sub-sequence. |
120 | -- Raises an exception if the index is out of bounds. |
121 | |
122 | fields |
123 | CurrentItem : SeqNode; |
124 | CurrentIndex : Integer; |
125 | TheSequence : HSequence from PCollection; |
126 | end; |
127 | |
128 | |
129 | is |
130 | |
131 | |
6e33d3ce |
132 | Create returns HSequence; |
7fd59977 |
133 | ---Purpose: Creation of an empty sequence. |
134 | |
135 | |
136 | IsEmpty(me) returns Boolean; |
137 | ---Level: Public |
138 | ---Purpose: Returns True if the sequence <me> contains no elements. |
139 | |
140 | Length(me) returns Integer; |
141 | ---Level: Public |
142 | ---Purpose: Returns the number of element(s) in the sequence. |
143 | -- Returns zero if the sequence is empty. |
144 | |
145 | First(me) returns any Item |
146 | raises NoSuchObject from Standard; |
147 | ---Level: Public |
148 | ---Purpose: Returns the first element of the sequence <me>. |
149 | -- Raises an exception if the sequence is empty. |
150 | ---Example: before |
151 | -- me = (A B C) |
152 | -- after |
153 | -- me = (A B C) |
154 | -- returns A |
155 | |
156 | Last(me) returns any Item |
157 | raises NoSuchObject from Standard ; |
158 | ---Level: Public |
159 | ---Purpose: Returns the last element of the sequence <me>. |
160 | -- Raises an exception if the sequence is empty |
161 | ---Example: before |
162 | -- me = (A B C) |
163 | -- after |
164 | -- me = (A B C) |
165 | -- returns C |
166 | |
167 | Clear(me : mutable); |
168 | ---Level: Public |
169 | ---Purpose: Removes all element(s) of the sequence <me>. |
170 | -- before |
171 | -- me = (A B C) |
172 | -- after |
173 | -- me = () |
174 | |
175 | Append(me : mutable; T : Item); |
176 | ---Level: Public |
177 | ---Purpose: Pushes an element T at the end of the sequence <me>, thus |
178 | -- creating a new node. |
179 | ---Example: before |
180 | -- me = (A B C) |
181 | -- after |
182 | -- me = (A B C T) |
183 | |
184 | Append(me : mutable; S : HSequence from PCollection); |
185 | ---Level: Public |
186 | ---Purpose: Pushes a sequence S at the end of the sequence <me>. |
187 | -- There is a concatenation of the two sequences by copying S. |
188 | ---Example: before |
189 | -- me = (A B C) |
190 | -- S = (D E F) |
191 | -- after |
192 | -- me = (A B C D E F) |
193 | -- S = (D E F) |
194 | |
195 | Prepend(me : mutable; T : Item); |
196 | ---Level: Public |
197 | ---Purpose: Pushes an element T at the beginning of the sequence <me>, |
198 | -- thus creating a new node. |
199 | ---Example: before |
200 | -- me = (A B C) |
201 | -- after |
202 | -- me = (T A B C ) |
203 | |
204 | |
205 | Prepend(me : mutable; S : HSequence from PCollection); |
206 | ---Level: Public |
207 | ---Purpose: Pushes a sequence S at the begining of the sequence <me>. |
208 | -- There is a concatenation of two sequences with a copy of S. |
209 | ---Example: before |
210 | -- me = (A B C) |
211 | -- S = (D E F) |
212 | -- after |
213 | -- me = (D E F A B C) |
214 | -- S = (D E F) |
215 | |
216 | Reverse(me : mutable); |
217 | ---Level: Public |
218 | ---Purpose: Reverses the order of the sequence <me>. |
219 | ---Example: before |
220 | -- me = (A B C) |
221 | -- after |
222 | -- me = (C B A) |
223 | |
224 | InsertBefore(me : mutable; Index : Integer; T : Item) |
225 | raises OutOfRange from Standard; |
226 | ---Level: Public |
227 | ---Purpose: Pushes an element before a specific index in the |
228 | -- sequence <me>. |
229 | -- Raises an exception if the index is out of bounds. |
230 | ---Example: before |
231 | -- me = (A B D), Index = 3, T = C |
232 | -- after |
233 | -- me = (A B C D ) |
234 | |
235 | InsertBefore(me : mutable ; Index : Integer; |
236 | S : HSequence from PCollection) |
237 | raises OutOfRange from Standard; |
238 | ---Level: Public |
239 | ---Purpose: Pushes a sequence before a specific index in |
240 | -- the sequence <me> by copying S. |
241 | -- Raises an exception if the index is out of bounds. |
242 | ---Example: before |
243 | -- me = (A B F), Index = 3, S = (C D E) |
244 | -- after |
245 | -- me = (A B C D E F) |
246 | -- S = (C D E) |
247 | |
248 | InsertAfter(me : mutable; Index : Integer; T : Item) |
249 | raises OutOfRange from Standard; |
250 | ---Level: Public |
251 | ---Purpose: Pushes an element after a specific index in the |
252 | -- sequence <me>. |
253 | -- Raises an exception if the index is out of bounds. |
254 | ---Example: before |
255 | -- me = (A B C), Index = 3, T = D |
256 | -- after |
257 | -- me = (A B C D ) |
258 | |
259 | InsertAfter(me : mutable ; Index : Integer; |
260 | S : HSequence from PCollection) |
261 | raises OutOfRange from Standard; |
262 | ---Level: Public |
263 | ---Purpose: Pushes a sequence after a specific index in |
264 | -- the sequence <me> by copying S. |
265 | -- Raises an exception if the index is out of bounds. |
266 | ---Example: before |
267 | -- me = (A B C), Index = 3, S = (D E F) |
268 | -- after |
269 | -- me = (A B C D E F) |
270 | -- S = (D E F) |
271 | |
272 | Exchange(me : mutable; I, J : Integer) raises OutOfRange from Standard; |
273 | ---Level: Public |
274 | ---Purpose: Swaps elements which are located in positions I and J |
275 | -- in the sequence <me>. |
276 | -- Raises an exception if the index I or J is out of bounds. |
277 | ---Example: before |
278 | -- me = (A B C), I = 1, J = 3 |
279 | -- after |
280 | -- me = (C B A) |
281 | |
282 | SubSequence(me; FromIndex, ToIndex : Integer) |
6e33d3ce |
283 | returns HSequence |
7fd59977 |
284 | raises OutOfRange from Standard; |
285 | ---Level: Public |
286 | ---Purpose: Creation a sub-sequence with the elements from the |
287 | -- starting index I to the last index J |
288 | -- there is a partial copy of the sequence <me> |
289 | -- Raises an exception if the index is out of bounds or if |
290 | -- <ToIndex> is less than <FromIndex>. |
291 | ---Example: before |
292 | -- me = (A B C D E), I = 2, J = 4 |
293 | -- after |
294 | -- me = (A B C D E) |
295 | -- returns |
296 | -- (B C D) |
297 | |
298 | Split(me : mutable; Index : Integer) |
6e33d3ce |
299 | returns HSequence |
7fd59977 |
300 | raises OutOfRange from Standard; |
301 | ---Level: Public |
302 | ---Purpose: Split a sequence into two sub-sequences. |
303 | ---Example: before |
304 | -- me = (A B C D) ,Index = 3 |
305 | -- after |
306 | -- me = (A B) |
307 | -- returns |
308 | -- (C D) |
309 | |
310 | SetValue(me : mutable; Index : Integer; T : Item) |
311 | raises OutOfRange; |
312 | ---Level: Public |
313 | ---Purpose: Modification of the element indexed by Index in |
314 | -- the sequence <me>. |
315 | -- Raises an exception if the index is out of bounds. |
316 | ---Example: before |
317 | -- me = (A B D), Index = 3, T = C |
318 | -- after |
319 | -- me = (A B C) |
320 | |
321 | Value(me; Index : Integer) returns any Item |
322 | raises OutOfRange from Standard; |
323 | ---Level: Public |
324 | ---Purpose: Value of the element indexed by Index in the |
325 | -- sequence <me>. |
326 | -- Raises an exception if the index is out of bounds. |
327 | ---Example: before |
328 | -- me = (A B C), Index = 1 |
329 | -- after |
330 | -- me = (A B C) |
331 | -- returns |
332 | -- A |
333 | |
334 | Contains(me; T : Item) returns Boolean; |
335 | ---Level: Public |
336 | ---Purpose: Returns True if the sequence <me> contains the element T |
337 | |
338 | Location(me; N : Integer; |
339 | T : Item; FromIndex : Integer; |
340 | ToIndex : Integer) returns Integer |
341 | raises OutOfRange from Standard; |
342 | ---Level: Public |
343 | ---Purpose: Returns the index of the nth occurence of the element T |
344 | -- in the sequence <me>. The search starts from the index FromIndex to |
345 | -- the index ToIndex. |
346 | -- Returns 0 if the element is not present in the sub-sequence. |
347 | -- Raises an exception if the index is out of bounds or if |
348 | -- <ToIndex> is less than <FromIndex>. |
349 | ---Example: before |
350 | -- me = (A B C B D E B H), N = 2, T = B, FromIndex = 3 |
351 | -- ToIndex = 8 |
352 | -- after |
353 | -- me = (A B C B D E B H) |
354 | -- returns 7 |
355 | |
356 | Location(me; N : Integer; T : Item) returns Integer |
357 | raises OutOfRange from Standard; |
358 | ---Level: Public |
359 | ---Purpose: Returns the index of the nth occurence of the element T |
360 | -- in the sequence <me>. The search starts from the beginning |
361 | -- to the end of the sequence. |
362 | -- Returns 0 if the element is not present in the sub-sequence. |
363 | -- Raises an exception if the index is out of bounds. |
364 | ---Example: before |
365 | -- me = (A B C B D E B H), N = 3, T = B |
366 | -- after |
367 | -- me = (A B C B D E B H) |
368 | -- returns 7 |
369 | |
370 | Remove(me : mutable; Index : Integer) |
371 | raises OutOfRange from Standard; |
372 | ---Level: Public |
373 | ---Purpose: Removes the element indexed by Index in the |
374 | -- sequence <me>. |
375 | -- Raises an exception if the index is out of bounds. |
376 | ---Example: before |
377 | -- me = (A B C), Index = 3 |
378 | -- after |
379 | -- me = (A B) |
380 | |
381 | Remove(me : mutable; FromIndex, ToIndex : Integer) |
382 | raises OutOfRange from Standard; |
383 | ---Level: Public |
384 | ---Purpose: Removes the elements from the index FromIndex to the |
385 | -- index ToIndex in the sequence <me>. |
386 | -- Raises an exception if the indexes are out of bounds |
387 | ---Example: before |
388 | -- me = (A B C D E F), FromIndex = 1 ToIndex = 3 |
389 | -- after |
390 | -- me = (D E F) |
391 | |
392 | GetFirst(me) |
393 | ---Level: Internal |
394 | ---Purpose: Returns "FirstItem" field. |
395 | returns SeqNode |
396 | is private; |
397 | |
398 | GetLast(me) |
399 | ---Level: Internal |
400 | ---Purpose: Returns "LastItem" field |
401 | returns SeqNode |
402 | is private; |
403 | |
7fd59977 |
404 | Destroy(me : mutable); |
405 | ---C++: alias ~ |
406 | |
407 | fields |
408 | FirstItem : SeqNode; |
409 | LastItem : SeqNode; |
410 | Size : Integer; |
411 | |
412 | friends class SeqExplorer from PCollection |
413 | |
414 | end; |
415 | |
416 | |
417 | |
418 | |