Daily bump.
[official-gcc.git] / gcc / ada / a-cbdlli.ads
blob603cb35b7a0f2e100f765215d60b316cc7f4c49c
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-2015, 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 ------------------------------------------------------------------------------
34 with Ada.Iterator_Interfaces;
36 private with Ada.Streams;
37 private with Ada.Finalization;
39 generic
40 type Element_Type is private;
42 with function "=" (Left, Right : Element_Type)
43 return Boolean is <>;
45 package Ada.Containers.Bounded_Doubly_Linked_Lists is
46 pragma Pure;
47 pragma Remote_Types;
49 type List (Capacity : Count_Type) is tagged private with
50 Constant_Indexing => Constant_Reference,
51 Variable_Indexing => Reference,
52 Default_Iterator => Iterate,
53 Iterator_Element => Element_Type;
55 pragma Preelaborable_Initialization (List);
57 type Cursor is private;
58 pragma Preelaborable_Initialization (Cursor);
60 Empty_List : constant List;
62 No_Element : constant Cursor;
64 function Has_Element (Position : Cursor) return Boolean;
66 package List_Iterator_Interfaces is new
67 Ada.Iterator_Interfaces (Cursor, Has_Element);
69 function "=" (Left, Right : List) return Boolean;
71 function Length (Container : List) return Count_Type;
73 function Is_Empty (Container : List) return Boolean;
75 procedure Clear (Container : in out List);
77 function Element (Position : Cursor) return Element_Type;
79 procedure Replace_Element
80 (Container : in out List;
81 Position : Cursor;
82 New_Item : Element_Type);
84 procedure Query_Element
85 (Position : Cursor;
86 Process : not null access procedure (Element : Element_Type));
88 procedure Update_Element
89 (Container : in out List;
90 Position : Cursor;
91 Process : not null access procedure (Element : in out Element_Type));
93 type Constant_Reference_Type
94 (Element : not null access constant Element_Type) is private
95 with
96 Implicit_Dereference => Element;
98 type Reference_Type
99 (Element : not null access Element_Type) is private
100 with
101 Implicit_Dereference => Element;
103 function Constant_Reference
104 (Container : aliased List;
105 Position : Cursor) return Constant_Reference_Type;
107 function Reference
108 (Container : aliased in out List;
109 Position : Cursor) return Reference_Type;
111 procedure Assign (Target : in out List; Source : List);
113 function Copy (Source : List; Capacity : Count_Type := 0) return List;
115 procedure Move
116 (Target : in out List;
117 Source : in out List);
119 procedure Insert
120 (Container : in out List;
121 Before : Cursor;
122 New_Item : Element_Type;
123 Count : Count_Type := 1);
125 procedure Insert
126 (Container : in out List;
127 Before : Cursor;
128 New_Item : Element_Type;
129 Position : out Cursor;
130 Count : Count_Type := 1);
132 procedure Insert
133 (Container : in out List;
134 Before : Cursor;
135 Position : out Cursor;
136 Count : Count_Type := 1);
138 procedure Prepend
139 (Container : in out List;
140 New_Item : Element_Type;
141 Count : Count_Type := 1);
143 procedure Append
144 (Container : in out List;
145 New_Item : Element_Type;
146 Count : Count_Type := 1);
148 procedure Delete
149 (Container : in out List;
150 Position : in out Cursor;
151 Count : Count_Type := 1);
153 procedure Delete_First
154 (Container : in out List;
155 Count : Count_Type := 1);
157 procedure Delete_Last
158 (Container : in out List;
159 Count : Count_Type := 1);
161 procedure Reverse_Elements (Container : in out List);
163 function Iterate
164 (Container : List)
165 return List_Iterator_Interfaces.Reversible_Iterator'class;
167 function Iterate
168 (Container : List;
169 Start : Cursor)
170 return List_Iterator_Interfaces.Reversible_Iterator'class;
172 procedure Swap
173 (Container : in out List;
174 I, J : Cursor);
176 procedure Swap_Links
177 (Container : in out List;
178 I, J : Cursor);
180 procedure Splice
181 (Target : in out List;
182 Before : Cursor;
183 Source : in out List);
185 procedure Splice
186 (Target : in out List;
187 Before : Cursor;
188 Source : in out List;
189 Position : in out Cursor);
191 procedure Splice
192 (Container : in out List;
193 Before : Cursor;
194 Position : Cursor);
196 function First (Container : List) return Cursor;
198 function First_Element (Container : List) return Element_Type;
200 function Last (Container : List) return Cursor;
202 function Last_Element (Container : List) return Element_Type;
204 function Next (Position : Cursor) return Cursor;
206 procedure Next (Position : in out Cursor);
208 function Previous (Position : Cursor) return Cursor;
210 procedure Previous (Position : in out Cursor);
212 function Find
213 (Container : List;
214 Item : Element_Type;
215 Position : Cursor := No_Element) return Cursor;
217 function Reverse_Find
218 (Container : List;
219 Item : Element_Type;
220 Position : Cursor := No_Element) return Cursor;
222 function Contains
223 (Container : List;
224 Item : Element_Type) return Boolean;
226 procedure Iterate
227 (Container : List;
228 Process : not null access procedure (Position : Cursor));
230 procedure Reverse_Iterate
231 (Container : List;
232 Process : not null access procedure (Position : Cursor));
234 generic
235 with function "<" (Left, Right : Element_Type) return Boolean is <>;
236 package Generic_Sorting is
238 function Is_Sorted (Container : List) return Boolean;
240 procedure Sort (Container : in out List);
242 procedure Merge (Target, Source : in out List);
244 end Generic_Sorting;
246 private
248 pragma Inline (Next);
249 pragma Inline (Previous);
251 use Ada.Streams;
252 use Ada.Finalization;
254 type Node_Type is record
255 Prev : Count_Type'Base;
256 Next : Count_Type;
257 Element : aliased Element_Type;
258 end record;
260 type Node_Array is array (Count_Type range <>) of Node_Type;
262 type List (Capacity : Count_Type) is tagged record
263 Nodes : Node_Array (1 .. Capacity) := (others => <>);
264 Free : Count_Type'Base := -1;
265 First : Count_Type := 0;
266 Last : Count_Type := 0;
267 Length : Count_Type := 0;
268 Busy : Natural := 0;
269 Lock : Natural := 0;
270 end record;
272 procedure Read
273 (Stream : not null access Root_Stream_Type'Class;
274 Item : out List);
276 for List'Read use Read;
278 procedure Write
279 (Stream : not null access Root_Stream_Type'Class;
280 Item : List);
282 for List'Write use Write;
284 type List_Access is access all List;
285 for List_Access'Storage_Size use 0;
287 type Cursor is record
288 Container : List_Access;
289 Node : Count_Type := 0;
290 end record;
292 procedure Read
293 (Stream : not null access Root_Stream_Type'Class;
294 Item : out Cursor);
296 for Cursor'Read use Read;
298 procedure Write
299 (Stream : not null access Root_Stream_Type'Class;
300 Item : Cursor);
302 for Cursor'Write use Write;
304 type Reference_Control_Type is new Controlled with record
305 Container : List_Access;
306 end record;
308 overriding procedure Adjust (Control : in out Reference_Control_Type);
309 pragma Inline (Adjust);
311 overriding procedure Finalize (Control : in out Reference_Control_Type);
312 pragma Inline (Finalize);
314 type Constant_Reference_Type
315 (Element : not null access constant Element_Type) is
316 record
317 Control : Reference_Control_Type :=
318 raise Program_Error with "uninitialized reference";
319 -- The RM says, "The default initialization of an object of
320 -- type Constant_Reference_Type or Reference_Type propagates
321 -- Program_Error."
322 end record;
324 procedure Read
325 (Stream : not null access Root_Stream_Type'Class;
326 Item : out Constant_Reference_Type);
328 for Constant_Reference_Type'Read use Read;
330 procedure Write
331 (Stream : not null access Root_Stream_Type'Class;
332 Item : Constant_Reference_Type);
334 for Constant_Reference_Type'Write use Write;
336 type Reference_Type (Element : not null access Element_Type) is record
337 Control : Reference_Control_Type :=
338 raise Program_Error with "uninitialized reference";
339 -- The RM says, "The default initialization of an object of
340 -- type Constant_Reference_Type or Reference_Type propagates
341 -- Program_Error."
342 end record;
344 procedure Write
345 (Stream : not null access Root_Stream_Type'Class;
346 Item : Reference_Type);
348 for Reference_Type'Write use Write;
350 procedure Read
351 (Stream : not null access Root_Stream_Type'Class;
352 Item : out Reference_Type);
354 for Reference_Type'Read use Read;
356 Empty_List : constant List := (Capacity => 0, others => <>);
358 No_Element : constant Cursor := Cursor'(null, 0);
360 type Iterator is new Limited_Controlled and
361 List_Iterator_Interfaces.Reversible_Iterator with
362 record
363 Container : List_Access;
364 Node : Count_Type;
365 end record;
367 overriding procedure Finalize (Object : in out Iterator);
369 overriding function First (Object : Iterator) return Cursor;
370 overriding function Last (Object : Iterator) return Cursor;
372 overriding function Next
373 (Object : Iterator;
374 Position : Cursor) return Cursor;
376 overriding function Previous
377 (Object : Iterator;
378 Position : Cursor) return Cursor;
380 end Ada.Containers.Bounded_Doubly_Linked_Lists;