gcc/
[official-gcc.git] / gcc / ada / a-cdlili.ads
blob3cefaceec1fe24fa655ec06ff4015188a4dab748
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
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 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2009, Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
21 -- --
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. --
25 -- --
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/>. --
30 -- --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 private with Ada.Finalization;
35 private with Ada.Streams;
37 generic
38 type Element_Type is private;
40 with function "=" (Left, Right : Element_Type)
41 return Boolean is <>;
43 package Ada.Containers.Doubly_Linked_Lists is
44 pragma Preelaborate;
45 pragma Remote_Types;
47 type List is tagged private;
48 pragma Preelaborable_Initialization (List);
50 type Cursor is private;
51 pragma Preelaborable_Initialization (Cursor);
53 Empty_List : constant List;
55 No_Element : constant Cursor;
57 function "=" (Left, Right : List) return Boolean;
59 function Length (Container : List) return Count_Type;
61 function Is_Empty (Container : List) return Boolean;
63 procedure Clear (Container : in out List);
65 function Element (Position : Cursor) return Element_Type;
67 procedure Replace_Element
68 (Container : in out List;
69 Position : Cursor;
70 New_Item : Element_Type);
72 procedure Query_Element
73 (Position : Cursor;
74 Process : not null access procedure (Element : Element_Type));
76 procedure Update_Element
77 (Container : in out List;
78 Position : Cursor;
79 Process : not null access procedure (Element : in out Element_Type));
81 procedure Move
82 (Target : in out List;
83 Source : in out List);
85 procedure Insert
86 (Container : in out List;
87 Before : Cursor;
88 New_Item : Element_Type;
89 Count : Count_Type := 1);
91 procedure Insert
92 (Container : in out List;
93 Before : Cursor;
94 New_Item : Element_Type;
95 Position : out Cursor;
96 Count : Count_Type := 1);
98 procedure Insert
99 (Container : in out List;
100 Before : Cursor;
101 Position : out Cursor;
102 Count : Count_Type := 1);
104 procedure Prepend
105 (Container : in out List;
106 New_Item : Element_Type;
107 Count : Count_Type := 1);
109 procedure Append
110 (Container : in out List;
111 New_Item : Element_Type;
112 Count : Count_Type := 1);
114 procedure Delete
115 (Container : in out List;
116 Position : in out Cursor;
117 Count : Count_Type := 1);
119 procedure Delete_First
120 (Container : in out List;
121 Count : Count_Type := 1);
123 procedure Delete_Last
124 (Container : in out List;
125 Count : Count_Type := 1);
127 procedure Reverse_Elements (Container : in out List);
129 procedure Swap
130 (Container : in out List;
131 I, J : Cursor);
133 procedure Swap_Links
134 (Container : in out List;
135 I, J : Cursor);
137 procedure Splice
138 (Target : in out List;
139 Before : Cursor;
140 Source : in out List);
142 procedure Splice
143 (Target : in out List;
144 Before : Cursor;
145 Source : in out List;
146 Position : in out Cursor);
148 procedure Splice
149 (Container : in out List;
150 Before : Cursor;
151 Position : Cursor);
153 function First (Container : List) return Cursor;
155 function First_Element (Container : List) return Element_Type;
157 function Last (Container : List) return Cursor;
159 function Last_Element (Container : List) return Element_Type;
161 function Next (Position : Cursor) return Cursor;
163 procedure Next (Position : in out Cursor);
165 function Previous (Position : Cursor) return Cursor;
167 procedure Previous (Position : in out Cursor);
169 function Find
170 (Container : List;
171 Item : Element_Type;
172 Position : Cursor := No_Element) return Cursor;
174 function Reverse_Find
175 (Container : List;
176 Item : Element_Type;
177 Position : Cursor := No_Element) return Cursor;
179 function Contains
180 (Container : List;
181 Item : Element_Type) return Boolean;
183 function Has_Element (Position : Cursor) return Boolean;
185 procedure Iterate
186 (Container : List;
187 Process : not null access procedure (Position : Cursor));
189 procedure Reverse_Iterate
190 (Container : List;
191 Process : not null access procedure (Position : Cursor));
193 generic
194 with function "<" (Left, Right : Element_Type) return Boolean is <>;
195 package Generic_Sorting is
197 function Is_Sorted (Container : List) return Boolean;
199 procedure Sort (Container : in out List);
201 procedure Merge (Target, Source : in out List);
203 end Generic_Sorting;
205 private
207 pragma Inline (Next);
208 pragma Inline (Previous);
210 type Node_Type;
211 type Node_Access is access Node_Type;
213 type Node_Type is
214 limited record
215 Element : Element_Type;
216 Next : Node_Access;
217 Prev : Node_Access;
218 end record;
220 use Ada.Finalization;
222 type List is
223 new Controlled with record
224 First : Node_Access;
225 Last : Node_Access;
226 Length : Count_Type := 0;
227 Busy : Natural := 0;
228 Lock : Natural := 0;
229 end record;
231 overriding
232 procedure Adjust (Container : in out List);
234 overriding
235 procedure Finalize (Container : in out List) renames Clear;
237 use Ada.Streams;
239 procedure Read
240 (Stream : not null access Root_Stream_Type'Class;
241 Item : out List);
243 for List'Read use Read;
245 procedure Write
246 (Stream : not null access Root_Stream_Type'Class;
247 Item : List);
249 for List'Write use Write;
251 type List_Access is access constant List;
252 for List_Access'Storage_Size use 0;
254 type Cursor is
255 record
256 Container : List_Access;
257 Node : Node_Access;
258 end record;
260 procedure Read
261 (Stream : not null access Root_Stream_Type'Class;
262 Item : out Cursor);
264 for Cursor'Read use Read;
266 procedure Write
267 (Stream : not null access Root_Stream_Type'Class;
268 Item : Cursor);
270 for Cursor'Write use Write;
272 Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
274 No_Element : constant Cursor := Cursor'(null, null);
276 end Ada.Containers.Doubly_Linked_Lists;