OSDN Git Service

2007-03-01 Paul Brook <paul@codesourcery.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-2006, 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 2,  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.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, USA.                                              --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- This unit was originally developed by Matthew J Heaney.                  --
34 ------------------------------------------------------------------------------
35
36 with Ada.Finalization;
37 with Ada.Streams;
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
48    type List is tagged private;
49    pragma Preelaborable_Initialization (List);
50
51    type Cursor is private;
52    pragma Preelaborable_Initialization (Cursor);
53
54    Empty_List : constant List;
55
56    No_Element : constant Cursor;
57
58    function "=" (Left, Right : List) return Boolean;
59
60    function Length (Container : List) return Count_Type;
61
62    function Is_Empty (Container : List) return Boolean;
63
64    procedure Clear (Container : in out List);
65
66    function Element (Position : Cursor) return Element_Type;
67
68    procedure Replace_Element
69      (Container : in out List;
70       Position  : Cursor;
71       New_Item  : Element_Type);
72
73    procedure Query_Element
74      (Position : Cursor;
75       Process  : not null access procedure (Element : Element_Type));
76
77    procedure Update_Element
78      (Container : in out List;
79       Position  : Cursor;
80       Process   : not null access procedure (Element : in out Element_Type));
81
82    procedure Move
83      (Target : in out List;
84       Source : in out List);
85
86    procedure Insert
87      (Container : in out List;
88       Before    : Cursor;
89       New_Item  : Element_Type;
90       Count     : Count_Type := 1);
91
92    procedure Insert
93      (Container : in out List;
94       Before    : Cursor;
95       New_Item  : Element_Type;
96       Position  : out Cursor;
97       Count     : Count_Type := 1);
98
99    procedure Insert
100      (Container : in out List;
101       Before    : Cursor;
102       Position  : out Cursor;
103       Count     : Count_Type := 1);
104
105    procedure Prepend
106      (Container : in out List;
107       New_Item  : Element_Type;
108       Count     : Count_Type := 1);
109
110    procedure Append
111      (Container : in out List;
112       New_Item  : Element_Type;
113       Count     : Count_Type := 1);
114
115    procedure Delete
116      (Container : in out List;
117       Position  : in out Cursor;
118       Count     : Count_Type := 1);
119
120    procedure Delete_First
121      (Container : in out List;
122       Count     : Count_Type := 1);
123
124    procedure Delete_Last
125      (Container : in out List;
126       Count     : Count_Type := 1);
127
128    procedure Reverse_Elements (Container : in out List);
129
130    procedure Swap
131      (Container : in out List;
132       I, J      : Cursor);
133
134    procedure Swap_Links
135      (Container : in out List;
136       I, J      : Cursor);
137
138    procedure Splice
139      (Target : in out List;
140       Before : Cursor;
141       Source : in out List);
142
143    procedure Splice
144      (Target   : in out List;
145       Before   : Cursor;
146       Source   : in out List;
147       Position : in out Cursor);
148
149    procedure Splice
150      (Container : in out List;
151       Before    : Cursor;
152       Position  : Cursor);
153
154    function First (Container : List) return Cursor;
155
156    function First_Element (Container : List) return Element_Type;
157
158    function Last (Container : List) return Cursor;
159
160    function Last_Element (Container : List) return Element_Type;
161
162    function Next (Position : Cursor) return Cursor;
163
164    procedure Next (Position : in out Cursor);
165
166    function Previous (Position : Cursor) return Cursor;
167
168    procedure Previous (Position : in out Cursor);
169
170    function Find
171      (Container : List;
172       Item      : Element_Type;
173       Position  : Cursor := No_Element) return Cursor;
174
175    function Reverse_Find
176      (Container : List;
177       Item      : Element_Type;
178       Position  : Cursor := No_Element) return Cursor;
179
180    function Contains
181      (Container : List;
182       Item      : Element_Type) return Boolean;
183
184    function Has_Element (Position : Cursor) return Boolean;
185
186    procedure Iterate
187      (Container : List;
188       Process   : not null access procedure (Position : Cursor));
189
190    procedure Reverse_Iterate
191      (Container : List;
192       Process   : not null access procedure (Position : Cursor));
193
194    generic
195       with function "<" (Left, Right : Element_Type) return Boolean is <>;
196    package Generic_Sorting is
197
198       function Is_Sorted (Container : List) return Boolean;
199
200       procedure Sort (Container : in out List);
201
202       procedure Merge (Target, Source : in out List);
203
204    end Generic_Sorting;
205
206 private
207    type Node_Type;
208    type Node_Access is access Node_Type;
209
210    type Node_Type is
211       limited record
212          Element : Element_Type;
213          Next    : Node_Access;
214          Prev    : Node_Access;
215       end record;
216
217    use Ada.Finalization;
218
219    type List is
220      new Controlled with record
221         First  : Node_Access;
222         Last   : Node_Access;
223         Length : Count_Type := 0;
224         Busy   : Natural := 0;
225         Lock   : Natural := 0;
226      end record;
227
228    procedure Adjust (Container : in out List);
229
230    procedure Finalize (Container : in out List) renames Clear;
231
232    use Ada.Streams;
233
234    procedure Read
235      (Stream : not null access Root_Stream_Type'Class;
236       Item   : out List);
237
238    for List'Read use Read;
239
240    procedure Write
241      (Stream : not null access Root_Stream_Type'Class;
242       Item   : List);
243
244    for List'Write use Write;
245
246    Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
247
248    type List_Access is access constant List;
249    for List_Access'Storage_Size use 0;
250
251    type Cursor is
252       record
253          Container : List_Access;
254          Node      : Node_Access;
255       end record;
256
257    procedure Read
258      (Stream : not null access Root_Stream_Type'Class;
259       Item   : out Cursor);
260
261    for Cursor'Read use Read;
262
263    procedure Write
264      (Stream : not null access Root_Stream_Type'Class;
265       Item   : Cursor);
266
267    for Cursor'Write use Write;
268
269    No_Element : constant Cursor := Cursor'(null, null);
270
271 end Ada.Containers.Doubly_Linked_Lists;