Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / ada / a-cobove.ads
blob30dc9aabfba77ddf401a341abe00624f7793dd96
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . B O U N D E D _ V E C T O R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2010, 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.Streams;
36 generic
37 type Index_Type is range <>;
38 type Element_Type is private;
40 with function "=" (Left, Right : Element_Type) return Boolean is <>;
42 package Ada.Containers.Bounded_Vectors is
43 pragma Pure;
44 pragma Remote_Types;
46 subtype Extended_Index is Index_Type'Base
47 range Index_Type'First - 1 ..
48 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
50 No_Index : constant Extended_Index := Extended_Index'First;
52 type Vector (Capacity : Count_Type) is tagged private;
53 pragma Preelaborable_Initialization (Vector);
55 type Cursor is private;
56 pragma Preelaborable_Initialization (Cursor);
58 Empty_Vector : constant Vector;
60 No_Element : constant Cursor;
62 overriding function "=" (Left, Right : Vector) return Boolean;
64 function To_Vector (Length : Count_Type) return Vector;
66 function To_Vector
67 (New_Item : Element_Type;
68 Length : Count_Type) return Vector;
70 function "&" (Left, Right : Vector) return Vector;
72 function "&" (Left : Vector; Right : Element_Type) return Vector;
74 function "&" (Left : Element_Type; Right : Vector) return Vector;
76 function "&" (Left, Right : Element_Type) return Vector;
78 function Capacity (Container : Vector) return Count_Type;
80 procedure Reserve_Capacity
81 (Container : in out Vector;
82 Capacity : Count_Type);
84 function Length (Container : Vector) return Count_Type;
86 procedure Set_Length
87 (Container : in out Vector;
88 Length : Count_Type);
90 function Is_Empty (Container : Vector) return Boolean;
92 procedure Clear (Container : in out Vector);
94 function To_Cursor
95 (Container : Vector;
96 Index : Extended_Index) return Cursor;
98 function To_Index (Position : Cursor) return Extended_Index;
100 function Element
101 (Container : Vector;
102 Index : Index_Type) return Element_Type;
104 function Element (Position : Cursor) return Element_Type;
106 procedure Replace_Element
107 (Container : in out Vector;
108 Index : Index_Type;
109 New_Item : Element_Type);
111 procedure Replace_Element
112 (Container : in out Vector;
113 Position : Cursor;
114 New_Item : Element_Type);
116 procedure Query_Element
117 (Container : Vector;
118 Index : Index_Type;
119 Process : not null access procedure (Element : Element_Type));
121 procedure Query_Element
122 (Position : Cursor;
123 Process : not null access procedure (Element : Element_Type));
125 procedure Update_Element
126 (Container : in out Vector;
127 Index : Index_Type;
128 Process : not null access procedure (Element : in out Element_Type));
130 procedure Update_Element
131 (Container : in out Vector;
132 Position : Cursor;
133 Process : not null access procedure (Element : in out Element_Type));
135 procedure Assign (Target : in out Vector; Source : Vector);
137 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
139 procedure Move (Target : in out Vector; Source : in out Vector);
141 procedure Insert
142 (Container : in out Vector;
143 Before : Extended_Index;
144 New_Item : Vector);
146 procedure Insert
147 (Container : in out Vector;
148 Before : Cursor;
149 New_Item : Vector);
151 procedure Insert
152 (Container : in out Vector;
153 Before : Cursor;
154 New_Item : Vector;
155 Position : out Cursor);
157 procedure Insert
158 (Container : in out Vector;
159 Before : Extended_Index;
160 New_Item : Element_Type;
161 Count : Count_Type := 1);
163 procedure Insert
164 (Container : in out Vector;
165 Before : Cursor;
166 New_Item : Element_Type;
167 Count : Count_Type := 1);
169 procedure Insert
170 (Container : in out Vector;
171 Before : Cursor;
172 New_Item : Element_Type;
173 Position : out Cursor;
174 Count : Count_Type := 1);
176 procedure Insert
177 (Container : in out Vector;
178 Before : Extended_Index;
179 Count : Count_Type := 1);
181 procedure Insert
182 (Container : in out Vector;
183 Before : Cursor;
184 Position : out Cursor;
185 Count : Count_Type := 1);
187 procedure Prepend
188 (Container : in out Vector;
189 New_Item : Vector);
191 procedure Prepend
192 (Container : in out Vector;
193 New_Item : Element_Type;
194 Count : Count_Type := 1);
196 procedure Append
197 (Container : in out Vector;
198 New_Item : Vector);
200 procedure Append
201 (Container : in out Vector;
202 New_Item : Element_Type;
203 Count : Count_Type := 1);
205 procedure Insert_Space
206 (Container : in out Vector;
207 Before : Extended_Index;
208 Count : Count_Type := 1);
210 procedure Insert_Space
211 (Container : in out Vector;
212 Before : Cursor;
213 Position : out Cursor;
214 Count : Count_Type := 1);
216 procedure Delete
217 (Container : in out Vector;
218 Index : Extended_Index;
219 Count : Count_Type := 1);
221 procedure Delete
222 (Container : in out Vector;
223 Position : in out Cursor;
224 Count : Count_Type := 1);
226 procedure Delete_First
227 (Container : in out Vector;
228 Count : Count_Type := 1);
230 procedure Delete_Last
231 (Container : in out Vector;
232 Count : Count_Type := 1);
234 procedure Reverse_Elements (Container : in out Vector);
236 procedure Swap (Container : in out Vector; I, J : Index_Type);
238 procedure Swap (Container : in out Vector; I, J : Cursor);
240 function First_Index (Container : Vector) return Index_Type;
242 function First (Container : Vector) return Cursor;
244 function First_Element (Container : Vector) return Element_Type;
246 function Last_Index (Container : Vector) return Extended_Index;
248 function Last (Container : Vector) return Cursor;
250 function Last_Element (Container : Vector) return Element_Type;
252 function Next (Position : Cursor) return Cursor;
254 procedure Next (Position : in out Cursor);
256 function Previous (Position : Cursor) return Cursor;
258 procedure Previous (Position : in out Cursor);
260 function Find_Index
261 (Container : Vector;
262 Item : Element_Type;
263 Index : Index_Type := Index_Type'First) return Extended_Index;
265 function Find
266 (Container : Vector;
267 Item : Element_Type;
268 Position : Cursor := No_Element) return Cursor;
270 function Reverse_Find_Index
271 (Container : Vector;
272 Item : Element_Type;
273 Index : Index_Type := Index_Type'Last) return Extended_Index;
275 function Reverse_Find
276 (Container : Vector;
277 Item : Element_Type;
278 Position : Cursor := No_Element) return Cursor;
280 function Contains
281 (Container : Vector;
282 Item : Element_Type) return Boolean;
284 function Has_Element (Position : Cursor) return Boolean;
286 procedure Iterate
287 (Container : Vector;
288 Process : not null access procedure (Position : Cursor));
290 procedure Reverse_Iterate
291 (Container : Vector;
292 Process : not null access procedure (Position : Cursor));
294 generic
295 with function "<" (Left, Right : Element_Type) return Boolean is <>;
296 package Generic_Sorting is
298 function Is_Sorted (Container : Vector) return Boolean;
300 procedure Sort (Container : in out Vector);
302 procedure Merge (Target : in out Vector; Source : in out Vector);
304 end Generic_Sorting;
306 private
308 pragma Inline (First_Index);
309 pragma Inline (Last_Index);
310 pragma Inline (Element);
311 pragma Inline (First_Element);
312 pragma Inline (Last_Element);
313 pragma Inline (Query_Element);
314 pragma Inline (Update_Element);
315 pragma Inline (Replace_Element);
316 pragma Inline (Is_Empty);
317 pragma Inline (Contains);
318 pragma Inline (Next);
319 pragma Inline (Previous);
321 type Elements_Array is array (Count_Type range <>) of Element_Type;
322 function "=" (L, R : Elements_Array) return Boolean is abstract;
324 type Vector (Capacity : Count_Type) is tagged record
325 Elements : Elements_Array (1 .. Capacity);
326 Last : Extended_Index := No_Index;
327 Busy : Natural := 0;
328 Lock : Natural := 0;
329 end record;
331 use Ada.Streams;
333 procedure Write
334 (Stream : not null access Root_Stream_Type'Class;
335 Container : Vector);
337 for Vector'Write use Write;
339 procedure Read
340 (Stream : not null access Root_Stream_Type'Class;
341 Container : out Vector);
343 for Vector'Read use Read;
345 type Vector_Access is access all Vector;
346 for Vector_Access'Storage_Size use 0;
348 type Cursor is record
349 Container : Vector_Access;
350 Index : Index_Type := Index_Type'First;
351 end record;
353 procedure Write
354 (Stream : not null access Root_Stream_Type'Class;
355 Position : Cursor);
357 for Cursor'Write use Write;
359 procedure Read
360 (Stream : not null access Root_Stream_Type'Class;
361 Position : out Cursor);
363 for Cursor'Read use Read;
365 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
367 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
369 end Ada.Containers.Bounded_Vectors;