OSDN Git Service

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