OSDN Git Service

2011-09-06 Ed Schonberg <schonberg@adacore.com>
[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 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 Insert
111      (Container : in out List;
112       Before    : Cursor;
113       Position  : out Cursor;
114       Count     : Count_Type := 1);
115
116    procedure Prepend
117      (Container : in out List;
118       New_Item  : Element_Type;
119       Count     : Count_Type := 1);
120
121    procedure Append
122      (Container : in out List;
123       New_Item  : Element_Type;
124       Count     : Count_Type := 1);
125
126    procedure Delete
127      (Container : in out List;
128       Position  : in out Cursor;
129       Count     : Count_Type := 1);
130
131    procedure Delete_First
132      (Container : in out List;
133       Count     : Count_Type := 1);
134
135    procedure Delete_Last
136      (Container : in out List;
137       Count     : Count_Type := 1);
138
139    procedure Reverse_Elements (Container : in out List);
140
141    function Iterate (Container : List)
142       return List_Iterator_Interfaces.Reversible_Iterator'class;
143
144    function Iterate (Container : List; Start : Cursor)
145       return List_Iterator_Interfaces.Reversible_Iterator'class;
146
147    procedure Swap
148      (Container : in out List;
149       I, J      : Cursor);
150
151    procedure Swap_Links
152      (Container : in out List;
153       I, J      : Cursor);
154
155    procedure Splice
156      (Target : in out List;
157       Before : Cursor;
158       Source : in out List);
159
160    procedure Splice
161      (Target   : in out List;
162       Before   : Cursor;
163       Source   : in out List;
164       Position : in out Cursor);
165
166    procedure Splice
167      (Container : in out List;
168       Before    : Cursor;
169       Position  : Cursor);
170
171    function First (Container : List) return Cursor;
172
173    function First_Element (Container : List) return Element_Type;
174
175    function Last (Container : List) return Cursor;
176
177    function Last_Element (Container : List) return Element_Type;
178
179    function Next (Position : Cursor) return Cursor;
180
181    procedure Next (Position : in out Cursor);
182
183    function Previous (Position : Cursor) return Cursor;
184
185    procedure Previous (Position : in out Cursor);
186
187    function Find
188      (Container : List;
189       Item      : Element_Type;
190       Position  : Cursor := No_Element) return Cursor;
191
192    function Reverse_Find
193      (Container : List;
194       Item      : Element_Type;
195       Position  : Cursor := No_Element) return Cursor;
196
197    function Contains
198      (Container : List;
199       Item      : Element_Type) return Boolean;
200
201    procedure Iterate
202      (Container : List;
203       Process   : not null access procedure (Position : Cursor));
204
205    procedure Reverse_Iterate
206      (Container : List;
207       Process   : not null access procedure (Position : Cursor));
208
209    generic
210       with function "<" (Left, Right : Element_Type) return Boolean is <>;
211    package Generic_Sorting is
212
213       function Is_Sorted (Container : List) return Boolean;
214
215       procedure Sort (Container : in out List);
216
217       procedure Merge (Target, Source : in out List);
218
219    end Generic_Sorting;
220
221    type Constant_Reference_Type
222       (Element : not null access constant Element_Type) is private
223    with
224       Implicit_Dereference => Element;
225
226    procedure Write
227      (Stream : not null access Root_Stream_Type'Class;
228       Item   : Constant_Reference_Type);
229
230    for Constant_Reference_Type'Write use Write;
231
232    procedure Read
233      (Stream : not null access Root_Stream_Type'Class;
234       Item   : out Constant_Reference_Type);
235
236    for Constant_Reference_Type'Read use Read;
237
238    type Reference_Type (Element : not null access Element_Type) is
239    private
240    with
241       Implicit_Dereference => Element;
242
243    procedure Write
244      (Stream : not null access Root_Stream_Type'Class;
245       Item   : Reference_Type);
246
247    for Reference_Type'Write use Write;
248
249    procedure Read
250      (Stream : not null access Root_Stream_Type'Class;
251       Item   : out Reference_Type);
252
253    for Reference_Type'Read use Read;
254
255    function Constant_Reference
256      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
257    return Constant_Reference_Type;
258
259    function Reference
260      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
261    return Reference_Type;
262
263 private
264
265    pragma Inline (Next);
266    pragma Inline (Previous);
267
268    type Node_Type;
269    type Node_Access is access Node_Type;
270
271    type Node_Type is
272       limited record
273          Element : aliased Element_Type;
274          Next    : Node_Access;
275          Prev    : Node_Access;
276       end record;
277
278    use Ada.Finalization;
279
280    type List is
281      new Controlled with record
282         First  : Node_Access;
283         Last   : Node_Access;
284         Length : Count_Type := 0;
285         Busy   : Natural := 0;
286         Lock   : Natural := 0;
287      end record;
288
289    overriding procedure Adjust (Container : in out List);
290
291    overriding procedure Finalize (Container : in out List) renames Clear;
292
293    procedure Read
294      (Stream : not null access Root_Stream_Type'Class;
295       Item   : out List);
296
297    for List'Read use Read;
298
299    procedure Write
300      (Stream : not null access Root_Stream_Type'Class;
301       Item   : List);
302
303    for List'Write use Write;
304
305    type List_Access is access constant List;
306    for List_Access'Storage_Size use 0;
307
308    type Cursor is
309       record
310          Container : List_Access;
311          Node      : Node_Access;
312       end record;
313
314    procedure Read
315      (Stream : not null access Root_Stream_Type'Class;
316       Item   : out Cursor);
317
318    for Cursor'Read use Read;
319
320    procedure Write
321      (Stream : not null access Root_Stream_Type'Class;
322       Item   : Cursor);
323
324    for Cursor'Write use Write;
325
326    type Constant_Reference_Type
327       (Element : not null access constant Element_Type) is null record;
328
329    type Reference_Type
330       (Element : not null access Element_Type) is null record;
331
332    Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
333
334    No_Element : constant Cursor := Cursor'(null, null);
335
336 end Ada.Containers.Doubly_Linked_Lists;