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 type Constant_Reference_Type
92 (Element : not null access constant Element_Type) is private
94 Implicit_Dereference => Element;
97 (Stream : not null access Root_Stream_Type'Class;
98 Item : Constant_Reference_Type);
100 for Constant_Reference_Type'Write use Write;
103 (Stream : not null access Root_Stream_Type'Class;
104 Item : out Constant_Reference_Type);
106 for Constant_Reference_Type'Read use Read;
109 (Element : not null access Element_Type) is private
111 Implicit_Dereference => Element;
114 (Stream : not null access Root_Stream_Type'Class;
115 Item : Reference_Type);
117 for Reference_Type'Write use Write;
120 (Stream : not null access Root_Stream_Type'Class;
121 Item : out Reference_Type);
123 for Reference_Type'Read use Read;
125 function Constant_Reference
126 (Container : aliased List;
127 Position : Cursor) return Constant_Reference_Type;
130 (Container : aliased in out List;
131 Position : Cursor) return Reference_Type;
133 procedure Assign (Target : in out List; Source : List);
135 function Copy (Source : List; Capacity : Count_Type := 0) return List;
138 (Target : in out List;
139 Source : in out List);
142 (Container : in out List;
144 New_Item : Element_Type;
145 Count : Count_Type := 1);
148 (Container : in out List;
150 New_Item : Element_Type;
151 Position : out Cursor;
152 Count : Count_Type := 1);
155 (Container : in out List;
157 Position : out Cursor;
158 Count : Count_Type := 1);
161 (Container : in out List;
162 New_Item : Element_Type;
163 Count : Count_Type := 1);
166 (Container : in out List;
167 New_Item : Element_Type;
168 Count : Count_Type := 1);
171 (Container : in out List;
172 Position : in out Cursor;
173 Count : Count_Type := 1);
175 procedure Delete_First
176 (Container : in out List;
177 Count : Count_Type := 1);
179 procedure Delete_Last
180 (Container : in out List;
181 Count : Count_Type := 1);
183 procedure Reverse_Elements (Container : in out List);
187 return List_Iterator_Interfaces.Reversible_Iterator'class;
192 return List_Iterator_Interfaces.Reversible_Iterator'class;
195 (Container : in out List;
199 (Container : in out List;
203 (Target : in out List;
205 Source : in out List);
208 (Target : in out List;
210 Source : in out List;
211 Position : in out Cursor);
214 (Container : in out List;
218 function First (Container : List) return Cursor;
220 function First_Element (Container : List) return Element_Type;
222 function Last (Container : List) return Cursor;
224 function Last_Element (Container : List) return Element_Type;
226 function Next (Position : Cursor) return Cursor;
228 procedure Next (Position : in out Cursor);
230 function Previous (Position : Cursor) return Cursor;
232 procedure Previous (Position : in out Cursor);
237 Position : Cursor := No_Element) return Cursor;
239 function Reverse_Find
242 Position : Cursor := No_Element) return Cursor;
246 Item : Element_Type) return Boolean;
250 Process : not null access procedure (Position : Cursor));
252 procedure Reverse_Iterate
254 Process : not null access procedure (Position : Cursor));
257 with function "<" (Left, Right : Element_Type) return Boolean is <>;
258 package Generic_Sorting is
260 function Is_Sorted (Container : List) return Boolean;
262 procedure Sort (Container : in out List);
264 procedure Merge (Target, Source : in out List);
270 pragma Inline (Next);
271 pragma Inline (Previous);
273 type Node_Type is record
274 Prev : Count_Type'Base;
276 Element : aliased 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;