OSDN Git Service

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