OSDN Git Service

* c-decl.c (grokfield): Allow typedefs for anonymous structs and
[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-2009, 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 private with Ada.Streams;
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.Doubly_Linked_Lists is
44    pragma Preelaborate;
45    pragma Remote_Types;
46
47    type List is tagged private;
48    pragma Preelaborable_Initialization (List);
49
50    type Cursor is private;
51    pragma Preelaborable_Initialization (Cursor);
52
53    Empty_List : constant List;
54
55    No_Element : constant Cursor;
56
57    function "=" (Left, Right : List) return Boolean;
58
59    function Length (Container : List) return Count_Type;
60
61    function Is_Empty (Container : List) return Boolean;
62
63    procedure Clear (Container : in out List);
64
65    function Element (Position : Cursor) return Element_Type;
66
67    procedure Replace_Element
68      (Container : in out List;
69       Position  : Cursor;
70       New_Item  : Element_Type);
71
72    procedure Query_Element
73      (Position : Cursor;
74       Process  : not null access procedure (Element : Element_Type));
75
76    procedure Update_Element
77      (Container : in out List;
78       Position  : Cursor;
79       Process   : not null access procedure (Element : in out Element_Type));
80
81    procedure Move
82      (Target : in out List;
83       Source : in out List);
84
85    procedure Insert
86      (Container : in out List;
87       Before    : Cursor;
88       New_Item  : Element_Type;
89       Count     : Count_Type := 1);
90
91    procedure Insert
92      (Container : in out List;
93       Before    : Cursor;
94       New_Item  : Element_Type;
95       Position  : out Cursor;
96       Count     : Count_Type := 1);
97
98    procedure Insert
99      (Container : in out List;
100       Before    : Cursor;
101       Position  : out Cursor;
102       Count     : Count_Type := 1);
103
104    procedure Prepend
105      (Container : in out List;
106       New_Item  : Element_Type;
107       Count     : Count_Type := 1);
108
109    procedure Append
110      (Container : in out List;
111       New_Item  : Element_Type;
112       Count     : Count_Type := 1);
113
114    procedure Delete
115      (Container : in out List;
116       Position  : in out Cursor;
117       Count     : Count_Type := 1);
118
119    procedure Delete_First
120      (Container : in out List;
121       Count     : Count_Type := 1);
122
123    procedure Delete_Last
124      (Container : in out List;
125       Count     : Count_Type := 1);
126
127    procedure Reverse_Elements (Container : in out List);
128
129    procedure Swap
130      (Container : in out List;
131       I, J      : Cursor);
132
133    procedure Swap_Links
134      (Container : in out List;
135       I, J      : Cursor);
136
137    procedure Splice
138      (Target : in out List;
139       Before : Cursor;
140       Source : in out List);
141
142    procedure Splice
143      (Target   : in out List;
144       Before   : Cursor;
145       Source   : in out List;
146       Position : in out Cursor);
147
148    procedure Splice
149      (Container : in out List;
150       Before    : Cursor;
151       Position  : Cursor);
152
153    function First (Container : List) return Cursor;
154
155    function First_Element (Container : List) return Element_Type;
156
157    function Last (Container : List) return Cursor;
158
159    function Last_Element (Container : List) return Element_Type;
160
161    function Next (Position : Cursor) return Cursor;
162
163    procedure Next (Position : in out Cursor);
164
165    function Previous (Position : Cursor) return Cursor;
166
167    procedure Previous (Position : in out Cursor);
168
169    function Find
170      (Container : List;
171       Item      : Element_Type;
172       Position  : Cursor := No_Element) return Cursor;
173
174    function Reverse_Find
175      (Container : List;
176       Item      : Element_Type;
177       Position  : Cursor := No_Element) return Cursor;
178
179    function Contains
180      (Container : List;
181       Item      : Element_Type) return Boolean;
182
183    function Has_Element (Position : Cursor) 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    generic
194       with function "<" (Left, Right : Element_Type) return Boolean is <>;
195    package Generic_Sorting is
196
197       function Is_Sorted (Container : List) return Boolean;
198
199       procedure Sort (Container : in out List);
200
201       procedure Merge (Target, Source : in out List);
202
203    end Generic_Sorting;
204
205 private
206
207    pragma Inline (Next);
208    pragma Inline (Previous);
209
210    type Node_Type;
211    type Node_Access is access Node_Type;
212
213    type Node_Type is
214       limited record
215          Element : Element_Type;
216          Next    : Node_Access;
217          Prev    : Node_Access;
218       end record;
219
220    use Ada.Finalization;
221
222    type List is
223      new Controlled with record
224         First  : Node_Access;
225         Last   : Node_Access;
226         Length : Count_Type := 0;
227         Busy   : Natural := 0;
228         Lock   : Natural := 0;
229      end record;
230
231    overriding
232    procedure Adjust (Container : in out List);
233
234    overriding
235    procedure Finalize (Container : in out List) renames Clear;
236
237    use Ada.Streams;
238
239    procedure Read
240      (Stream : not null access Root_Stream_Type'Class;
241       Item   : out List);
242
243    for List'Read use Read;
244
245    procedure Write
246      (Stream : not null access Root_Stream_Type'Class;
247       Item   : List);
248
249    for List'Write use Write;
250
251    type List_Access is access constant List;
252    for List_Access'Storage_Size use 0;
253
254    type Cursor is
255       record
256          Container : List_Access;
257          Node      : Node_Access;
258       end record;
259
260    procedure Read
261      (Stream : not null access Root_Stream_Type'Class;
262       Item   : out Cursor);
263
264    for Cursor'Read use Read;
265
266    procedure Write
267      (Stream : not null access Root_Stream_Type'Class;
268       Item   : Cursor);
269
270    for Cursor'Write use Write;
271
272    Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
273
274    No_Element : constant Cursor := Cursor'(null, null);
275
276 end Ada.Containers.Doubly_Linked_Lists;