OSDN Git Service

ada:
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cidlli.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --               ADA.CONTAINERS.INDEFINITE_DOUBLY_LINKED_LISTS              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the  contents of the part following the private keyword. --
14 --                                                                          --
15 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
16 -- terms of the  GNU General Public License as published  by the Free Soft- --
17 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
18 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
21 --                                                                          --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception,   --
24 -- version 3.1, as published by the Free Software Foundation.               --
25 --                                                                          --
26 -- You should have received a copy of the GNU General Public License and    --
27 -- a copy of the GCC Runtime Library Exception along with this program;     --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29 -- <http://www.gnu.org/licenses/>.                                          --
30 --                                                                          --
31 -- This unit was originally developed by Matthew J Heaney.                  --
32 ------------------------------------------------------------------------------
33
34 with Ada.Iterator_Interfaces;
35 with Ada.Streams;             use Ada.Streams;
36
37 private with Ada.Finalization;
38
39 generic
40    type Element_Type (<>) is private;
41
42    with function "=" (Left, Right : Element_Type)
43       return Boolean is <>;
44
45 package Ada.Containers.Indefinite_Doubly_Linked_Lists is
46    pragma Preelaborate;
47    pragma Remote_Types;
48
49    type List is tagged private with
50       Constant_Indexing => Constant_Reference,
51       Variable_Indexing => Reference,
52       Default_Iterator  => Iterate,
53       Iterator_Element  => Element_Type;
54
55    pragma Preelaborable_Initialization (List);
56
57    type Cursor is private;
58    pragma Preelaborable_Initialization (Cursor);
59
60    Empty_List : constant List;
61
62    No_Element : constant Cursor;
63
64    function Has_Element (Position : Cursor) return Boolean;
65
66    package List_Iterator_Interfaces is new
67      Ada.Iterator_Interfaces (Cursor, Has_Element);
68
69    function "=" (Left, Right : List) return Boolean;
70
71    function Length (Container : List) return Count_Type;
72
73    function Is_Empty (Container : List) return Boolean;
74
75    procedure Clear (Container : in out List);
76
77    function Element (Position : Cursor) return Element_Type;
78
79    procedure Replace_Element
80      (Container : in out List;
81       Position  : Cursor;
82       New_Item  : Element_Type);
83
84    procedure Query_Element
85      (Position : Cursor;
86       Process  : not null access procedure (Element : Element_Type));
87
88    procedure Update_Element
89      (Container : in out List;
90       Position  : Cursor;
91       Process   : not null access procedure (Element : in out Element_Type));
92
93    procedure Move
94      (Target : in out List;
95       Source : in out List);
96
97    procedure Insert
98      (Container : in out List;
99       Before    : Cursor;
100       New_Item  : Element_Type;
101       Count     : Count_Type := 1);
102
103    procedure Insert
104      (Container : in out List;
105       Before    : Cursor;
106       New_Item  : Element_Type;
107       Position  : out Cursor;
108       Count     : Count_Type := 1);
109
110    procedure Prepend
111      (Container : in out List;
112       New_Item  : Element_Type;
113       Count     : Count_Type := 1);
114
115    procedure Append
116      (Container : in out List;
117       New_Item  : Element_Type;
118       Count     : Count_Type := 1);
119
120    procedure Delete
121      (Container : in out List;
122       Position  : in out Cursor;
123       Count     : Count_Type := 1);
124
125    procedure Delete_First
126      (Container : in out List;
127       Count     : Count_Type := 1);
128
129    procedure Delete_Last
130      (Container : in out List;
131       Count     : Count_Type := 1);
132
133    procedure Reverse_Elements (Container : in out List);
134
135    procedure Swap (Container : in out List; I, J : Cursor);
136
137    procedure Swap_Links (Container : in out List; I, J : Cursor);
138
139    procedure Splice
140      (Target : in out List;
141       Before : Cursor;
142       Source : in out List);
143
144    procedure Splice
145      (Target   : in out List;
146       Before   : Cursor;
147       Source   : in out List;
148       Position : in out Cursor);
149
150    procedure Splice
151      (Container : in out List;
152       Before    : Cursor;
153       Position  : Cursor);
154
155    function First (Container : List) return Cursor;
156
157    function First_Element (Container : List) return Element_Type;
158
159    function Last (Container : List) return Cursor;
160
161    function Last_Element (Container : List) return Element_Type;
162
163    function Next (Position : Cursor) return Cursor;
164
165    procedure Next (Position : in out Cursor);
166
167    function Previous (Position : Cursor) return Cursor;
168
169    procedure Previous (Position : in out Cursor);
170
171    function Find
172      (Container : List;
173       Item      : Element_Type;
174       Position  : Cursor := No_Element) return Cursor;
175
176    function Reverse_Find
177      (Container : List;
178       Item      : Element_Type;
179       Position  : Cursor := No_Element) return Cursor;
180
181    function Contains
182      (Container : List;
183       Item      : Element_Type) return Boolean;
184
185    procedure Iterate
186      (Container : List;
187       Process   : not null access procedure (Position : Cursor));
188
189    procedure Reverse_Iterate
190      (Container : List;
191       Process   : not null access procedure (Position : Cursor));
192
193    function Iterate
194      (Container : List)
195       return List_Iterator_Interfaces.Reversible_Iterator'class;
196
197    function Iterate
198      (Container : List;
199       Start     : Cursor)
200       return List_Iterator_Interfaces.Reversible_Iterator'class;
201
202    type Constant_Reference_Type
203       (Element : not null access constant Element_Type) is private
204    with
205       Implicit_Dereference => Element;
206
207    procedure Write
208      (Stream : not null access Root_Stream_Type'Class;
209       Item   : Constant_Reference_Type);
210
211    for Constant_Reference_Type'Write use Write;
212
213    procedure Read
214      (Stream : not null access Root_Stream_Type'Class;
215       Item   : out Constant_Reference_Type);
216
217    for Constant_Reference_Type'Read use Read;
218
219    type Reference_Type (Element : not null access Element_Type) is
220    private
221    with
222       Implicit_Dereference => Element;
223
224    procedure Write
225      (Stream : not null access Root_Stream_Type'Class;
226       Item   : Reference_Type);
227
228    for Reference_Type'Write use Write;
229
230    procedure Read
231      (Stream : not null access Root_Stream_Type'Class;
232       Item   : out Reference_Type);
233
234    for Reference_Type'Read use Read;
235
236    function Constant_Reference
237      (Container : List;
238       Position  : Cursor)    --  SHOULD BE ALIASED ???
239       return Constant_Reference_Type;
240
241    function Reference
242      (Container : List;
243       Position  : Cursor)    --  SHOULD BE ALIASED ???
244       return Reference_Type;
245
246    generic
247       with function "<" (Left, Right : Element_Type) return Boolean is <>;
248    package Generic_Sorting is
249
250       function Is_Sorted (Container : List) return Boolean;
251
252       procedure Sort (Container : in out List);
253
254       procedure Merge (Target, Source : in out List);
255
256    end Generic_Sorting;
257
258 private
259
260    pragma Inline (Next);
261    pragma Inline (Previous);
262
263    type Node_Type;
264    type Node_Access is access Node_Type;
265
266    type Element_Access is access Element_Type;
267
268    type Node_Type is
269       limited record
270          Element : Element_Access;
271          Next    : Node_Access;
272          Prev    : Node_Access;
273       end record;
274
275    use Ada.Finalization;
276
277    type List is
278      new Controlled with record
279         First  : Node_Access;
280         Last   : Node_Access;
281         Length : Count_Type := 0;
282         Busy   : Natural := 0;
283         Lock   : Natural := 0;
284      end record;
285
286    type Constant_Reference_Type
287       (Element : not null access constant Element_Type) is null record;
288
289    type Reference_Type
290       (Element : not null access Element_Type) is null record;
291
292    overriding procedure Adjust (Container : in out List);
293
294    overriding procedure Finalize (Container : in out List) renames Clear;
295
296    procedure Read
297      (Stream : not null access Root_Stream_Type'Class;
298       Item   : out List);
299
300    for List'Read use Read;
301
302    procedure Write
303      (Stream : not null access Root_Stream_Type'Class;
304       Item   : List);
305
306    for List'Write use Write;
307
308    type List_Access is access constant List;
309    for List_Access'Storage_Size use 0;
310
311    type Cursor is
312       record
313          Container : List_Access;
314          Node      : Node_Access;
315       end record;
316
317    procedure Read
318      (Stream : not null access Root_Stream_Type'Class;
319       Item   : out Cursor);
320
321    for Cursor'Read use Read;
322
323    procedure Write
324      (Stream : not null access Root_Stream_Type'Class;
325       Item   : Cursor);
326
327    for Cursor'Write use Write;
328
329    Empty_List : constant List := List'(Controlled with null, null, 0, 0, 0);
330
331    No_Element : constant Cursor := Cursor'(null, null);
332
333 end Ada.Containers.Indefinite_Doubly_Linked_Lists;