1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.BOUNDED_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.Streams; use Ada.Streams;
35 with Ada.Iterator_Interfaces;
38 type Element_Type is private;
40 with function "=" (Left, Right : Element_Type)
43 package Ada.Containers.Bounded_Doubly_Linked_Lists is
47 type List (Capacity : Count_Type) is tagged private with
48 Constant_Indexing => Constant_Reference,
49 Variable_Indexing => Reference,
50 Default_Iterator => Iterate,
51 Iterator_Element => Element_Type;
53 pragma Preelaborable_Initialization (List);
55 type Cursor is private;
56 pragma Preelaborable_Initialization (Cursor);
58 Empty_List : constant List;
60 No_Element : constant Cursor;
62 function Has_Element (Position : Cursor) return Boolean;
64 package List_Iterator_Interfaces is new
65 Ada.Iterator_Interfaces (Cursor, Has_Element);
67 function "=" (Left, Right : List) return Boolean;
69 function Length (Container : List) return Count_Type;
71 function Is_Empty (Container : List) return Boolean;
73 procedure Clear (Container : in out List);
75 function Element (Position : Cursor) return Element_Type;
77 procedure Replace_Element
78 (Container : in out List;
80 New_Item : Element_Type);
82 procedure Query_Element
84 Process : not null access procedure (Element : Element_Type));
86 procedure Update_Element
87 (Container : in out List;
89 Process : not null access procedure (Element : in out Element_Type));
91 procedure Assign (Target : in out List; Source : List);
93 function Copy (Source : List; Capacity : Count_Type := 0) return List;
96 (Target : in out List;
97 Source : in out List);
100 (Container : in out List;
102 New_Item : Element_Type;
103 Count : Count_Type := 1);
106 (Container : in out List;
108 New_Item : Element_Type;
109 Position : out Cursor;
110 Count : Count_Type := 1);
113 (Container : in out List;
115 Position : out Cursor;
116 Count : Count_Type := 1);
119 (Container : in out List;
120 New_Item : Element_Type;
121 Count : Count_Type := 1);
124 (Container : in out List;
125 New_Item : Element_Type;
126 Count : Count_Type := 1);
129 (Container : in out List;
130 Position : in out Cursor;
131 Count : Count_Type := 1);
133 procedure Delete_First
134 (Container : in out List;
135 Count : Count_Type := 1);
137 procedure Delete_Last
138 (Container : in out List;
139 Count : Count_Type := 1);
141 procedure Reverse_Elements (Container : in out List);
145 return List_Iterator_Interfaces.Reversible_Iterator'class;
150 return List_Iterator_Interfaces.Reversible_Iterator'class;
153 (Container : in out List;
157 (Container : in out List;
161 (Target : in out List;
163 Source : in out List);
166 (Target : in out List;
168 Source : in out List;
169 Position : in out Cursor);
172 (Container : in out List;
176 function First (Container : List) return Cursor;
178 function First_Element (Container : List) return Element_Type;
180 function Last (Container : List) return Cursor;
182 function Last_Element (Container : List) return Element_Type;
184 function Next (Position : Cursor) return Cursor;
186 procedure Next (Position : in out Cursor);
188 function Previous (Position : Cursor) return Cursor;
190 procedure Previous (Position : in out Cursor);
195 Position : Cursor := No_Element) return Cursor;
197 function Reverse_Find
200 Position : Cursor := No_Element) return Cursor;
204 Item : Element_Type) return Boolean;
208 Process : not null access procedure (Position : Cursor));
210 procedure Reverse_Iterate
212 Process : not null access procedure (Position : Cursor));
215 with function "<" (Left, Right : Element_Type) return Boolean is <>;
216 package Generic_Sorting is
218 function Is_Sorted (Container : List) return Boolean;
220 procedure Sort (Container : in out List);
222 procedure Merge (Target, Source : in out List);
226 type Constant_Reference_Type
227 (Element : not null access constant Element_Type) is private
229 Implicit_Dereference => Element;
232 (Stream : not null access Root_Stream_Type'Class;
233 Item : Constant_Reference_Type);
235 for Constant_Reference_Type'Write use Write;
238 (Stream : not null access Root_Stream_Type'Class;
239 Item : out Constant_Reference_Type);
241 for Constant_Reference_Type'Read use Read;
243 type Reference_Type (Element : not null access Element_Type) is
246 Implicit_Dereference => Element;
249 (Stream : not null access Root_Stream_Type'Class;
250 Item : Reference_Type);
252 for Reference_Type'Write use Write;
255 (Stream : not null access Root_Stream_Type'Class;
256 Item : out Reference_Type);
258 for Reference_Type'Read use Read;
260 function Constant_Reference
261 (Container : List; Position : Cursor) -- SHOULD BE ALIASED
262 return Constant_Reference_Type;
265 (Container : List; Position : Cursor) -- SHOULD BE ALIASED
266 return Reference_Type;
270 pragma Inline (Next);
271 pragma Inline (Previous);
273 type Node_Type is record
274 Prev : Count_Type'Base;
276 Element : Element_Type;
279 type Node_Array is array (Count_Type range <>) of Node_Type;
281 type List (Capacity : Count_Type) is tagged record
282 Nodes : Node_Array (1 .. Capacity) := (others => <>);
283 Free : Count_Type'Base := -1;
284 First : Count_Type := 0;
285 Last : Count_Type := 0;
286 Length : Count_Type := 0;
292 (Stream : not null access Root_Stream_Type'Class;
295 for List'Read use Read;
298 (Stream : not null access Root_Stream_Type'Class;
301 for List'Write use Write;
303 type List_Access is access all List;
304 for List_Access'Storage_Size use 0;
308 Container : List_Access;
309 Node : Count_Type := 0;
313 (Stream : not null access Root_Stream_Type'Class;
316 for Cursor'Read use Read;
319 (Stream : not null access Root_Stream_Type'Class;
322 for Cursor'Write use Write;
324 type Constant_Reference_Type
325 (Element : not null access constant Element_Type) is null record;
328 (Element : not null access Element_Type) is null record;
330 Empty_List : constant List := (Capacity => 0, others => <>);
332 No_Element : constant Cursor := Cursor'(null, 0);
334 end Ada.Containers.Bounded_Doubly_Linked_Lists;