1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_DOUBLY_LINKED_LISTS --
9 -- Copyright (C) 2004-2012, 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;
36 private with Ada.Finalization;
37 private with Ada.Streams;
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));
93 type Constant_Reference_Type
94 (Element : not null access constant Element_Type) is private
96 Implicit_Dereference => Element;
99 (Element : not null access Element_Type) is private
101 Implicit_Dereference => Element;
103 function Constant_Reference
104 (Container : aliased List;
105 Position : Cursor) return Constant_Reference_Type;
106 pragma Inline (Constant_Reference);
109 (Container : aliased in out List;
110 Position : Cursor) return Reference_Type;
111 pragma Inline (Reference);
113 procedure Assign (Target : in out List; Source : List);
115 function Copy (Source : List) return List;
118 (Target : in out List;
119 Source : in out List);
122 (Container : in out List;
124 New_Item : Element_Type;
125 Count : Count_Type := 1);
128 (Container : in out List;
130 New_Item : Element_Type;
131 Position : out Cursor;
132 Count : Count_Type := 1);
135 (Container : in out List;
136 New_Item : Element_Type;
137 Count : Count_Type := 1);
140 (Container : in out List;
141 New_Item : Element_Type;
142 Count : Count_Type := 1);
145 (Container : in out List;
146 Position : in out Cursor;
147 Count : Count_Type := 1);
149 procedure Delete_First
150 (Container : in out List;
151 Count : Count_Type := 1);
153 procedure Delete_Last
154 (Container : in out List;
155 Count : Count_Type := 1);
157 procedure Reverse_Elements (Container : in out List);
159 procedure Swap (Container : in out List; I, J : Cursor);
161 procedure Swap_Links (Container : in out List; I, J : Cursor);
164 (Target : in out List;
166 Source : in out List);
169 (Target : in out List;
171 Source : in out List;
172 Position : in out Cursor);
175 (Container : in out List;
179 function First (Container : List) return Cursor;
181 function First_Element (Container : List) return Element_Type;
183 function Last (Container : List) return Cursor;
185 function Last_Element (Container : List) return Element_Type;
187 function Next (Position : Cursor) return Cursor;
189 procedure Next (Position : in out Cursor);
191 function Previous (Position : Cursor) return Cursor;
193 procedure Previous (Position : in out Cursor);
198 Position : Cursor := No_Element) return Cursor;
200 function Reverse_Find
203 Position : Cursor := No_Element) return Cursor;
207 Item : Element_Type) return Boolean;
211 Process : not null access procedure (Position : Cursor));
213 procedure Reverse_Iterate
215 Process : not null access procedure (Position : Cursor));
219 return List_Iterator_Interfaces.Reversible_Iterator'class;
224 return List_Iterator_Interfaces.Reversible_Iterator'class;
227 with function "<" (Left, Right : Element_Type) return Boolean is <>;
228 package Generic_Sorting is
230 function Is_Sorted (Container : List) return Boolean;
232 procedure Sort (Container : in out List);
234 procedure Merge (Target, Source : in out List);
240 pragma Inline (Next);
241 pragma Inline (Previous);
244 type Node_Access is access Node_Type;
246 type Element_Access is access Element_Type;
250 Element : Element_Access;
255 use Ada.Finalization;
259 new Controlled with record
262 Length : Count_Type := 0;
267 overriding procedure Adjust (Container : in out List);
269 overriding procedure Finalize (Container : in out List) renames Clear;
272 (Stream : not null access Root_Stream_Type'Class;
275 for List'Read use Read;
278 (Stream : not null access Root_Stream_Type'Class;
281 for List'Write use Write;
283 type List_Access is access all List;
284 for List_Access'Storage_Size use 0;
288 Container : List_Access;
293 (Stream : not null access Root_Stream_Type'Class;
296 for Cursor'Read use Read;
299 (Stream : not null access Root_Stream_Type'Class;
302 for Cursor'Write use Write;
304 type Reference_Control_Type is
305 new Controlled with record
306 Container : List_Access;
309 overriding procedure Adjust (Control : in out Reference_Control_Type);
310 pragma Inline (Adjust);
312 overriding procedure Finalize (Control : in out Reference_Control_Type);
313 pragma Inline (Finalize);
315 type Constant_Reference_Type
316 (Element : not null access constant Element_Type) is
318 Control : Reference_Control_Type;
322 (Stream : not null access Root_Stream_Type'Class;
323 Item : Constant_Reference_Type);
325 for Constant_Reference_Type'Write use Write;
328 (Stream : not null access Root_Stream_Type'Class;
329 Item : out Constant_Reference_Type);
331 for Constant_Reference_Type'Read use Read;
334 (Element : not null access Element_Type) is
336 Control : Reference_Control_Type;
340 (Stream : not null access Root_Stream_Type'Class;
341 Item : Reference_Type);
343 for Reference_Type'Write use Write;
346 (Stream : not null access Root_Stream_Type'Class;
347 Item : out Reference_Type);
349 for Reference_Type'Read use Read;
351 Empty_List : constant List := List'(Controlled with null, null, 0, 0, 0);
353 No_Element : constant Cursor := Cursor'(null, null);
355 end Ada.Containers.Indefinite_Doubly_Linked_Lists;