2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / a-convec.ads
blob5b268b5e3f056767c2e6e0a0c7bbb0cb2506eb75
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-2005, 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 2, 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. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- This unit was originally developed by Matthew J Heaney. --
34 ------------------------------------------------------------------------------
35 with Ada.Finalization;
36 with Ada.Streams;
38 generic
39 type Index_Type is range <>;
40 type Element_Type is private;
42 with function "=" (Left, Right : Element_Type) return Boolean is <>;
44 package Ada.Containers.Vectors is
45 pragma Preelaborate;
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;
51 No_Index : constant Extended_Index := Extended_Index'First;
53 type Vector is tagged private;
55 type Cursor is private;
57 Empty_Vector : constant Vector;
59 No_Element : constant Cursor;
61 function "=" (Left, Right : Vector) return Boolean;
63 function To_Vector (Length : Count_Type) return Vector;
65 function To_Vector
66 (New_Item : Element_Type;
67 Length : Count_Type) return Vector;
69 function "&" (Left, Right : Vector) return Vector;
71 function "&" (Left : Vector; Right : Element_Type) return Vector;
73 function "&" (Left : Element_Type; Right : Vector) return Vector;
75 function "&" (Left, Right : Element_Type) return Vector;
77 function Capacity (Container : Vector) return Count_Type;
79 procedure Reserve_Capacity
80 (Container : in out Vector;
81 Capacity : Count_Type);
83 function Length (Container : Vector) return Count_Type;
85 procedure Set_Length
86 (Container : in out Vector;
87 Length : Count_Type);
89 function Is_Empty (Container : Vector) return Boolean;
91 procedure Clear (Container : in out Vector);
93 function To_Cursor
94 (Container : Vector;
95 Index : Extended_Index) return Cursor;
97 function To_Index (Position : Cursor) return Extended_Index;
99 function Element
100 (Container : Vector;
101 Index : Index_Type) return Element_Type;
103 function Element (Position : Cursor) return Element_Type;
105 procedure Replace_Element
106 (Container : in out Vector;
107 Index : Index_Type;
108 New_Item : Element_Type);
110 procedure Replace_Element
111 (Container : in out Vector;
112 Position : Cursor;
113 New_Item : Element_Type);
115 procedure Query_Element
116 (Container : Vector;
117 Index : Index_Type;
118 Process : not null access procedure (Element : Element_Type));
120 procedure Query_Element
121 (Position : Cursor;
122 Process : not null access procedure (Element : Element_Type));
124 procedure Update_Element
125 (Container : in out Vector;
126 Index : Index_Type;
127 Process : not null access procedure (Element : in out Element_Type));
129 procedure Update_Element
130 (Container : in out Vector;
131 Position : Cursor;
132 Process : not null access procedure (Element : in out Element_Type));
134 procedure Move (Target : in out Vector; Source : in out Vector);
136 procedure Insert
137 (Container : in out Vector;
138 Before : Extended_Index;
139 New_Item : Vector);
141 procedure Insert
142 (Container : in out Vector;
143 Before : Cursor;
144 New_Item : Vector);
146 procedure Insert
147 (Container : in out Vector;
148 Before : Cursor;
149 New_Item : Vector;
150 Position : out Cursor);
152 procedure Insert
153 (Container : in out Vector;
154 Before : Extended_Index;
155 New_Item : Element_Type;
156 Count : Count_Type := 1);
158 procedure Insert
159 (Container : in out Vector;
160 Before : Cursor;
161 New_Item : Element_Type;
162 Count : Count_Type := 1);
164 procedure Insert
165 (Container : in out Vector;
166 Before : Cursor;
167 New_Item : Element_Type;
168 Position : out Cursor;
169 Count : Count_Type := 1);
171 procedure Insert
172 (Container : in out Vector;
173 Before : Extended_Index;
174 Count : Count_Type := 1);
176 procedure Insert
177 (Container : in out Vector;
178 Before : Cursor;
179 Position : out Cursor;
180 Count : Count_Type := 1);
182 procedure Prepend
183 (Container : in out Vector;
184 New_Item : Vector);
186 procedure Prepend
187 (Container : in out Vector;
188 New_Item : Element_Type;
189 Count : Count_Type := 1);
191 procedure Append
192 (Container : in out Vector;
193 New_Item : Vector);
195 procedure Append
196 (Container : in out Vector;
197 New_Item : Element_Type;
198 Count : Count_Type := 1);
200 procedure Insert_Space
201 (Container : in out Vector;
202 Before : Extended_Index;
203 Count : Count_Type := 1);
205 procedure Insert_Space
206 (Container : in out Vector;
207 Before : Cursor;
208 Position : out Cursor;
209 Count : Count_Type := 1);
211 procedure Delete
212 (Container : in out Vector;
213 Index : Extended_Index;
214 Count : Count_Type := 1);
216 procedure Delete
217 (Container : in out Vector;
218 Position : in out Cursor;
219 Count : Count_Type := 1);
221 procedure Delete_First
222 (Container : in out Vector;
223 Count : Count_Type := 1);
225 procedure Delete_Last
226 (Container : in out Vector;
227 Count : Count_Type := 1);
229 procedure Reverse_Elements (Container : in out Vector);
231 procedure Swap (Container : in out Vector; I, J : Index_Type);
233 procedure Swap (Container : in out Vector; I, J : Cursor);
235 function First_Index (Container : Vector) return Index_Type;
237 function First (Container : Vector) return Cursor;
239 function First_Element (Container : Vector) return Element_Type;
241 function Last_Index (Container : Vector) return Extended_Index;
243 function Last (Container : Vector) return Cursor;
245 function Last_Element (Container : Vector) return Element_Type;
247 function Next (Position : Cursor) return Cursor;
249 procedure Next (Position : in out Cursor);
251 function Previous (Position : Cursor) return Cursor;
253 procedure Previous (Position : in out Cursor);
255 function Find_Index
256 (Container : Vector;
257 Item : Element_Type;
258 Index : Index_Type := Index_Type'First) return Extended_Index;
260 function Find
261 (Container : Vector;
262 Item : Element_Type;
263 Position : Cursor := No_Element) return Cursor;
265 function Reverse_Find_Index
266 (Container : Vector;
267 Item : Element_Type;
268 Index : Index_Type := Index_Type'Last) return Extended_Index;
270 function Reverse_Find
271 (Container : Vector;
272 Item : Element_Type;
273 Position : Cursor := No_Element) return Cursor;
275 function Contains
276 (Container : Vector;
277 Item : Element_Type) return Boolean;
279 function Has_Element (Position : Cursor) return Boolean;
281 procedure Iterate
282 (Container : Vector;
283 Process : not null access procedure (Position : Cursor));
285 procedure Reverse_Iterate
286 (Container : Vector;
287 Process : not null access procedure (Position : Cursor));
289 generic
290 with function "<" (Left, Right : Element_Type) return Boolean is <>;
291 package Generic_Sorting is
293 function Is_Sorted (Container : Vector) return Boolean;
295 procedure Sort (Container : in out Vector);
297 procedure Merge (Target : in out Vector; Source : in out Vector);
299 end Generic_Sorting;
301 private
303 pragma Inline (First_Index);
304 pragma Inline (Last_Index);
305 pragma Inline (Element);
306 pragma Inline (First_Element);
307 pragma Inline (Last_Element);
308 pragma Inline (Query_Element);
309 pragma Inline (Update_Element);
310 pragma Inline (Replace_Element);
311 pragma Inline (Contains);
313 type Elements_Type is array (Index_Type range <>) of Element_Type;
315 function "=" (L, R : Elements_Type) return Boolean is abstract;
317 type Elements_Access is access Elements_Type;
319 use Ada.Finalization;
321 type Vector is new Controlled with record
322 Elements : Elements_Access;
323 Last : Extended_Index := No_Index;
324 Busy : Natural := 0;
325 Lock : Natural := 0;
326 end record;
328 procedure Adjust (Container : in out Vector);
330 procedure Finalize (Container : in out Vector);
332 use Ada.Streams;
334 procedure Write
335 (Stream : access Root_Stream_Type'Class;
336 Container : Vector);
338 for Vector'Write use Write;
340 procedure Read
341 (Stream : access Root_Stream_Type'Class;
342 Container : out Vector);
344 for Vector'Read use Read;
346 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
348 type Vector_Access is access constant Vector;
349 for Vector_Access'Storage_Size use 0;
351 type Cursor is record
352 Container : Vector_Access;
353 Index : Index_Type := Index_Type'First;
354 end record;
356 procedure Write
357 (Stream : access Root_Stream_Type'Class;
358 Position : Cursor);
360 for Cursor'Write use Write;
362 procedure Read
363 (Stream : access Root_Stream_Type'Class;
364 Position : out Cursor);
366 for Cursor'Read use Read;
368 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
370 end Ada.Containers.Vectors;