1 -- File: TCollection_List.cdl
2 -- Created: Thu Dec 17 12:04:18 1992
3 -- Author: Remi LEQUETTE
5 ---Copyright: Matra Datavision 1992
7 generic class List from TCollection (Item as any)
8 ---Purpose: Ordered lists of non-unique objects which can be
9 -- accessed sequentially using an iterator.
10 -- Item insertion in a list is very fast at any position. But
11 -- searching for items by value may be slow if the list is long,
12 -- because it requires a sequential search.
13 -- List is a generic class which depends on Item, the type of
14 -- element in the structure.
15 -- Use a ListIterator iterator to explore a List structure.
17 -- - An iterator class is automatically instantiated from the
18 -- TCollection_ListIterator class at the time of
19 -- instantiation of a List structure.
20 -- - A sequence is a better structure when searching for
21 -- items by value is an important goal for a data structure.
22 -- - Queues and stacks are other kinds of list with a
23 -- different access to data.
26 Address from Standard,
30 NoSuchObject from Standard
32 class ListNode from TCollection
33 inherits MapNode from TCollection
34 uses MapNodePtr from TCollection
36 Create(I : Item; n : MapNodePtr from TCollection) returns ListNode from TCollection;
39 Value(me) returns Item;
48 ---Purpose: Functions used for iterating the contents of a List data structure.
49 -- A ListIterator object can be used to go through a list
50 -- sequentially, and to hold a position in a list as a
51 -- bookmark. It is not an index, however. Each step of the
52 -- iteration gives the current position of the iterator, to
53 -- which corresponds the current item in the list. The
54 -- current position is undefined if the list is empty, or when
55 -- the exploration is finished.
56 -- Note: an iterator class is automatically instantiated from
57 -- this generic class at the time of instantiation of a List
60 NoMoreObject from Standard,
61 NoSuchObject from Standard
65 Create returns ListIterator;
66 ---Purpose: Constructs an empty iterator for a List data structure. Use
67 -- the function Initialize to define the list to explore.
69 Create(L : List) returns ListIterator;
70 ---Purpose: Constructs an iterator on the list list, and positions it on
71 -- the first item of the list list, if it exists.
72 -- The current position is undefined if the list list is empty.
74 -- - the function More to know if there is a current item,
75 -- - then the function Value to read the value of the current item,
76 -- - then the function Next to position the iterator on the
77 -- next item, if it exists.
79 Initialize(me : in out; L : List)
80 ---Purpose: Sets, or resets this iterator for the list list, and positions it
81 -- on the first item of the list list, if it exists.
82 -- The current position is undefined if the list list is empty.
84 -- TColStd_ListOfInteger list;
85 -- TColStd_ListIteratorOfListOfInteger
87 -- pos.Initialize(list);
89 -- - the function More to know if there is a current item,
90 -- - then the function Value to read the value of the current item,
91 -- - then the function Next to position the iterator on the
92 -- next item, if it exists.
95 More(me) returns Boolean from Standard
96 ---Purpose: Returns true if there is a current item in the list explored
97 -- with this iterator (i.e. when the current position is defined).
99 -- - the iterator is not initialized, or
100 -- - the list is empty, or
101 -- - the exploration is finished.
103 -- - the function Value to read the current item,
104 -- - the function Next to position this iterator on the next item, if it exists.
106 -- Standard_Integer i;
107 -- TColStd_ListOfInteger s;
108 -- TColStd_ListIteratorOfListOfInteger
119 ---Purpose: Sets this iterator on the next item in the explored list.
120 -- If the current position of this iterator corresponds to the
121 -- last item in the list, it becomes undefined.
123 -- Standard_NoMoreObject if the current position of this
124 -- iterator is undefined.
126 NoMoreObject from Standard
129 Value(me) returns any Item
130 ---Purpose: Returns the value of the current item of this iterator in the
132 -- Note: Item is the type of element in the explored List list.
134 -- TColStd_ListOfInteger s;
135 -- TColStd_ListIteratorOfListOfInteger
138 -- assert (pos.Value() == s.First() );
140 -- Standard_NoSuchObject if the current position of this
141 -- iterator is undefined.
144 NoSuchObject from Standard
148 current : Address from Standard;
149 previous : Address from Standard;
152 class List from TCollection
154 end ListIterator from TCollection;
157 Create returns List from TCollection;
158 ---Purpose: Constructs an empty list.
160 -- - the function Append or Prepend to add an item or a
161 -- collection of items at the end, or at the beginning of the list,
162 -- - a list iterator to explore the list and read its items,
163 -- - and in conjunction with this iterator:
164 -- - the function InsertAfter or InsertBefore to add an
165 -- item or a collection of items at any position in the list,
166 -- - the function Remove to remove an item at any position in the list.
168 -- To copy a list, you must explicitly call the assignment operator (operator=).
170 Create(Other : List from TCollection)
171 returns List from TCollection
173 ---Purpose: Creation by copy of existing list.
174 -- Warning: This constructor prints a warning message.
175 -- We recommand to use the operator =.
177 Assign(me : in out; Other : List from TCollection)
178 ---Purpose: Replace <me> by a copy of <Other>.
179 ---C++: alias operator=
182 Extent(me) returns Integer
183 ---Purpose: Returns the number of items.
187 ---Purpose: Clears the content of the list <me>.
191 IsEmpty(me) returns Boolean from Standard
192 ---Purpose: Returns true if this list is empty.
196 Prepend(me : in out; I : Item)
198 ---Purpose: Insert the Item <I> at the head of the list.
201 -- san: 18/04/2003 - addition methods returns ListIterator
202 Prepend(me : in out; I : Item; theIt : in out ListIterator )
204 ---Purpose: Insert the Item <I> at the head of the list.
205 --- Returns ListIterator pointing to the first Item.
208 Prepend(me : in out; Other : in out List from TCollection)
210 ---Purpose: Insert the list <Other> at the head of <me>.
211 --- <Other> is cleared.
214 Append(me : in out; I : Item)
216 ---Purpose: Insert the Item <I> at the end of the list.
219 -- san: 18/04/2003 - addition methods returns ListIterator
220 Append(me : in out; I : Item; theIt : in out ListIterator )
222 ---Purpose: Insert the Item <I> at the head of the list.
223 --- Returns ListIterator pointing to the first Item.
226 Append(me : in out; Other : in out List from TCollection)
228 ---Purpose: Append the list <L> at the end of <me>.
229 --- <Other> is cleared.
232 First(me) returns any Item
233 ---Purpose: Returns the first Item in the list, may be modified.
234 -- Trigger: Raises an exception when the list is empty.
237 NoSuchObject from Standard
240 Last(me) returns any Item
241 ---Purpose: Returns the last Item in the list, may be modified.
242 -- Trigger: Raises an exception when the list is empty.
245 NoSuchObject from Standard
248 RemoveFirst(me : in out)
249 ---Purpose: Removes the first Item from the list. Nothing is
250 -- done if the list is empty.
253 Remove(me : in out; It : in out ListIterator)
254 ---Purpose: Removes the current Item of the ListIterator from the
255 -- List. The ListIterator current will be the next Item
258 -- Standard_NoSuchObject if the current position of the
259 -- list iterator pos is undefined.
261 NoSuchObject from Standard
264 InsertBefore (me : in out; I : Item;
265 It : in out ListIterator)
267 ---Purpose: Insert <I> in the List before the current position
268 -- of <It>. It is not change.
270 NoSuchObject from Standard
273 InsertBefore (me : in out; Other : in out List from TCollection;
274 It : in out ListIterator)
276 ---Purpose: Insert <Other> in the List before the current position
277 -- of <It>. <It> is not change. <Other> is cleared.
279 NoSuchObject from Standard
282 InsertAfter (me : in out; I : Item;
283 It : in out ListIterator)
285 ---Purpose: Insert <I> in the List after the current position
286 -- if <It>. <It> is not changed.
289 InsertAfter (me : in out; Other : in out List from TCollection;
290 It : in out ListIterator)
292 ---Purpose: Insert <Other> in the List after the current position
293 -- if <It>. <It> is not changed. <Other> is cleared.
297 myFirst : Address from Standard;
298 myLast : Address from Standard;
301 class ListIterator from TCollection