OSDN Git Service

PR 33870
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-coinve.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --    A D A . C O N T A I N E R S . I N D E F I N I T E _ 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.Indefinite_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 Prepend
176      (Container : in out Vector;
177       New_Item  : Vector);
178
179    procedure Prepend
180      (Container : in out Vector;
181       New_Item  : Element_Type;
182       Count     : Count_Type := 1);
183
184    procedure Append
185      (Container : in out Vector;
186       New_Item  : Vector);
187
188    procedure Append
189      (Container : in out Vector;
190       New_Item  : Element_Type;
191       Count     : Count_Type := 1);
192
193    procedure Insert_Space
194      (Container : in out Vector;
195       Before    : Extended_Index;
196       Count     : Count_Type := 1);
197
198    procedure Insert_Space
199      (Container : in out Vector;
200       Before    : Cursor;
201       Position  : out Cursor;
202       Count     : Count_Type := 1);
203
204    procedure Delete
205      (Container : in out Vector;
206       Index     : Extended_Index;
207       Count     : Count_Type := 1);
208
209    procedure Delete
210      (Container : in out Vector;
211       Position  : in out Cursor;
212       Count     : Count_Type := 1);
213
214    procedure Delete_First
215      (Container : in out Vector;
216       Count     : Count_Type := 1);
217
218    procedure Delete_Last
219      (Container : in out Vector;
220       Count     : Count_Type := 1);
221
222    procedure Reverse_Elements (Container : in out Vector);
223
224    procedure Swap (Container : in out Vector; I, J : Index_Type);
225
226    procedure Swap (Container : in out Vector; I, J : Cursor);
227
228    function First_Index (Container : Vector) return Index_Type;
229
230    function First (Container : Vector) return Cursor;
231
232    function First_Element (Container : Vector) return Element_Type;
233
234    function Last_Index (Container : Vector) return Extended_Index;
235
236    function Last (Container : Vector) return Cursor;
237
238    function Last_Element (Container : Vector) return Element_Type;
239
240    function Next (Position : Cursor) return Cursor;
241
242    procedure Next (Position : in out Cursor);
243
244    function Previous (Position : Cursor) return Cursor;
245
246    procedure Previous (Position : in out Cursor);
247
248    function Find_Index
249      (Container : Vector;
250       Item      : Element_Type;
251       Index     : Index_Type := Index_Type'First) return Extended_Index;
252
253    function Find
254      (Container : Vector;
255       Item      : Element_Type;
256       Position  : Cursor := No_Element) return Cursor;
257
258    function Reverse_Find_Index
259      (Container : Vector;
260       Item      : Element_Type;
261       Index     : Index_Type := Index_Type'Last) return Extended_Index;
262
263    function Reverse_Find
264      (Container : Vector;
265       Item      : Element_Type;
266       Position  : Cursor := No_Element) return Cursor;
267
268    function Contains
269      (Container : Vector;
270       Item      : Element_Type) return Boolean;
271
272    function Has_Element (Position : Cursor) return Boolean;
273
274    procedure Iterate
275      (Container : Vector;
276       Process   : not null access procedure (Position : Cursor));
277
278    procedure Reverse_Iterate
279      (Container : Vector;
280       Process   : not null access procedure (Position : Cursor));
281
282    generic
283       with function "<" (Left, Right : Element_Type) return Boolean is <>;
284    package Generic_Sorting is
285
286       function Is_Sorted (Container : Vector) return Boolean;
287
288       procedure Sort (Container : in out Vector);
289
290       procedure Merge (Target : in out Vector; Source : in out Vector);
291
292    end Generic_Sorting;
293
294 private
295
296    pragma Inline (First_Index);
297    pragma Inline (Last_Index);
298    pragma Inline (Element);
299    pragma Inline (First_Element);
300    pragma Inline (Last_Element);
301    pragma Inline (Query_Element);
302    pragma Inline (Update_Element);
303    pragma Inline (Replace_Element);
304    pragma Inline (Contains);
305    pragma Inline (Next);
306    pragma Inline (Previous);
307
308    type Element_Access is access Element_Type;
309
310    type Elements_Array is array (Index_Type range <>) of Element_Access;
311    function "=" (L, R : Elements_Array) return Boolean is abstract;
312
313    type Elements_Type (Last : Index_Type) is limited record
314       EA : Elements_Array (Index_Type'First .. Last);
315    end record;
316
317    type Elements_Access is access Elements_Type;
318
319    use Ada.Finalization;
320
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;
327
328    overriding
329    procedure Adjust (Container : in out Vector);
330
331    overriding
332    procedure Finalize (Container : in out Vector);
333
334    use Ada.Streams;
335
336    procedure Write
337      (Stream    : not null access Root_Stream_Type'Class;
338       Container : Vector);
339
340    for Vector'Write use Write;
341
342    procedure Read
343      (Stream    : not null access Root_Stream_Type'Class;
344       Container : out Vector);
345
346    for Vector'Read use Read;
347
348    type Vector_Access is access constant Vector;
349    for Vector_Access'Storage_Size use 0;
350
351    type Cursor is record
352       Container : Vector_Access;
353       Index     : Index_Type := Index_Type'First;
354    end record;
355
356    procedure Write
357      (Stream   : not null access Root_Stream_Type'Class;
358       Position : Cursor);
359
360    for Cursor'Write use Write;
361
362    procedure Read
363      (Stream   : not null access Root_Stream_Type'Class;
364       Position : out Cursor);
365
366    for Cursor'Read use Read;
367
368    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
369
370    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
371
372 end Ada.Containers.Indefinite_Vectors;