OSDN Git Service

2012-01-05 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cdlili.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --   A D A . C O N T A I N E R S . D O U B L Y _ L I N K E D _ L I S T S    --
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 private with Ada.Finalization;
35
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
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.Doubly_Linked_Lists is
46    pragma Preelaborate;
47    pragma Remote_Types;
48
49    type List is tagged private
50    with
51       Constant_Indexing => Constant_Reference,
52       Variable_Indexing => Reference,
53       Default_Iterator  => Iterate,
54       Iterator_Element  => Element_Type;
55
56    pragma Preelaborable_Initialization (List);
57
58    type Cursor is private;
59    pragma Preelaborable_Initialization (Cursor);
60
61    Empty_List : constant List;
62
63    No_Element : constant Cursor;
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 Assign (Target : in out List; Source : List);
94
95    function Copy (Source : List) return List;
96
97    procedure Move
98      (Target : in out List;
99       Source : in out List);
100
101    procedure Insert
102      (Container : in out List;
103       Before    : Cursor;
104       New_Item  : Element_Type;
105       Count     : Count_Type := 1);
106
107    procedure Insert
108      (Container : in out List;
109       Before    : Cursor;
110       New_Item  : Element_Type;
111       Position  : out Cursor;
112       Count     : Count_Type := 1);
113
114    procedure Insert
115      (Container : in out List;
116       Before    : Cursor;
117       Position  : out Cursor;
118       Count     : Count_Type := 1);
119
120    procedure Prepend
121      (Container : in out List;
122       New_Item  : Element_Type;
123       Count     : Count_Type := 1);
124
125    procedure Append
126      (Container : in out List;
127       New_Item  : Element_Type;
128       Count     : Count_Type := 1);
129
130    procedure Delete
131      (Container : in out List;
132       Position  : in out Cursor;
133       Count     : Count_Type := 1);
134
135    procedure Delete_First
136      (Container : in out List;
137       Count     : Count_Type := 1);
138
139    procedure Delete_Last
140      (Container : in out List;
141       Count     : Count_Type := 1);
142
143    procedure Reverse_Elements (Container : in out List);
144
145    function Iterate (Container : List)
146       return List_Iterator_Interfaces.Reversible_Iterator'Class;
147
148    function Iterate (Container : List; Start : Cursor)
149       return List_Iterator_Interfaces.Reversible_Iterator'Class;
150
151    procedure Swap
152      (Container : in out List;
153       I, J      : Cursor);
154
155    procedure Swap_Links
156      (Container : in out List;
157       I, J      : Cursor);
158
159    procedure Splice
160      (Target : in out List;
161       Before : Cursor;
162       Source : in out List);
163
164    procedure Splice
165      (Target   : in out List;
166       Before   : Cursor;
167       Source   : in out List;
168       Position : in out Cursor);
169
170    procedure Splice
171      (Container : in out List;
172       Before    : Cursor;
173       Position  : Cursor);
174
175    function First (Container : List) return Cursor;
176
177    function First_Element (Container : List) return Element_Type;
178
179    function Last (Container : List) return Cursor;
180
181    function Last_Element (Container : List) return Element_Type;
182
183    function Next (Position : Cursor) return Cursor;
184
185    procedure Next (Position : in out Cursor);
186
187    function Previous (Position : Cursor) return Cursor;
188
189    procedure Previous (Position : in out Cursor);
190
191    function Find
192      (Container : List;
193       Item      : Element_Type;
194       Position  : Cursor := No_Element) return Cursor;
195
196    function Reverse_Find
197      (Container : List;
198       Item      : Element_Type;
199       Position  : Cursor := No_Element) return Cursor;
200
201    function Contains
202      (Container : List;
203       Item      : Element_Type) return Boolean;
204
205    procedure Iterate
206      (Container : List;
207       Process   : not null access procedure (Position : Cursor));
208
209    procedure Reverse_Iterate
210      (Container : List;
211       Process   : not null access procedure (Position : Cursor));
212
213    generic
214       with function "<" (Left, Right : Element_Type) return Boolean is <>;
215    package Generic_Sorting is
216
217       function Is_Sorted (Container : List) return Boolean;
218
219       procedure Sort (Container : in out List);
220
221       procedure Merge (Target, Source : in out List);
222
223    end Generic_Sorting;
224
225    type Constant_Reference_Type
226       (Element : not null access constant Element_Type) is private
227    with
228       Implicit_Dereference => Element;
229
230    procedure Write
231      (Stream : not null access Root_Stream_Type'Class;
232       Item   : Constant_Reference_Type);
233
234    for Constant_Reference_Type'Write use Write;
235
236    procedure Read
237      (Stream : not null access Root_Stream_Type'Class;
238       Item   : out Constant_Reference_Type);
239
240    for Constant_Reference_Type'Read use Read;
241
242    type Reference_Type (Element : not null access Element_Type) is
243    private
244    with
245       Implicit_Dereference => Element;
246
247    procedure Write
248      (Stream : not null access Root_Stream_Type'Class;
249       Item   : Reference_Type);
250
251    for Reference_Type'Write use Write;
252
253    procedure Read
254      (Stream : not null access Root_Stream_Type'Class;
255       Item   : out Reference_Type);
256
257    for Reference_Type'Read use Read;
258
259    function Constant_Reference
260      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
261    return Constant_Reference_Type;
262
263    function Reference
264      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
265    return Reference_Type;
266
267 private
268
269    pragma Inline (Next);
270    pragma Inline (Previous);
271
272    type Node_Type;
273    type Node_Access is access Node_Type;
274
275    type Node_Type is
276       limited record
277          Element : aliased Element_Type;
278          Next    : Node_Access;
279          Prev    : Node_Access;
280       end record;
281
282    use Ada.Finalization;
283
284    type List is
285      new Controlled with record
286         First  : Node_Access;
287         Last   : Node_Access;
288         Length : Count_Type := 0;
289         Busy   : Natural := 0;
290         Lock   : Natural := 0;
291      end record;
292
293    overriding procedure Adjust (Container : in out List);
294
295    overriding procedure Finalize (Container : in out List) renames Clear;
296
297    procedure Read
298      (Stream : not null access Root_Stream_Type'Class;
299       Item   : out List);
300
301    for List'Read use Read;
302
303    procedure Write
304      (Stream : not null access Root_Stream_Type'Class;
305       Item   : List);
306
307    for List'Write use Write;
308
309    type List_Access is access all List;
310    for List_Access'Storage_Size use 0;
311
312    type Cursor is
313       record
314          Container : List_Access;
315          Node      : Node_Access;
316       end record;
317
318    procedure Read
319      (Stream : not null access Root_Stream_Type'Class;
320       Item   : out Cursor);
321
322    for Cursor'Read use Read;
323
324    procedure Write
325      (Stream : not null access Root_Stream_Type'Class;
326       Item   : Cursor);
327
328    for Cursor'Write use Write;
329
330    type Constant_Reference_Type
331       (Element : not null access constant Element_Type) is null record;
332
333    type Reference_Type
334       (Element : not null access Element_Type) is null record;
335
336    Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
337
338    No_Element : constant Cursor := Cursor'(null, null);
339
340 end Ada.Containers.Doubly_Linked_Lists;