OSDN Git Service

2005-07-04 Matthew Heaney <heaney@adacore.com>
[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-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
36 with Ada.Finalization;
37 with Ada.Streams;
38
39 generic
40    type Index_Type is range <>;
41
42    type Element_Type (<>) is private;
43
44    with function "=" (Left, Right : Element_Type) return Boolean is <>;
45
46 package Ada.Containers.Indefinite_Vectors is
47 pragma Preelaborate (Indefinite_Vectors);
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    subtype Index_Subtype is Index_Type;
56
57    type Vector is tagged private;
58
59    type Cursor is private;
60
61    Empty_Vector : constant Vector;
62
63    No_Element : constant Cursor;
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 "=" (Left, Right : Vector) return Boolean;
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    function Is_Empty (Container : Vector) return Boolean;
90
91    procedure Clear (Container : in out Vector);
92
93    function To_Cursor
94      (Container : Vector;
95       Index     : Extended_Index) return Cursor;
96
97    function To_Index (Position : Cursor) return Extended_Index;
98
99    function Element
100      (Container : Vector;
101       Index     : Index_Type) return Element_Type;
102
103    function Element (Position : Cursor) return Element_Type;
104
105    procedure Query_Element
106      (Container : Vector;
107       Index     : Index_Type;
108       Process   : not null access procedure (Element : Element_Type));
109
110    procedure Query_Element
111      (Position : Cursor;
112       Process  : not null access procedure (Element : Element_Type));
113
114    procedure Update_Element
115      (Container : Vector;
116       Index     : Index_Type;
117       Process   : not null access procedure (Element : in out Element_Type));
118
119    procedure Update_Element
120      (Position : Cursor;
121       Process  : not null access procedure (Element : in out Element_Type));
122
123    procedure Replace_Element
124      (Container : Vector;
125       Index     : Index_Type;
126       By        : Element_Type);
127
128    procedure Replace_Element
129      (Position : Cursor;
130       By       : Element_Type);
131
132    procedure Assign (Target : in out Vector; Source : Vector);
133
134    procedure Move (Target : in out Vector; Source : in out Vector);
135
136    procedure Insert
137      (Container : in out Vector;
138       Before    : Extended_Index;
139       New_Item  : Vector);
140
141    procedure Insert
142      (Container : in out Vector;
143       Before    : Cursor;
144       New_Item  : Vector);
145
146    procedure Insert
147      (Container : in out Vector;
148       Before    : Cursor;
149       New_Item  : Vector;
150       Position  : out Cursor);
151
152    procedure Insert
153      (Container : in out Vector;
154       Before    : Extended_Index;
155       New_Item  : Element_Type;
156       Count     : Count_Type := 1);
157
158    procedure Insert
159      (Container : in out Vector;
160       Before    : Cursor;
161       New_Item  : Element_Type;
162       Count     : Count_Type := 1);
163
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);
170
171    procedure Prepend
172      (Container : in out Vector;
173       New_Item  : Vector);
174
175    procedure Prepend
176      (Container : in out Vector;
177       New_Item  : Element_Type;
178       Count     : Count_Type := 1);
179
180    procedure Append
181      (Container : in out Vector;
182       New_Item  : Vector);
183
184    procedure Append
185      (Container : in out Vector;
186       New_Item  : Element_Type;
187       Count     : Count_Type := 1);
188
189    procedure Insert_Space
190      (Container : in out Vector;
191       Before    : Extended_Index;
192       Count     : Count_Type := 1);
193
194    procedure Insert_Space
195      (Container : in out Vector;
196       Before    : Cursor;
197       Position  : out Cursor;
198       Count     : Count_Type := 1);
199
200    procedure Set_Length
201      (Container : in out Vector;
202       Length    : Count_Type);
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    function First_Index (Container : Vector) return Index_Type;
223
224    function First (Container : Vector) return Cursor;
225
226    function First_Element (Container : Vector) return Element_Type;
227
228    function Last_Index (Container : Vector) return Extended_Index;
229
230    function Last (Container : Vector) return Cursor;
231
232    function Last_Element (Container : Vector) return Element_Type;
233
234    procedure Swap (Container : Vector; I, J : Index_Type);
235
236    procedure Swap (I, J : Cursor);
237
238    generic
239       with function "<" (Left, Right : Element_Type) return Boolean is <>;
240    package Generic_Sorting is
241
242       function Is_Sorted (Container : Vector) return Boolean;
243
244       procedure Sort (Container : in out Vector);
245
246       procedure Merge (Target, Source : in out Vector);
247
248    end Generic_Sorting;
249
250    function Find_Index
251      (Container : Vector;
252       Item      : Element_Type;
253       Index     : Index_Type := Index_Type'First) return Extended_Index;
254
255    function Find
256      (Container : Vector;
257       Item      : Element_Type;
258        Position  : Cursor := No_Element) return Cursor;
259
260    function Reverse_Find_Index
261      (Container : Vector;
262       Item      : Element_Type;
263       Index     : Index_Type := Index_Type'Last) return Extended_Index;
264
265    function Reverse_Find (Container : Vector;
266                           Item      : Element_Type;
267                           Position  : Cursor := No_Element)
268       return Cursor;
269
270    function Contains
271      (Container : Vector;
272       Item      : Element_Type) return Boolean;
273
274    function Next (Position : Cursor) return Cursor;
275
276    function Previous (Position : Cursor) return Cursor;
277
278    procedure Next (Position : in out Cursor);
279
280    procedure Previous (Position : in out Cursor);
281
282    function Has_Element (Position : Cursor) return Boolean;
283
284    procedure Iterate
285      (Container : Vector;
286       Process   : not null access procedure (Position : Cursor));
287
288    procedure Reverse_Iterate
289      (Container : Vector;
290       Process   : not null access procedure (Position : Cursor));
291
292 private
293
294    pragma Inline (First_Index);
295    pragma Inline (Last_Index);
296    pragma Inline (Element);
297    pragma Inline (First_Element);
298    pragma Inline (Last_Element);
299    pragma Inline (Query_Element);
300    pragma Inline (Update_Element);
301    pragma Inline (Replace_Element);
302    pragma Inline (Contains);
303
304    type Element_Access is access Element_Type;
305
306    type Elements_Type is array (Index_Type range <>) of Element_Access;
307
308    function "=" (L, R : Elements_Type) return Boolean is abstract;
309
310    type Elements_Access is access Elements_Type;
311
312    use Ada.Finalization;
313
314    type Vector is new Controlled with record
315       Elements : Elements_Access;
316       Last     : Extended_Index := No_Index;
317       Busy     : Natural := 0;
318       Lock     : Natural := 0;
319    end record;
320
321    procedure Adjust (Container : in out Vector);
322
323    procedure Finalize (Container : in out Vector);
324
325    use Ada.Streams;
326
327    procedure Write
328      (Stream    : access Root_Stream_Type'Class;
329       Container : Vector);
330
331    for Vector'Write use Write;
332
333    procedure Read
334      (Stream    : access Root_Stream_Type'Class;
335       Container : out Vector);
336
337    for Vector'Read use Read;
338
339    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
340
341    type Vector_Access is access constant Vector;
342    for Vector_Access'Storage_Size use 0;
343
344    type Cursor is record
345       Container : Vector_Access;
346       Index     : Index_Type := Index_Type'First;
347    end record;
348
349    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
350
351 end Ada.Containers.Indefinite_Vectors;