]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/a-convec.ads
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / gcc / ada / a-convec.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . V E C T O R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2008, 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 ------------------------------------------------------------------------------
33
34 private with Ada.Finalization;
35 private with Ada.Streams;
36
37 generic
38 type Index_Type is range <>;
39 type Element_Type is private;
40
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
42
43 package Ada.Containers.Vectors is
44 pragma Preelaborate;
45 pragma Remote_Types;
46
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
49 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
50
51 No_Index : constant Extended_Index := Extended_Index'First;
52
53 type Vector is tagged private;
54 pragma Preelaborable_Initialization (Vector);
55
56 type Cursor is private;
57 pragma Preelaborable_Initialization (Cursor);
58
59 Empty_Vector : constant Vector;
60
61 No_Element : constant Cursor;
62
63 overriding function "=" (Left, Right : Vector) return Boolean;
64
65 function To_Vector (Length : Count_Type) return Vector;
66
67 function To_Vector
68 (New_Item : Element_Type;
69 Length : Count_Type) return Vector;
70
71 function "&" (Left, Right : Vector) return Vector;
72
73 function "&" (Left : Vector; Right : Element_Type) return Vector;
74
75 function "&" (Left : Element_Type; Right : Vector) return Vector;
76
77 function "&" (Left, Right : Element_Type) return Vector;
78
79 function Capacity (Container : Vector) return Count_Type;
80
81 procedure Reserve_Capacity
82 (Container : in out Vector;
83 Capacity : Count_Type);
84
85 function Length (Container : Vector) return Count_Type;
86
87 procedure Set_Length
88 (Container : in out Vector;
89 Length : Count_Type);
90
91 function Is_Empty (Container : Vector) return Boolean;
92
93 procedure Clear (Container : in out Vector);
94
95 function To_Cursor
96 (Container : Vector;
97 Index : Extended_Index) return Cursor;
98
99 function To_Index (Position : Cursor) return Extended_Index;
100
101 function Element
102 (Container : Vector;
103 Index : Index_Type) return Element_Type;
104
105 function Element (Position : Cursor) return Element_Type;
106
107 procedure Replace_Element
108 (Container : in out Vector;
109 Index : Index_Type;
110 New_Item : Element_Type);
111
112 procedure Replace_Element
113 (Container : in out Vector;
114 Position : Cursor;
115 New_Item : Element_Type);
116
117 procedure Query_Element
118 (Container : Vector;
119 Index : Index_Type;
120 Process : not null access procedure (Element : Element_Type));
121
122 procedure Query_Element
123 (Position : Cursor;
124 Process : not null access procedure (Element : Element_Type));
125
126 procedure Update_Element
127 (Container : in out Vector;
128 Index : Index_Type;
129 Process : not null access procedure (Element : in out Element_Type));
130
131 procedure Update_Element
132 (Container : in out Vector;
133 Position : Cursor;
134 Process : not null access procedure (Element : in out Element_Type));
135
136 procedure Move (Target : in out Vector; Source : in out Vector);
137
138 procedure Insert
139 (Container : in out Vector;
140 Before : Extended_Index;
141 New_Item : Vector);
142
143 procedure Insert
144 (Container : in out Vector;
145 Before : Cursor;
146 New_Item : Vector);
147
148 procedure Insert
149 (Container : in out Vector;
150 Before : Cursor;
151 New_Item : Vector;
152 Position : out Cursor);
153
154 procedure Insert
155 (Container : in out Vector;
156 Before : Extended_Index;
157 New_Item : Element_Type;
158 Count : Count_Type := 1);
159
160 procedure Insert
161 (Container : in out Vector;
162 Before : Cursor;
163 New_Item : Element_Type;
164 Count : Count_Type := 1);
165
166 procedure Insert
167 (Container : in out Vector;
168 Before : Cursor;
169 New_Item : Element_Type;
170 Position : out Cursor;
171 Count : Count_Type := 1);
172
173 procedure Insert
174 (Container : in out Vector;
175 Before : Extended_Index;
176 Count : Count_Type := 1);
177
178 procedure Insert
179 (Container : in out Vector;
180 Before : Cursor;
181 Position : out Cursor;
182 Count : Count_Type := 1);
183
184 procedure Prepend
185 (Container : in out Vector;
186 New_Item : Vector);
187
188 procedure Prepend
189 (Container : in out Vector;
190 New_Item : Element_Type;
191 Count : Count_Type := 1);
192
193 procedure Append
194 (Container : in out Vector;
195 New_Item : Vector);
196
197 procedure Append
198 (Container : in out Vector;
199 New_Item : Element_Type;
200 Count : Count_Type := 1);
201
202 procedure Insert_Space
203 (Container : in out Vector;
204 Before : Extended_Index;
205 Count : Count_Type := 1);
206
207 procedure Insert_Space
208 (Container : in out Vector;
209 Before : Cursor;
210 Position : out Cursor;
211 Count : Count_Type := 1);
212
213 procedure Delete
214 (Container : in out Vector;
215 Index : Extended_Index;
216 Count : Count_Type := 1);
217
218 procedure Delete
219 (Container : in out Vector;
220 Position : in out Cursor;
221 Count : Count_Type := 1);
222
223 procedure Delete_First
224 (Container : in out Vector;
225 Count : Count_Type := 1);
226
227 procedure Delete_Last
228 (Container : in out Vector;
229 Count : Count_Type := 1);
230
231 procedure Reverse_Elements (Container : in out Vector);
232
233 procedure Swap (Container : in out Vector; I, J : Index_Type);
234
235 procedure Swap (Container : in out Vector; I, J : Cursor);
236
237 function First_Index (Container : Vector) return Index_Type;
238
239 function First (Container : Vector) return Cursor;
240
241 function First_Element (Container : Vector) return Element_Type;
242
243 function Last_Index (Container : Vector) return Extended_Index;
244
245 function Last (Container : Vector) return Cursor;
246
247 function Last_Element (Container : Vector) return Element_Type;
248
249 function Next (Position : Cursor) return Cursor;
250
251 procedure Next (Position : in out Cursor);
252
253 function Previous (Position : Cursor) return Cursor;
254
255 procedure Previous (Position : in out Cursor);
256
257 function Find_Index
258 (Container : Vector;
259 Item : Element_Type;
260 Index : Index_Type := Index_Type'First) return Extended_Index;
261
262 function Find
263 (Container : Vector;
264 Item : Element_Type;
265 Position : Cursor := No_Element) return Cursor;
266
267 function Reverse_Find_Index
268 (Container : Vector;
269 Item : Element_Type;
270 Index : Index_Type := Index_Type'Last) return Extended_Index;
271
272 function Reverse_Find
273 (Container : Vector;
274 Item : Element_Type;
275 Position : Cursor := No_Element) return Cursor;
276
277 function Contains
278 (Container : Vector;
279 Item : Element_Type) return Boolean;
280
281 function Has_Element (Position : Cursor) return Boolean;
282
283 procedure Iterate
284 (Container : Vector;
285 Process : not null access procedure (Position : Cursor));
286
287 procedure Reverse_Iterate
288 (Container : Vector;
289 Process : not null access procedure (Position : Cursor));
290
291 generic
292 with function "<" (Left, Right : Element_Type) return Boolean is <>;
293 package Generic_Sorting is
294
295 function Is_Sorted (Container : Vector) return Boolean;
296
297 procedure Sort (Container : in out Vector);
298
299 procedure Merge (Target : in out Vector; Source : in out Vector);
300
301 end Generic_Sorting;
302
303 private
304
305 pragma Inline (First_Index);
306 pragma Inline (Last_Index);
307 pragma Inline (Element);
308 pragma Inline (First_Element);
309 pragma Inline (Last_Element);
310 pragma Inline (Query_Element);
311 pragma Inline (Update_Element);
312 pragma Inline (Replace_Element);
313 pragma Inline (Contains);
314 pragma Inline (Next);
315 pragma Inline (Previous);
316
317 type Elements_Array is array (Index_Type range <>) of Element_Type;
318 function "=" (L, R : Elements_Array) return Boolean is abstract;
319
320 type Elements_Type (Last : Index_Type) is limited record
321 EA : Elements_Array (Index_Type'First .. Last);
322 end record;
323
324 type Elements_Access is access Elements_Type;
325
326 use Ada.Finalization;
327
328 type Vector is new Controlled with record
329 Elements : Elements_Access;
330 Last : Extended_Index := No_Index;
331 Busy : Natural := 0;
332 Lock : Natural := 0;
333 end record;
334
335 overriding
336 procedure Adjust (Container : in out Vector);
337
338 overriding
339 procedure Finalize (Container : in out Vector);
340
341 use Ada.Streams;
342
343 procedure Write
344 (Stream : not null access Root_Stream_Type'Class;
345 Container : Vector);
346
347 for Vector'Write use Write;
348
349 procedure Read
350 (Stream : not null access Root_Stream_Type'Class;
351 Container : out Vector);
352
353 for Vector'Read use Read;
354
355 type Vector_Access is access constant Vector;
356 for Vector_Access'Storage_Size use 0;
357
358 type Cursor is record
359 Container : Vector_Access;
360 Index : Index_Type := Index_Type'First;
361 end record;
362
363 procedure Write
364 (Stream : not null access Root_Stream_Type'Class;
365 Position : Cursor);
366
367 for Cursor'Write use Write;
368
369 procedure Read
370 (Stream : not null access Root_Stream_Type'Class;
371 Position : out Cursor);
372
373 for Cursor'Read use Read;
374
375 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
376
377 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
378
379 end Ada.Containers.Vectors;