OSDN Git Service

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