1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
-- File: TCollection_Sequence.cdl
-- Created: Fri Sep 11 17:34:39 1992
-- Author: Mireille MERCIEN
-- <mip@sdsun3>
---Copyright: Matra Datavision 1992
generic class Sequence from TCollection (SeqItem as any)
inherits BaseSequence from TCollection
---Purpose: A sequence of items indexed by an integer.
-- Sequences have approximately the same goal as
-- unidimensional arrays (TCollection_Array1): they are
-- commonly used as elementary data structures for more
-- complex objects. But a sequence is a structure of
-- variable size: sequences avoid the use of large and
-- quasi-empty arrays. Exploring a sequence data
-- structure is performant when the exploration is done in
-- sequence; elsewhere a sequence item is longer to read
-- than an array item. Note also that sequences are not
-- performant when they have to support numerous
-- algorithmic explorations: a map is better for that.
-- Sequence is a generic class which depends on Item,
-- the type of element in the sequence.
raises
NoSuchObject from Standard,
OutOfRange from Standard
class SequenceNode from TCollection
inherits SeqNode from TCollection
uses SeqNodePtr from TCollection
is
Create(I : SeqItem; n,p : SeqNodePtr from TCollection) returns SequenceNode from TCollection;
---C++: inline
Value(me) returns SeqItem;
---C++: return &
---C++: inline
fields
myValue : SeqItem;
end;
is
Create returns Sequence;
---Purpose: Constructs an empty sequence.
-- Use:
-- - the function Append or Prepend to add an item or
-- a collection of items at the end, or at the beginning of the sequence,
-- - the function InsertAfter or InsertBefore to add an
-- item or a collection of items at any position in the sequence,
-- - operator() or the function SetValue to assign a
-- new value to an item of the sequence,
-- - operator() to read an item of the sequence,
-- - the function Remove to remove an item at any
-- position in the sequence.
-- Warning
-- To copy a sequence, you must explicitly call the
-- assignment operator (operator=).
---C++: inline
Create(Other : Sequence) returns Sequence from TCollection
---Purpose: Creation by copy of existing Sequence.
-- Warning: This constructor prints a warning message.
-- We recommand to use the operator =.
is private;
Clear(me : in out);
---Purpose: Removes all element(s) of the sequence <me>
-- Example:
-- before
-- me = (A B C)
-- after
-- me = ()
--
---C++: alias ~
Assign(me : in out; Other : Sequence) returns Sequence from TCollection
---Purpose: Copies the contents of the sequence Other into this sequence.
-- If this sequence is not empty, it is automatically cleared before the copy.
---C++: alias operator =
---C++: return const &
is static;
Append(me : in out; T : SeqItem);
---Level: Public
---Purpose: Appends <T> at the end of <me>.
-- Example:
-- before
-- me = (A B C)
-- after
-- me = (A B C T)
Append(me : in out; S : in out Sequence)
---Level: Public
---Purpose: Concatenates <S> at the end of <me>.
-- <S> is cleared.
-- Example:
-- before
-- me = (A B C)
-- S = (D E F)
-- after
-- me = (A B C D E F)
-- S = ()
--
---C++: inline
is static;
Prepend(me : in out; T : SeqItem);
---Level: Public
---Purpose: Add <T> at the beginning of <me>.
-- Example:
-- before
-- me = (A B C)
-- after
-- me = (T A B C )
Prepend(me : in out; S : in out Sequence);
---Level: Public
---Purpose: Concatenates <S> at the beginning of <me>.
-- <S> is cleared.
-- Example:
-- before
-- me = (A B C) S = (D E F)
-- after me = (D E F A B C)
-- S = ()
--
---C++: inline
InsertBefore(me : in out; Index : Integer from Standard; T : SeqItem)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Inserts <T> in <me> before the position <Index>.
-- Raises an exception if the index is out of bounds.
-- Example:
-- before
-- me = (A B D), Index = 3, T = C
-- after
-- me = (A B C D )
--
---C++: inline
InsertBefore(me : in out ; Index : Integer from Standard; S : in out Sequence)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Inserts the sequence <S> in <me> before
-- the position <Index>. <S> is cleared.
-- Raises an exception if the index is out of bounds
-- Example:
-- before
-- me = (A B F), Index = 3, S = (C D E)
-- after
-- me = (A B C D E F)
-- S = ()
--
---C++: inline
InsertAfter(me : in out; Index : Integer from Standard; T : SeqItem)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Inserts <T> in <me> after the position <Index>.
-- Raises an exception if the index is out of bound
-- Example:
-- before
-- me = (A B C), Index = 3, T = D
-- after
-- me = (A B C D)
InsertAfter(me : in out; Index : Integer from Standard; S : in out Sequence)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Inserts the sequence <S> in <me> after the
-- position <Index>. <S> is cleared.
-- Raises an exception if the index is out of bound.
-- Example:
-- before
-- me = (A B C), Index = 3, S = (D E F)
-- after
-- me = (A B C D E F)
-- S = ()
--
---C++: inline
First(me) returns any SeqItem
raises NoSuchObject from Standard
---Level: Public
---Purpose: Returns the first element of the sequence <me>
-- Raises an exception if the sequence is empty.
-- Example:
-- before
-- me = (A B C)
-- after
-- me = (A B C)
-- returns A
---C++: return const &
is static;
Last(me) returns any SeqItem
raises NoSuchObject from Standard
---Level: Public
---Purpose: Returns the last element of the sequence <me>
-- Raises an exception if the sequence is empty.
-- Example:
-- before
-- me = (A B C)
-- after
-- me = (A B C)
-- returns C
---C++: return const &
is static;
Split(me : in out; Index : Integer from Standard; Sub : in out Sequence)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Keeps in <me> the items 1 to <Index>-1 and
-- puts in <Sub> the items <Index> to the end.
-- Example:
-- before
-- me = (A B C D) ,Index = 3
-- after
-- me = (A B)
-- Sub = (C D)
--
---C++: inline
Value(me; Index : Integer from Standard) returns any SeqItem
raises OutOfRange from Standard;
---Level: Public
---Purpose: Returns the Item at position <Index> in <me>.
-- Raises an exception if the index is out of bound
-- Example:
-- before
-- me = (A B C), Index = 1
-- after
-- me = (A B C)
-- returns
-- A
---C++: return const &
---C++: alias operator()
SetValue(me : in out; Index : Integer from Standard; I : SeqItem)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Changes the item at position <Index>
-- Raises an exception if the index is out of bound
-- Example:
-- before
-- me = (A B C), Index = 1, Item = D
-- after
-- me = (D B C)
--
ChangeValue(me : in out; Index : Integer from Standard) returns any SeqItem
raises OutOfRange from Standard;
---Level: Public
---Purpose: Returns the Item at position <Index> in
-- <me>. This method may be used to modify
-- <me> : S.Value(Index) = Item.
-- Raises an exception if the index is out of bound
-- Example:
-- before
-- me = (A B C), Index = 1
-- after
-- me = (A B C)
-- returns
-- A
---C++: return &
---C++: alias operator()
Remove(me : in out; Index : Integer from Standard)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Removes from <me> the item at position <Index>.
-- Raises an exception if the index is out of bounds
-- Example:
-- before
-- me = (A B C), Index = 3
-- after
-- me = (A B)
Remove(me : in out; FromIndex, ToIndex : Integer from Standard)
raises OutOfRange from Standard;
---Level: Public
---Purpose: Removes from <me> all the items of
-- positions between <FromIndex> and <ToIndex>.
-- Raises an exception if the indices are out of bounds.
-- Example:
-- before
-- me = (A B C D E F), FromIndex = 1 ToIndex = 3
-- after
-- me = (D E F)
end;
|