1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.BOUNDED_DOUBLY_LINKED_LISTS --
9 -- Copyright (C) 2004-2010, 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.Streams;
37 type Element_Type is private;
39 with function "=" (Left, Right : Element_Type)
42 package Ada.Containers.Bounded_Doubly_Linked_Lists is
46 type List (Capacity : Count_Type) is tagged private;
47 pragma Preelaborable_Initialization (List);
49 type Cursor is private;
50 pragma Preelaborable_Initialization (Cursor);
52 Empty_List : constant List;
54 No_Element : constant Cursor;
56 function "=" (Left, Right : List) return Boolean;
58 function Length (Container : List) return Count_Type;
60 function Is_Empty (Container : List) return Boolean;
62 procedure Clear (Container : in out List);
64 function Element (Position : Cursor) return Element_Type;
66 procedure Replace_Element
67 (Container : in out List;
69 New_Item : Element_Type);
71 procedure Query_Element
73 Process : not null access procedure (Element : Element_Type));
75 procedure Update_Element
76 (Container : in out List;
78 Process : not null access procedure (Element : in out Element_Type));
80 procedure Assign (Target : in out List; Source : List);
82 function Copy (Source : List; Capacity : Count_Type := 0) return List;
85 (Target : in out List;
86 Source : in out List);
89 (Container : in out List;
91 New_Item : Element_Type;
92 Count : Count_Type := 1);
95 (Container : in out List;
97 New_Item : Element_Type;
98 Position : out Cursor;
99 Count : Count_Type := 1);
102 (Container : in out List;
104 Position : out Cursor;
105 Count : Count_Type := 1);
108 (Container : in out List;
109 New_Item : Element_Type;
110 Count : Count_Type := 1);
113 (Container : in out List;
114 New_Item : Element_Type;
115 Count : Count_Type := 1);
118 (Container : in out List;
119 Position : in out Cursor;
120 Count : Count_Type := 1);
122 procedure Delete_First
123 (Container : in out List;
124 Count : Count_Type := 1);
126 procedure Delete_Last
127 (Container : in out List;
128 Count : Count_Type := 1);
130 procedure Reverse_Elements (Container : in out List);
133 (Container : in out List;
137 (Container : in out List;
141 (Target : in out List;
143 Source : in out List);
146 (Target : in out List;
148 Source : in out List;
149 Position : in out Cursor);
152 (Container : in out List;
156 function First (Container : List) return Cursor;
158 function First_Element (Container : List) return Element_Type;
160 function Last (Container : List) return Cursor;
162 function Last_Element (Container : List) return Element_Type;
164 function Next (Position : Cursor) return Cursor;
166 procedure Next (Position : in out Cursor);
168 function Previous (Position : Cursor) return Cursor;
170 procedure Previous (Position : in out Cursor);
175 Position : Cursor := No_Element) return Cursor;
177 function Reverse_Find
180 Position : Cursor := No_Element) return Cursor;
184 Item : Element_Type) return Boolean;
186 function Has_Element (Position : Cursor) return Boolean;
190 Process : not null access procedure (Position : Cursor));
192 procedure Reverse_Iterate
194 Process : not null access procedure (Position : Cursor));
197 with function "<" (Left, Right : Element_Type) return Boolean is <>;
198 package Generic_Sorting is
200 function Is_Sorted (Container : List) return Boolean;
202 procedure Sort (Container : in out List);
204 procedure Merge (Target, Source : in out List);
210 pragma Inline (Next);
211 pragma Inline (Previous);
213 type Node_Type is record
214 Prev : Count_Type'Base;
216 Element : Element_Type;
219 type Node_Array is array (Count_Type range <>) of Node_Type;
221 type List (Capacity : Count_Type) is tagged record
222 Nodes : Node_Array (1 .. Capacity) := (others => <>);
223 Free : Count_Type'Base := -1;
224 First : Count_Type := 0;
225 Last : Count_Type := 0;
226 Length : Count_Type := 0;
234 (Stream : not null access Root_Stream_Type'Class;
237 for List'Read use Read;
240 (Stream : not null access Root_Stream_Type'Class;
243 for List'Write use Write;
245 type List_Access is access all List;
246 for List_Access'Storage_Size use 0;
250 Container : List_Access;
251 Node : Count_Type := 0;
255 (Stream : not null access Root_Stream_Type'Class;
258 for Cursor'Read use Read;
261 (Stream : not null access Root_Stream_Type'Class;
264 for Cursor'Write use Write;
266 Empty_List : constant List := (Capacity => 0, others => <>);
268 No_Element : constant Cursor := Cursor'(null, 0);
270 end Ada.Containers.Bounded_Doubly_Linked_Lists;