OSDN Git Service

2011-09-06 Ed Schonberg <schonberg@adacore.com>
[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    procedure Assign (Target : in out List; Source : List);
92
93    function Copy (Source : List; Capacity : Count_Type := 0) return List;
94
95    procedure Move
96      (Target : in out List;
97       Source : in out List);
98
99    procedure Insert
100      (Container : in out List;
101       Before    : Cursor;
102       New_Item  : Element_Type;
103       Count     : Count_Type := 1);
104
105    procedure Insert
106      (Container : in out List;
107       Before    : Cursor;
108       New_Item  : Element_Type;
109       Position  : out Cursor;
110       Count     : Count_Type := 1);
111
112    procedure Insert
113      (Container : in out List;
114       Before    : Cursor;
115       Position  : out Cursor;
116       Count     : Count_Type := 1);
117
118    procedure Prepend
119      (Container : in out List;
120       New_Item  : Element_Type;
121       Count     : Count_Type := 1);
122
123    procedure Append
124      (Container : in out List;
125       New_Item  : Element_Type;
126       Count     : Count_Type := 1);
127
128    procedure Delete
129      (Container : in out List;
130       Position  : in out Cursor;
131       Count     : Count_Type := 1);
132
133    procedure Delete_First
134      (Container : in out List;
135       Count     : Count_Type := 1);
136
137    procedure Delete_Last
138      (Container : in out List;
139       Count     : Count_Type := 1);
140
141    procedure Reverse_Elements (Container : in out List);
142
143    function Iterate
144      (Container : List)
145       return List_Iterator_Interfaces.Reversible_Iterator'class;
146
147    function Iterate
148      (Container : List;
149       Start     : Cursor)
150       return List_Iterator_Interfaces.Reversible_Iterator'class;
151
152    procedure Swap
153      (Container : in out List;
154       I, J      : Cursor);
155
156    procedure Swap_Links
157      (Container : in out List;
158       I, J      : Cursor);
159
160    procedure Splice
161      (Target : in out List;
162       Before : Cursor;
163       Source : in out List);
164
165    procedure Splice
166      (Target   : in out List;
167       Before   : Cursor;
168       Source   : in out List;
169       Position : in out Cursor);
170
171    procedure Splice
172      (Container : in out List;
173       Before    : Cursor;
174       Position  : Cursor);
175
176    function First (Container : List) return Cursor;
177
178    function First_Element (Container : List) return Element_Type;
179
180    function Last (Container : List) return Cursor;
181
182    function Last_Element (Container : List) return Element_Type;
183
184    function Next (Position : Cursor) return Cursor;
185
186    procedure Next (Position : in out Cursor);
187
188    function Previous (Position : Cursor) return Cursor;
189
190    procedure Previous (Position : in out Cursor);
191
192    function Find
193      (Container : List;
194       Item      : Element_Type;
195       Position  : Cursor := No_Element) return Cursor;
196
197    function Reverse_Find
198      (Container : List;
199       Item      : Element_Type;
200       Position  : Cursor := No_Element) return Cursor;
201
202    function Contains
203      (Container : List;
204       Item      : Element_Type) return Boolean;
205
206    procedure Iterate
207      (Container : List;
208       Process   : not null access procedure (Position : Cursor));
209
210    procedure Reverse_Iterate
211      (Container : List;
212       Process   : not null access procedure (Position : Cursor));
213
214    generic
215       with function "<" (Left, Right : Element_Type) return Boolean is <>;
216    package Generic_Sorting is
217
218       function Is_Sorted (Container : List) return Boolean;
219
220       procedure Sort (Container : in out List);
221
222       procedure Merge (Target, Source : in out List);
223
224    end Generic_Sorting;
225
226    type Constant_Reference_Type
227       (Element : not null access constant Element_Type) is private
228    with
229       Implicit_Dereference => Element;
230
231    procedure Write
232      (Stream : not null access Root_Stream_Type'Class;
233       Item   : Constant_Reference_Type);
234
235    for Constant_Reference_Type'Write use Write;
236
237    procedure Read
238      (Stream : not null access Root_Stream_Type'Class;
239       Item   : out Constant_Reference_Type);
240
241    for Constant_Reference_Type'Read use Read;
242
243    type Reference_Type (Element : not null access Element_Type) is
244    private
245    with
246       Implicit_Dereference => Element;
247
248    procedure Write
249      (Stream : not null access Root_Stream_Type'Class;
250       Item   : Reference_Type);
251
252    for Reference_Type'Write use Write;
253
254    procedure Read
255      (Stream : not null access Root_Stream_Type'Class;
256       Item   : out Reference_Type);
257
258    for Reference_Type'Read use Read;
259
260    function Constant_Reference
261      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
262    return Constant_Reference_Type;
263
264    function Reference
265      (Container : List; Position : Cursor)    --  SHOULD BE ALIASED
266    return Reference_Type;
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 : 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;