OSDN Git Service

2006-02-17 Matthew Heaney <heaney@adacore.com>
[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-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;
37
38 generic
39    type Index_Type is range <>;
40    type Element_Type is private;
41
42    with function "=" (Left, Right : Element_Type) return Boolean is <>;
43
44 package Ada.Containers.Vectors is
45    pragma Preelaborate;
46
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;
50
51    No_Index : constant Extended_Index := Extended_Index'First;
52
53    type Vector is tagged private;
54
55    type Cursor is private;
56
57    Empty_Vector : constant Vector;
58
59    No_Element : constant Cursor;
60
61    function "=" (Left, Right : Vector) return Boolean;
62
63    function To_Vector (Length : Count_Type) return Vector;
64
65    function To_Vector
66      (New_Item : Element_Type;
67       Length   : Count_Type) return Vector;
68
69    function "&" (Left, Right : Vector) return Vector;
70
71    function "&" (Left : Vector; Right : Element_Type) return Vector;
72
73    function "&" (Left : Element_Type; Right : Vector) return Vector;
74
75    function "&" (Left, Right : Element_Type) return Vector;
76
77    function Capacity (Container : Vector) return Count_Type;
78
79    procedure Reserve_Capacity
80      (Container : in out Vector;
81       Capacity  : Count_Type);
82
83    function Length (Container : Vector) return Count_Type;
84
85    procedure Set_Length
86      (Container : in out Vector;
87       Length    : 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 Replace_Element
106      (Container : in out Vector;
107       Index     : Index_Type;
108       New_Item  : Element_Type);
109
110    procedure Replace_Element
111      (Container : in out Vector;
112       Position  : Cursor;
113       New_Item  : Element_Type);
114
115    procedure Query_Element
116      (Container : Vector;
117       Index     : Index_Type;
118       Process   : not null access procedure (Element : Element_Type));
119
120    procedure Query_Element
121      (Position : Cursor;
122       Process  : not null access procedure (Element : Element_Type));
123
124    procedure Update_Element
125      (Container : in out Vector;
126       Index     : Index_Type;
127       Process   : not null access procedure (Element : in out Element_Type));
128
129    procedure Update_Element
130      (Container : in out Vector;
131       Position  : Cursor;
132       Process   : not null access procedure (Element : in out Element_Type));
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 Insert
172      (Container : in out Vector;
173       Before    : Extended_Index;
174       Count     : Count_Type := 1);
175
176    procedure Insert
177      (Container : in out Vector;
178       Before    : Cursor;
179       Position  : out Cursor;
180       Count     : Count_Type := 1);
181
182    procedure Prepend
183      (Container : in out Vector;
184       New_Item  : Vector);
185
186    procedure Prepend
187      (Container : in out Vector;
188       New_Item  : Element_Type;
189       Count     : Count_Type := 1);
190
191    procedure Append
192      (Container : in out Vector;
193       New_Item  : Vector);
194
195    procedure Append
196      (Container : in out Vector;
197       New_Item  : Element_Type;
198       Count     : Count_Type := 1);
199
200    procedure Insert_Space
201      (Container : in out Vector;
202       Before    : Extended_Index;
203       Count     : Count_Type := 1);
204
205    procedure Insert_Space
206      (Container : in out Vector;
207       Before    : Cursor;
208       Position  : out Cursor;
209       Count     : Count_Type := 1);
210
211    procedure Delete
212      (Container : in out Vector;
213       Index     : Extended_Index;
214       Count     : Count_Type := 1);
215
216    procedure Delete
217      (Container : in out Vector;
218       Position  : in out Cursor;
219       Count     : Count_Type := 1);
220
221    procedure Delete_First
222      (Container : in out Vector;
223       Count     : Count_Type := 1);
224
225    procedure Delete_Last
226      (Container : in out Vector;
227       Count     : Count_Type := 1);
228
229    procedure Reverse_Elements (Container : in out Vector);
230
231    procedure Swap (Container : in out Vector; I, J : Index_Type);
232
233    procedure Swap (Container : in out Vector; I, J : Cursor);
234
235    function First_Index (Container : Vector) return Index_Type;
236
237    function First (Container : Vector) return Cursor;
238
239    function First_Element (Container : Vector) return Element_Type;
240
241    function Last_Index (Container : Vector) return Extended_Index;
242
243    function Last (Container : Vector) return Cursor;
244
245    function Last_Element (Container : Vector) return Element_Type;
246
247    function Next (Position : Cursor) return Cursor;
248
249    procedure Next (Position : in out Cursor);
250
251    function Previous (Position : Cursor) return Cursor;
252
253    procedure Previous (Position : in out Cursor);
254
255    function Find_Index
256      (Container : Vector;
257       Item      : Element_Type;
258       Index     : Index_Type := Index_Type'First) return Extended_Index;
259
260    function Find
261      (Container : Vector;
262       Item      : Element_Type;
263       Position  : Cursor := No_Element) return Cursor;
264
265    function Reverse_Find_Index
266      (Container : Vector;
267       Item      : Element_Type;
268       Index     : Index_Type := Index_Type'Last) return Extended_Index;
269
270    function Reverse_Find
271      (Container : Vector;
272       Item      : Element_Type;
273       Position  : Cursor := No_Element) return Cursor;
274
275    function Contains
276      (Container : Vector;
277       Item      : Element_Type) return Boolean;
278
279    function Has_Element (Position : Cursor) return Boolean;
280
281    procedure Iterate
282      (Container : Vector;
283       Process   : not null access procedure (Position : Cursor));
284
285    procedure Reverse_Iterate
286      (Container : Vector;
287       Process   : not null access procedure (Position : Cursor));
288
289    generic
290       with function "<" (Left, Right : Element_Type) return Boolean is <>;
291    package Generic_Sorting is
292
293       function Is_Sorted (Container : Vector) return Boolean;
294
295       procedure Sort (Container : in out Vector);
296
297       procedure Merge (Target : in out Vector; Source : in out Vector);
298
299    end Generic_Sorting;
300
301 private
302
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);
312
313    type Elements_Type is array (Index_Type range <>) of Element_Type;
314
315    function "=" (L, R : Elements_Type) return Boolean is abstract;
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    procedure Adjust (Container : in out Vector);
329
330    procedure Finalize (Container : in out Vector);
331
332    use Ada.Streams;
333
334    procedure Write
335      (Stream    : not null access Root_Stream_Type'Class;
336       Container : Vector);
337
338    for Vector'Write use Write;
339
340    procedure Read
341      (Stream    : not null access Root_Stream_Type'Class;
342       Container : out Vector);
343
344    for Vector'Read use Read;
345
346    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
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    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
369
370 end Ada.Containers.Vectors;