1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . C O N T A I N E R S . D O U B L Y _ L I N K E D _ L I S T S --
9 -- Copyright (C) 2004-2013, 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
.Finalization
;
37 private with Ada
.Streams
;
40 type Element_Type
is private;
42 with function "=" (Left
, Right
: Element_Type
)
45 package Ada
.Containers
.Doubly_Linked_Lists
is
49 type List
is tagged private
51 Constant_Indexing
=> Constant_Reference
,
52 Variable_Indexing
=> Reference
,
53 Default_Iterator
=> Iterate
,
54 Iterator_Element
=> Element_Type
;
56 pragma Preelaborable_Initialization
(List
);
58 type Cursor
is private;
59 pragma Preelaborable_Initialization
(Cursor
);
61 Empty_List
: constant List
;
63 No_Element
: constant Cursor
;
65 function Has_Element
(Position
: Cursor
) return Boolean;
67 package List_Iterator_Interfaces
is new
68 Ada
.Iterator_Interfaces
(Cursor
, Has_Element
);
70 function "=" (Left
, Right
: List
) return Boolean;
72 function Length
(Container
: List
) return Count_Type
;
74 function Is_Empty
(Container
: List
) return Boolean;
76 procedure Clear
(Container
: in out List
);
78 function Element
(Position
: Cursor
) return Element_Type
;
80 procedure Replace_Element
81 (Container
: in out List
;
83 New_Item
: Element_Type
);
85 procedure Query_Element
87 Process
: not null access procedure (Element
: Element_Type
));
89 procedure Update_Element
90 (Container
: in out List
;
92 Process
: not null access procedure (Element
: in out Element_Type
));
94 type Constant_Reference_Type
95 (Element
: not null access constant Element_Type
) is private
97 Implicit_Dereference
=> Element
;
100 (Element
: not null access Element_Type
) is private
102 Implicit_Dereference
=> Element
;
104 function Constant_Reference
105 (Container
: aliased List
;
106 Position
: Cursor
) return Constant_Reference_Type
;
107 pragma Inline
(Constant_Reference
);
110 (Container
: aliased in out List
;
111 Position
: Cursor
) return Reference_Type
;
112 pragma Inline
(Reference
);
114 procedure Assign
(Target
: in out List
; Source
: List
);
116 function Copy
(Source
: List
) return List
;
119 (Target
: in out List
;
120 Source
: in out List
);
123 (Container
: in out List
;
125 New_Item
: Element_Type
;
126 Count
: Count_Type
:= 1);
129 (Container
: in out List
;
131 New_Item
: Element_Type
;
132 Position
: out Cursor
;
133 Count
: Count_Type
:= 1);
136 (Container
: in out List
;
138 Position
: out Cursor
;
139 Count
: Count_Type
:= 1);
142 (Container
: in out List
;
143 New_Item
: Element_Type
;
144 Count
: Count_Type
:= 1);
147 (Container
: in out List
;
148 New_Item
: Element_Type
;
149 Count
: Count_Type
:= 1);
152 (Container
: in out List
;
153 Position
: in out Cursor
;
154 Count
: Count_Type
:= 1);
156 procedure Delete_First
157 (Container
: in out List
;
158 Count
: Count_Type
:= 1);
160 procedure Delete_Last
161 (Container
: in out List
;
162 Count
: Count_Type
:= 1);
164 procedure Reverse_Elements
(Container
: in out List
);
166 function Iterate
(Container
: List
)
167 return List_Iterator_Interfaces
.Reversible_Iterator
'Class;
169 function Iterate
(Container
: List
; Start
: Cursor
)
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 type Node_Access
is access Node_Type
;
256 Element
: aliased Element_Type
;
261 use Ada
.Finalization
;
265 new Controlled
with record
268 Length
: Count_Type
:= 0;
273 overriding
procedure Adjust
(Container
: in out List
);
275 overriding
procedure Finalize
(Container
: in out List
) renames Clear
;
278 (Stream
: not null access Root_Stream_Type
'Class;
281 for List
'Read use Read
;
284 (Stream
: not null access Root_Stream_Type
'Class;
287 for List
'Write use Write
;
289 type List_Access
is access all List
;
290 for List_Access
'Storage_Size use 0;
294 Container
: List_Access
;
299 (Stream
: not null access Root_Stream_Type
'Class;
302 for Cursor
'Read use Read
;
305 (Stream
: not null access Root_Stream_Type
'Class;
308 for Cursor
'Write use Write
;
310 type Reference_Control_Type
is
311 new Controlled
with record
312 Container
: List_Access
;
315 overriding
procedure Adjust
(Control
: in out Reference_Control_Type
);
316 pragma Inline
(Adjust
);
318 overriding
procedure Finalize
(Control
: in out Reference_Control_Type
);
319 pragma Inline
(Finalize
);
321 type Constant_Reference_Type
322 (Element
: not null access constant Element_Type
) is
324 Control
: Reference_Control_Type
;
328 (Stream
: not null access Root_Stream_Type
'Class;
329 Item
: Constant_Reference_Type
);
331 for Constant_Reference_Type
'Write use Write
;
334 (Stream
: not null access Root_Stream_Type
'Class;
335 Item
: out Constant_Reference_Type
);
337 for Constant_Reference_Type
'Read use Read
;
340 (Element
: not null access Element_Type
) is
342 Control
: Reference_Control_Type
;
346 (Stream
: not null access Root_Stream_Type
'Class;
347 Item
: Reference_Type
);
349 for Reference_Type
'Write use Write
;
352 (Stream
: not null access Root_Stream_Type
'Class;
353 Item
: out Reference_Type
);
355 for Reference_Type
'Read use Read
;
357 Empty_List
: constant List
:= (Controlled
with null, null, 0, 0, 0);
359 No_Element
: constant Cursor
:= Cursor
'(null, null);
361 type Iterator is new Limited_Controlled and
362 List_Iterator_Interfaces.Reversible_Iterator with
364 Container : List_Access;
368 overriding procedure Finalize (Object : in out Iterator);
370 overriding function First (Object : Iterator) return Cursor;
371 overriding function Last (Object : Iterator) return Cursor;
373 overriding function Next
375 Position : Cursor) return Cursor;
377 overriding function Previous
379 Position : Cursor) return Cursor;
381 end Ada.Containers.Doubly_Linked_Lists;