OSDN Git Service

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