1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
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 --
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 private with Ada.Finalization;
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
40 type Element_Type is private;
42 with function "=" (Left, Right : Element_Type)
45 package Ada.Containers.Doubly_Linked_Lists is
49 type List is tagged private
51 Constant_Indexing => Constant_Reference,
52 Variable_Indexing => Reference,
53 Default_Iterator => Iterate,
54 Iterator_Element => Element_Type;
56 pragma Preelaborable_Initialization (List);
58 type Cursor is private;
59 pragma Preelaborable_Initialization (Cursor);
61 Empty_List : constant List;
63 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;
113 Position : out Cursor;
114 Count : Count_Type := 1);
117 (Container : in out List;
118 New_Item : Element_Type;
119 Count : Count_Type := 1);
122 (Container : in out List;
123 New_Item : Element_Type;
124 Count : Count_Type := 1);
127 (Container : in out List;
128 Position : in out Cursor;
129 Count : Count_Type := 1);
131 procedure Delete_First
132 (Container : in out List;
133 Count : Count_Type := 1);
135 procedure Delete_Last
136 (Container : in out List;
137 Count : Count_Type := 1);
139 procedure Reverse_Elements (Container : in out List);
141 function Iterate (Container : List)
142 return List_Iterator_Interfaces.Reversible_Iterator'class;
144 function Iterate (Container : List; Start : Cursor)
145 return List_Iterator_Interfaces.Reversible_Iterator'class;
148 (Container : in out List;
152 (Container : in out List;
156 (Target : in out List;
158 Source : in out List);
161 (Target : in out List;
163 Source : in out List;
164 Position : in out Cursor);
167 (Container : in out List;
171 function First (Container : List) return Cursor;
173 function First_Element (Container : List) return Element_Type;
175 function Last (Container : List) return Cursor;
177 function Last_Element (Container : List) return Element_Type;
179 function Next (Position : Cursor) return Cursor;
181 procedure Next (Position : in out Cursor);
183 function Previous (Position : Cursor) return Cursor;
185 procedure Previous (Position : in out Cursor);
190 Position : Cursor := No_Element) return Cursor;
192 function Reverse_Find
195 Position : Cursor := No_Element) return Cursor;
199 Item : Element_Type) return Boolean;
203 Process : not null access procedure (Position : Cursor));
205 procedure Reverse_Iterate
207 Process : not null access procedure (Position : Cursor));
210 with function "<" (Left, Right : Element_Type) return Boolean is <>;
211 package Generic_Sorting is
213 function Is_Sorted (Container : List) return Boolean;
215 procedure Sort (Container : in out List);
217 procedure Merge (Target, Source : in out List);
221 type Constant_Reference_Type
222 (Element : not null access constant Element_Type) is private
224 Implicit_Dereference => Element;
227 (Stream : not null access Root_Stream_Type'Class;
228 Item : Constant_Reference_Type);
230 for Constant_Reference_Type'Write use Write;
233 (Stream : not null access Root_Stream_Type'Class;
234 Item : out Constant_Reference_Type);
236 for Constant_Reference_Type'Read use Read;
238 type Reference_Type (Element : not null access Element_Type) is
241 Implicit_Dereference => Element;
244 (Stream : not null access Root_Stream_Type'Class;
245 Item : Reference_Type);
247 for Reference_Type'Write use Write;
250 (Stream : not null access Root_Stream_Type'Class;
251 Item : out Reference_Type);
253 for Reference_Type'Read use Read;
255 function Constant_Reference
256 (Container : List; Position : Cursor) -- SHOULD BE ALIASED
257 return Constant_Reference_Type;
260 (Container : List; Position : Cursor) -- SHOULD BE ALIASED
261 return Reference_Type;
265 pragma Inline (Next);
266 pragma Inline (Previous);
269 type Node_Access is access Node_Type;
273 Element : aliased Element_Type;
278 use Ada.Finalization;
281 new Controlled with record
284 Length : Count_Type := 0;
289 overriding procedure Adjust (Container : in out List);
291 overriding procedure Finalize (Container : in out List) renames Clear;
294 (Stream : not null access Root_Stream_Type'Class;
297 for List'Read use Read;
300 (Stream : not null access Root_Stream_Type'Class;
303 for List'Write use Write;
305 type List_Access is access constant List;
306 for List_Access'Storage_Size use 0;
310 Container : List_Access;
315 (Stream : not null access Root_Stream_Type'Class;
318 for Cursor'Read use Read;
321 (Stream : not null access Root_Stream_Type'Class;
324 for Cursor'Write use Write;
326 type Constant_Reference_Type
327 (Element : not null access constant Element_Type) is null record;
330 (Element : not null access Element_Type) is null record;
332 Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
334 No_Element : constant Cursor := Cursor'(null, null);
336 end Ada.Containers.Doubly_Linked_Lists;