OSDN Git Service

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