1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.BOUNDED_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.Streams;
39 type Element_Type is private;
41 with function "=" (Left, Right : Element_Type)
44 package Ada.Containers.Bounded_Doubly_Linked_Lists is
48 type List (Capacity : Count_Type) is tagged private with
49 Constant_Indexing => Constant_Reference,
50 Variable_Indexing => Reference,
51 Default_Iterator => Iterate,
52 Iterator_Element => Element_Type;
54 pragma Preelaborable_Initialization (List);
56 type Cursor is private;
57 pragma Preelaborable_Initialization (Cursor);
59 Empty_List : constant List;
61 No_Element : constant Cursor;
63 function Has_Element (Position : Cursor) return Boolean;
65 package List_Iterator_Interfaces is new
66 Ada.Iterator_Interfaces (Cursor, Has_Element);
68 function "=" (Left, Right : List) return Boolean;
70 function Length (Container : List) return Count_Type;
72 function Is_Empty (Container : List) return Boolean;
74 procedure Clear (Container : in out List);
76 function Element (Position : Cursor) return Element_Type;
78 procedure Replace_Element
79 (Container : in out List;
81 New_Item : Element_Type);
83 procedure Query_Element
85 Process : not null access procedure (Element : Element_Type));
87 procedure Update_Element
88 (Container : in out List;
90 Process : not null access procedure (Element : in out Element_Type));
92 type Constant_Reference_Type
93 (Element : not null access constant Element_Type) is private
95 Implicit_Dereference => Element;
98 (Element : not null access Element_Type) is private
100 Implicit_Dereference => Element;
102 function Constant_Reference
103 (Container : aliased List;
104 Position : Cursor) return Constant_Reference_Type;
107 (Container : aliased in out List;
108 Position : Cursor) return Reference_Type;
110 procedure Assign (Target : in out List; Source : List);
112 function Copy (Source : List; Capacity : Count_Type := 0) return List;
115 (Target : in out List;
116 Source : in out List);
119 (Container : in out List;
121 New_Item : Element_Type;
122 Count : Count_Type := 1);
125 (Container : in out List;
127 New_Item : Element_Type;
128 Position : out Cursor;
129 Count : Count_Type := 1);
132 (Container : in out List;
134 Position : out Cursor;
135 Count : Count_Type := 1);
138 (Container : in out List;
139 New_Item : Element_Type;
140 Count : Count_Type := 1);
143 (Container : in out List;
144 New_Item : Element_Type;
145 Count : Count_Type := 1);
148 (Container : in out List;
149 Position : in out Cursor;
150 Count : Count_Type := 1);
152 procedure Delete_First
153 (Container : in out List;
154 Count : Count_Type := 1);
156 procedure Delete_Last
157 (Container : in out List;
158 Count : Count_Type := 1);
160 procedure Reverse_Elements (Container : in out List);
164 return List_Iterator_Interfaces.Reversible_Iterator'class;
169 return List_Iterator_Interfaces.Reversible_Iterator'class;
172 (Container : in out List;
176 (Container : in out List;
180 (Target : in out List;
182 Source : in out List);
185 (Target : in out List;
187 Source : in out List;
188 Position : in out Cursor);
191 (Container : in out List;
195 function First (Container : List) return Cursor;
197 function First_Element (Container : List) return Element_Type;
199 function Last (Container : List) return Cursor;
201 function Last_Element (Container : List) return Element_Type;
203 function Next (Position : Cursor) return Cursor;
205 procedure Next (Position : in out Cursor);
207 function Previous (Position : Cursor) return Cursor;
209 procedure Previous (Position : in out Cursor);
214 Position : Cursor := No_Element) return Cursor;
216 function Reverse_Find
219 Position : Cursor := No_Element) return Cursor;
223 Item : Element_Type) return Boolean;
227 Process : not null access procedure (Position : Cursor));
229 procedure Reverse_Iterate
231 Process : not null access procedure (Position : Cursor));
234 with function "<" (Left, Right : Element_Type) return Boolean is <>;
235 package Generic_Sorting is
237 function Is_Sorted (Container : List) return Boolean;
239 procedure Sort (Container : in out List);
241 procedure Merge (Target, Source : in out List);
247 pragma Inline (Next);
248 pragma Inline (Previous);
252 type Node_Type is record
253 Prev : Count_Type'Base;
255 Element : aliased Element_Type;
258 type Node_Array is array (Count_Type range <>) of Node_Type;
260 type List (Capacity : Count_Type) is tagged record
261 Nodes : Node_Array (1 .. Capacity) := (others => <>);
262 Free : Count_Type'Base := -1;
263 First : Count_Type := 0;
264 Last : Count_Type := 0;
265 Length : Count_Type := 0;
271 (Stream : not null access Root_Stream_Type'Class;
274 for List'Read use Read;
277 (Stream : not null access Root_Stream_Type'Class;
280 for List'Write use Write;
282 type List_Access is access all List;
283 for List_Access'Storage_Size use 0;
287 Container : List_Access;
288 Node : Count_Type := 0;
292 (Stream : not null access Root_Stream_Type'Class;
295 for Cursor'Read use Read;
298 (Stream : not null access Root_Stream_Type'Class;
301 for Cursor'Write use Write;
303 type Constant_Reference_Type
304 (Element : not null access constant Element_Type) is null record;
307 (Stream : not null access Root_Stream_Type'Class;
308 Item : Constant_Reference_Type);
310 for Constant_Reference_Type'Write use Write;
313 (Stream : not null access Root_Stream_Type'Class;
314 Item : out Constant_Reference_Type);
316 for Constant_Reference_Type'Read use Read;
319 (Element : not null access Element_Type) is null record;
322 (Stream : not null access Root_Stream_Type'Class;
323 Item : Reference_Type);
325 for Reference_Type'Write use Write;
328 (Stream : not null access Root_Stream_Type'Class;
329 Item : out Reference_Type);
331 for Reference_Type'Read use Read;
333 Empty_List : constant List := (Capacity => 0, others => <>);
335 No_Element : constant Cursor := Cursor'(null, 0);
337 end Ada.Containers.Bounded_Doubly_Linked_Lists;