OSDN Git Service

2005-06-14 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,  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;
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    package Generic_Sorting is
238
239       function Is_Sorted (Container : Vector) return Boolean;
240
241       procedure Sort (Container : in out Vector);
242
243       procedure Merge (Target, Source : in out Vector);
244
245    end Generic_Sorting;
246
247    function Find_Index
248      (Container : Vector;
249       Item      : Element_Type;
250       Index     : Index_Type := Index_Type'First) return Extended_Index;
251
252    function Find
253      (Container : Vector;
254       Item      : Element_Type;
255       Position  : Cursor := No_Element) return Cursor;
256
257    function Reverse_Find_Index
258      (Container : Vector;
259       Item      : Element_Type;
260       Index     : Index_Type := Index_Type'Last) return Extended_Index;
261
262    function Reverse_Find
263      (Container : Vector;
264       Item      : Element_Type;
265       Position  : Cursor := No_Element) return Cursor;
266
267    function Contains
268      (Container : Vector;
269       Item      : Element_Type) return Boolean;
270
271    function Next (Position : Cursor) return Cursor;
272
273    function Previous (Position : Cursor) return Cursor;
274
275    procedure Next (Position : in out Cursor);
276
277    procedure Previous (Position : in out Cursor);
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 private
290
291    pragma Inline (First_Index);
292    pragma Inline (Last_Index);
293    pragma Inline (Element);
294    pragma Inline (First_Element);
295    pragma Inline (Last_Element);
296    pragma Inline (Query_Element);
297    pragma Inline (Update_Element);
298    pragma Inline (Replace_Element);
299    pragma Inline (Contains);
300
301    type Elements_Type is array (Index_Type range <>) of Element_Type;
302
303    function "=" (L, R : Elements_Type) return Boolean is abstract;
304
305    type Elements_Access is access Elements_Type;
306
307    use Ada.Finalization;
308
309    type Vector is new Controlled with record
310       Elements : Elements_Access;
311       Last     : Extended_Index := No_Index;
312       Busy     : Natural := 0;
313       Lock     : Natural := 0;
314    end record;
315
316    procedure Adjust (Container : in out Vector);
317
318    procedure Finalize (Container : in out Vector);
319
320    use Ada.Streams;
321
322    procedure Write
323      (Stream    : access Root_Stream_Type'Class;
324       Container : Vector);
325
326    for Vector'Write use Write;
327
328    procedure Read
329      (Stream    : access Root_Stream_Type'Class;
330       Container : out Vector);
331
332    for Vector'Read use Read;
333
334    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
335
336    type Vector_Access is access constant Vector;
337    for Vector_Access'Storage_Size use 0;
338
339    type Cursor is record
340       Container : Vector_Access;
341       Index     : Index_Type := Index_Type'First;
342    end record;
343
344    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
345
346 end Ada.Containers.Vectors;