OSDN Git Service

2005-03-08 Geert Bosch <bosch@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-convec.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                          ADA.CONTAINERS.VECTORS                          --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --             Copyright (C) 2004 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,  59 Temple Place - Suite 330,  Boston, --
24 -- MA 02111-1307, 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 (Vectors);
46
47    subtype Extended_Index is Index_Type'Base
48      range Index_Type'First - 1 ..
49            Index_Type'Last +
50               Boolean'Pos (Index_Type'Base'Last > Index_Type'Last);
51
52    No_Index : constant Extended_Index := Extended_Index'First;
53
54    subtype Index_Subtype is Index_Type;
55
56    type Vector is tagged private;
57
58    type Cursor is private;
59
60    Empty_Vector : constant Vector;
61
62    No_Element : constant Cursor;
63
64    function To_Vector (Length : Count_Type) return Vector;
65
66    function To_Vector
67      (New_Item : Element_Type;
68       Length   : Count_Type) return Vector;
69
70    function "&" (Left, Right : Vector) return Vector;
71
72    function "&" (Left : Vector; Right : Element_Type) return Vector;
73
74    function "&" (Left : Element_Type; Right : Vector) return Vector;
75
76    function "&" (Left, Right : Element_Type) return Vector;
77
78    function "=" (Left, Right : Vector) return Boolean;
79
80    function Capacity (Container : Vector) return Count_Type;
81
82    procedure Reserve_Capacity
83      (Container : in out Vector;
84       Capacity  : Count_Type);
85
86    function Length (Container : Vector) return Count_Type;
87
88    function Is_Empty (Container : Vector) return Boolean;
89
90    procedure Clear (Container : in out Vector);
91
92    function To_Cursor
93      (Container : Vector;
94       Index     : Extended_Index) return Cursor;
95
96    function To_Index (Position : Cursor) return Extended_Index;
97
98    function Element
99      (Container : Vector;
100       Index     : Index_Type) return Element_Type;
101
102    function Element (Position : Cursor) return Element_Type;
103
104    procedure Query_Element
105      (Container : Vector;
106       Index     : Index_Type;
107       Process   : not null access procedure (Element : Element_Type));
108
109    procedure Query_Element
110      (Position : Cursor;
111       Process  : not null access procedure (Element : Element_Type));
112
113    procedure Update_Element
114      (Container : Vector;
115       Index     : Index_Type;
116       Process   : not null access procedure (Element : in out Element_Type));
117
118    procedure Update_Element
119      (Position : Cursor;
120       Process  : not null access procedure (Element : in out Element_Type));
121
122    procedure Replace_Element
123      (Container : Vector;
124       Index     : Index_Type;
125       By        : Element_Type);
126
127    procedure Replace_Element (Position : Cursor; By : Element_Type);
128
129    procedure Assign (Target : in out Vector; Source : Vector);
130
131    procedure Move (Target : in out Vector; Source : in out Vector);
132
133    procedure Insert
134      (Container : in out Vector;
135       Before    : Extended_Index;
136       New_Item  : Vector);
137
138    procedure Insert
139      (Container : in out Vector;
140       Before    : Cursor;
141       New_Item  : Vector);
142
143    procedure Insert
144      (Container : in out Vector;
145       Before    : Cursor;
146       New_Item  : Vector;
147       Position  : out Cursor);
148
149    procedure Insert
150      (Container : in out Vector;
151       Before    : Extended_Index;
152       New_Item  : Element_Type;
153       Count     : Count_Type := 1);
154
155    procedure Insert
156      (Container : in out Vector;
157       Before    : Cursor;
158       New_Item  : Element_Type;
159       Count     : Count_Type := 1);
160
161    procedure Insert
162      (Container : in out Vector;
163       Before    : Cursor;
164       New_Item  : Element_Type;
165       Position  : out Cursor;
166       Count     : Count_Type := 1);
167
168    procedure Prepend
169      (Container : in out Vector;
170       New_Item  : Vector);
171
172    procedure Prepend
173      (Container : in out Vector;
174       New_Item  : Element_Type;
175       Count     : Count_Type := 1);
176
177    procedure Append
178      (Container : in out Vector;
179       New_Item  : Vector);
180
181    procedure Append
182      (Container : in out Vector;
183       New_Item  : Element_Type;
184       Count     : Count_Type := 1);
185
186    procedure Insert_Space
187      (Container : in out Vector;
188       Before    : Extended_Index;
189       Count     : Count_Type := 1);
190
191    procedure Insert_Space
192      (Container : in out Vector;
193       Before    : Cursor;
194       Position  : out Cursor;
195       Count     : Count_Type := 1);
196
197    procedure Set_Length
198      (Container : in out Vector;
199       Length    : Count_Type);
200
201    procedure Delete
202      (Container : in out Vector;
203       Index     : Extended_Index;  --  TODO: verify
204       Count     : Count_Type := 1);
205
206    procedure Delete
207      (Container : in out Vector;
208       Position  : in out Cursor;
209       Count     : Count_Type := 1);
210
211    procedure Delete_First
212      (Container : in out Vector;
213       Count     : Count_Type := 1);
214
215    procedure Delete_Last
216      (Container : in out Vector;
217       Count     : Count_Type := 1);
218
219    function First_Index (Container : Vector) return Index_Type;
220
221    function First (Container : Vector) return Cursor;
222
223    function First_Element (Container : Vector) return Element_Type;
224
225    function Last_Index (Container : Vector) return Extended_Index;
226
227    function Last (Container : Vector) return Cursor;
228
229    function Last_Element (Container : Vector) return Element_Type;
230
231    procedure Swap (Container : Vector; I, J : Index_Type);
232
233    procedure Swap (I, J : Cursor);
234
235    generic
236       with function "<" (Left, Right : Element_Type) return Boolean is <>;
237    procedure Generic_Sort (Container : Vector);
238
239    function Find_Index
240      (Container : Vector;
241       Item      : Element_Type;
242       Index     : Index_Type := Index_Type'First) return Extended_Index;
243
244    function Find
245      (Container : Vector;
246       Item      : Element_Type;
247       Position  : Cursor := No_Element) return Cursor;
248
249    function Reverse_Find_Index
250      (Container : Vector;
251       Item      : Element_Type;
252       Index     : Index_Type := Index_Type'Last) return Extended_Index;
253
254    function Reverse_Find
255      (Container : Vector;
256       Item      : Element_Type;
257       Position  : Cursor := No_Element) return Cursor;
258
259    function Contains
260      (Container : Vector;
261       Item      : Element_Type) return Boolean;
262
263    function Next (Position : Cursor) return Cursor;
264
265    function Previous (Position : Cursor) return Cursor;
266
267    procedure Next (Position : in out Cursor);
268
269    procedure Previous (Position : in out Cursor);
270
271    function Has_Element (Position : Cursor) return Boolean;
272
273    procedure Iterate
274      (Container : Vector;
275       Process   : not null access procedure (Position : Cursor));
276
277    procedure Reverse_Iterate
278      (Container : Vector;
279       Process   : not null access procedure (Position : Cursor));
280
281 private
282
283    pragma Inline (First_Index);
284    pragma Inline (Last_Index);
285    pragma Inline (Element);
286    pragma Inline (First_Element);
287    pragma Inline (Last_Element);
288    pragma Inline (Query_Element);
289    pragma Inline (Update_Element);
290    pragma Inline (Replace_Element);
291    pragma Inline (Contains);
292
293    type Elements_Type is array (Index_Type range <>) of Element_Type;
294
295    function "=" (L, R : Elements_Type) return Boolean is abstract;
296
297    type Elements_Access is access Elements_Type;
298
299    use Ada.Finalization;
300
301    type Vector is new Controlled with record
302       Elements : Elements_Access;
303       Last     : Extended_Index := No_Index;
304    end record;
305
306    procedure Adjust (Container : in out Vector);
307
308    procedure Finalize (Container : in out Vector);
309
310    use Ada.Streams;
311
312    procedure Write
313      (Stream    : access Root_Stream_Type'Class;
314       Container : Vector);
315
316    for Vector'Write use Write;
317
318    procedure Read
319      (Stream    : access Root_Stream_Type'Class;
320       Container : out Vector);
321
322    for Vector'Read use Read;
323
324    Empty_Vector : constant Vector := (Controlled with null, No_Index);
325
326    type Vector_Access is access constant Vector;
327    for Vector_Access'Storage_Size use 0;
328
329    type Cursor is record
330       Container : Vector_Access;
331       Index     : Index_Type := Index_Type'First;
332    end record;
333
334    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
335
336 end Ada.Containers.Vectors;