1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.BOUNDED_DOUBLY_LINKED_LISTS --
9 -- Copyright (C) 2004-2014, 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
;
37 private with Ada
.Finalization
;
40 type Element_Type
is private;
42 with function "=" (Left
, Right
: Element_Type
)
45 package Ada
.Containers
.Bounded_Doubly_Linked_Lists
is
49 type List
(Capacity
: Count_Type
) 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
;
108 (Container
: aliased in out List
;
109 Position
: Cursor
) return Reference_Type
;
111 procedure Assign
(Target
: in out List
; Source
: List
);
113 function Copy
(Source
: List
; Capacity
: Count_Type
:= 0) return List
;
116 (Target
: in out List
;
117 Source
: in out List
);
120 (Container
: in out List
;
122 New_Item
: Element_Type
;
123 Count
: Count_Type
:= 1);
126 (Container
: in out List
;
128 New_Item
: Element_Type
;
129 Position
: out Cursor
;
130 Count
: Count_Type
:= 1);
133 (Container
: in out List
;
135 Position
: out Cursor
;
136 Count
: Count_Type
:= 1);
139 (Container
: in out List
;
140 New_Item
: Element_Type
;
141 Count
: Count_Type
:= 1);
144 (Container
: in out List
;
145 New_Item
: Element_Type
;
146 Count
: Count_Type
:= 1);
149 (Container
: in out List
;
150 Position
: in out Cursor
;
151 Count
: Count_Type
:= 1);
153 procedure Delete_First
154 (Container
: in out List
;
155 Count
: Count_Type
:= 1);
157 procedure Delete_Last
158 (Container
: in out List
;
159 Count
: Count_Type
:= 1);
161 procedure Reverse_Elements
(Container
: in out List
);
165 return List_Iterator_Interfaces
.Reversible_Iterator
'class;
170 return List_Iterator_Interfaces
.Reversible_Iterator
'class;
173 (Container
: in out List
;
177 (Container
: in out List
;
181 (Target
: in out List
;
183 Source
: in out List
);
186 (Target
: in out List
;
188 Source
: in out List
;
189 Position
: in out Cursor
);
192 (Container
: in out List
;
196 function First
(Container
: List
) return Cursor
;
198 function First_Element
(Container
: List
) return Element_Type
;
200 function Last
(Container
: List
) return Cursor
;
202 function Last_Element
(Container
: List
) return Element_Type
;
204 function Next
(Position
: Cursor
) return Cursor
;
206 procedure Next
(Position
: in out Cursor
);
208 function Previous
(Position
: Cursor
) return Cursor
;
210 procedure Previous
(Position
: in out Cursor
);
215 Position
: Cursor
:= No_Element
) return Cursor
;
217 function Reverse_Find
220 Position
: Cursor
:= No_Element
) return Cursor
;
224 Item
: Element_Type
) return Boolean;
228 Process
: not null access procedure (Position
: Cursor
));
230 procedure Reverse_Iterate
232 Process
: not null access procedure (Position
: Cursor
));
235 with function "<" (Left
, Right
: Element_Type
) return Boolean is <>;
236 package Generic_Sorting
is
238 function Is_Sorted
(Container
: List
) return Boolean;
240 procedure Sort
(Container
: in out List
);
242 procedure Merge
(Target
, Source
: in out List
);
248 pragma Inline
(Next
);
249 pragma Inline
(Previous
);
252 use Ada
.Finalization
;
254 type Node_Type
is record
255 Prev
: Count_Type
'Base;
257 Element
: aliased Element_Type
;
260 type Node_Array
is array (Count_Type
range <>) of Node_Type
;
262 type List
(Capacity
: Count_Type
) is tagged record
263 Nodes
: Node_Array
(1 .. Capacity
) := (others => <>);
264 Free
: Count_Type
'Base := -1;
265 First
: Count_Type
:= 0;
266 Last
: Count_Type
:= 0;
267 Length
: Count_Type
:= 0;
273 (Stream
: not null access Root_Stream_Type
'Class;
276 for List
'Read use Read
;
279 (Stream
: not null access Root_Stream_Type
'Class;
282 for List
'Write use Write
;
284 type List_Access
is access all List
;
285 for List_Access
'Storage_Size use 0;
287 type Cursor
is record
288 Container
: List_Access
;
289 Node
: Count_Type
:= 0;
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 new Controlled
with record
305 Container
: List_Access
;
308 overriding
procedure Adjust
(Control
: in out Reference_Control_Type
);
309 pragma Inline
(Adjust
);
311 overriding
procedure Finalize
(Control
: in out Reference_Control_Type
);
312 pragma Inline
(Finalize
);
314 type Constant_Reference_Type
315 (Element
: not null access constant Element_Type
) is
317 Control
: Reference_Control_Type
;
321 (Stream
: not null access Root_Stream_Type
'Class;
322 Item
: out Constant_Reference_Type
);
324 for Constant_Reference_Type
'Read use Read
;
327 (Stream
: not null access Root_Stream_Type
'Class;
328 Item
: Constant_Reference_Type
);
330 for Constant_Reference_Type
'Write use Write
;
332 type Reference_Type
(Element
: not null access Element_Type
) is record
333 Control
: Reference_Control_Type
;
337 (Stream
: not null access Root_Stream_Type
'Class;
338 Item
: Reference_Type
);
340 for Reference_Type
'Write use Write
;
343 (Stream
: not null access Root_Stream_Type
'Class;
344 Item
: out Reference_Type
);
346 for Reference_Type
'Read use Read
;
348 Empty_List
: constant List
:= (Capacity
=> 0, others => <>);
350 No_Element
: constant Cursor
:= Cursor
'(null, 0);
352 type Iterator is new Limited_Controlled and
353 List_Iterator_Interfaces.Reversible_Iterator with
355 Container : List_Access;
359 overriding procedure Finalize (Object : in out Iterator);
361 overriding function First (Object : Iterator) return Cursor;
362 overriding function Last (Object : Iterator) return Cursor;
364 overriding function Next
366 Position : Cursor) return Cursor;
368 overriding function Previous
370 Position : Cursor) return Cursor;
372 end Ada.Containers.Bounded_Doubly_Linked_Lists;