1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_DOUBLY_LINKED_LISTS --
9 -- Copyright (C) 2004-2011, Free Software Foundation, Inc. --
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. --
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. --
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. --
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/>. --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada.Iterator_Interfaces;
35 with Ada.Streams; use Ada.Streams;
37 private with Ada.Finalization;
40 type Element_Type (<>) is private;
42 with function "=" (Left, Right : Element_Type)
45 package Ada.Containers.Indefinite_Doubly_Linked_Lists is
49 type List 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;
82 New_Item : Element_Type);
84 procedure Query_Element
86 Process : not null access procedure (Element : Element_Type));
88 procedure Update_Element
89 (Container : in out List;
91 Process : not null access procedure (Element : in out Element_Type));
94 (Target : in out List;
95 Source : in out List);
98 (Container : in out List;
100 New_Item : Element_Type;
101 Count : Count_Type := 1);
104 (Container : in out List;
106 New_Item : Element_Type;
107 Position : out Cursor;
108 Count : Count_Type := 1);
111 (Container : in out List;
112 New_Item : Element_Type;
113 Count : Count_Type := 1);
116 (Container : in out List;
117 New_Item : Element_Type;
118 Count : Count_Type := 1);
121 (Container : in out List;
122 Position : in out Cursor;
123 Count : Count_Type := 1);
125 procedure Delete_First
126 (Container : in out List;
127 Count : Count_Type := 1);
129 procedure Delete_Last
130 (Container : in out List;
131 Count : Count_Type := 1);
133 procedure Reverse_Elements (Container : in out List);
135 procedure Swap (Container : in out List; I, J : Cursor);
137 procedure Swap_Links (Container : in out List; I, J : Cursor);
140 (Target : in out List;
142 Source : in out List);
145 (Target : in out List;
147 Source : in out List;
148 Position : in out Cursor);
151 (Container : in out List;
155 function First (Container : List) return Cursor;
157 function First_Element (Container : List) return Element_Type;
159 function Last (Container : List) return Cursor;
161 function Last_Element (Container : List) return Element_Type;
163 function Next (Position : Cursor) return Cursor;
165 procedure Next (Position : in out Cursor);
167 function Previous (Position : Cursor) return Cursor;
169 procedure Previous (Position : in out Cursor);
174 Position : Cursor := No_Element) return Cursor;
176 function Reverse_Find
179 Position : Cursor := No_Element) return Cursor;
183 Item : Element_Type) return Boolean;
187 Process : not null access procedure (Position : Cursor));
189 procedure Reverse_Iterate
191 Process : not null access procedure (Position : Cursor));
195 return List_Iterator_Interfaces.Reversible_Iterator'class;
200 return List_Iterator_Interfaces.Reversible_Iterator'class;
202 type Constant_Reference_Type
203 (Element : not null access constant Element_Type) is private
205 Implicit_Dereference => Element;
208 (Stream : not null access Root_Stream_Type'Class;
209 Item : Constant_Reference_Type);
211 for Constant_Reference_Type'Write use Write;
214 (Stream : not null access Root_Stream_Type'Class;
215 Item : out Constant_Reference_Type);
217 for Constant_Reference_Type'Read use Read;
219 type Reference_Type (Element : not null access Element_Type) is
222 Implicit_Dereference => Element;
225 (Stream : not null access Root_Stream_Type'Class;
226 Item : Reference_Type);
228 for Reference_Type'Write use Write;
231 (Stream : not null access Root_Stream_Type'Class;
232 Item : out Reference_Type);
234 for Reference_Type'Read use Read;
236 function Constant_Reference
238 Position : Cursor) -- SHOULD BE ALIASED ???
239 return Constant_Reference_Type;
243 Position : Cursor) -- SHOULD BE ALIASED ???
244 return Reference_Type;
247 with function "<" (Left, Right : Element_Type) return Boolean is <>;
248 package Generic_Sorting is
250 function Is_Sorted (Container : List) return Boolean;
252 procedure Sort (Container : in out List);
254 procedure Merge (Target, Source : in out List);
260 pragma Inline (Next);
261 pragma Inline (Previous);
264 type Node_Access is access Node_Type;
266 type Element_Access is access Element_Type;
270 Element : Element_Access;
275 use Ada.Finalization;
278 new Controlled with record
281 Length : Count_Type := 0;
286 type Constant_Reference_Type
287 (Element : not null access constant Element_Type) is null record;
290 (Element : not null access Element_Type) is null record;
292 overriding procedure Adjust (Container : in out List);
294 overriding procedure Finalize (Container : in out List) renames Clear;
297 (Stream : not null access Root_Stream_Type'Class;
300 for List'Read use Read;
303 (Stream : not null access Root_Stream_Type'Class;
306 for List'Write use Write;
308 type List_Access is access constant List;
309 for List_Access'Storage_Size use 0;
313 Container : List_Access;
318 (Stream : not null access Root_Stream_Type'Class;
321 for Cursor'Read use Read;
324 (Stream : not null access Root_Stream_Type'Class;
327 for Cursor'Write use Write;
329 Empty_List : constant List := List'(Controlled with null, null, 0, 0, 0);
331 No_Element : constant Cursor := Cursor'(null, null);
333 end Ada.Containers.Indefinite_Doubly_Linked_Lists;