OSDN Git Service

2007-04-20 Robert Dewar <dewar@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-2006, 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    type Element_Type (<>) is private;
42
43    with function "=" (Left, Right : Element_Type) return Boolean is <>;
44
45 package Ada.Containers.Indefinite_Vectors is
46    pragma Preelaborate;
47
48    subtype Extended_Index is Index_Type'Base
49      range Index_Type'First - 1 ..
50            Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
51
52    No_Index : constant Extended_Index := Extended_Index'First;
53
54    type Vector is tagged private;
55    pragma Preelaborable_Initialization (Vector);
56
57    type Cursor is private;
58    pragma Preelaborable_Initialization (Cursor);
59
60    Empty_Vector : constant Vector;
61
62    No_Element : constant Cursor;
63
64    function "=" (Left, Right : Vector) return Boolean;
65
66    function To_Vector (Length : Count_Type) return Vector;
67
68    function To_Vector
69      (New_Item : Element_Type;
70       Length   : Count_Type) return Vector;
71
72    function "&" (Left, Right : Vector) return Vector;
73
74    function "&" (Left : Vector; Right : Element_Type) return Vector;
75
76    function "&" (Left : Element_Type; Right : Vector) return Vector;
77
78    function "&" (Left, Right : Element_Type) return Vector;
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    procedure Set_Length
89      (Container : in out Vector;
90       Length    : Count_Type);
91
92    function Is_Empty (Container : Vector) return Boolean;
93
94    procedure Clear (Container : in out Vector);
95
96    function To_Cursor
97      (Container : Vector;
98       Index     : Extended_Index) return Cursor;
99
100    function To_Index (Position : Cursor) return Extended_Index;
101
102    function Element
103      (Container : Vector;
104       Index     : Index_Type) return Element_Type;
105
106    function Element (Position : Cursor) return Element_Type;
107
108    procedure Replace_Element
109      (Container : in out Vector;
110       Index     : Index_Type;
111       New_Item  : Element_Type);
112
113    procedure Replace_Element
114      (Container : in out Vector;
115       Position  : Cursor;
116       New_Item  : Element_Type);
117
118    procedure Query_Element
119      (Container : Vector;
120       Index     : Index_Type;
121       Process   : not null access procedure (Element : Element_Type));
122
123    procedure Query_Element
124      (Position : Cursor;
125       Process  : not null access procedure (Element : Element_Type));
126
127    procedure Update_Element
128      (Container : in out Vector;
129       Index     : Index_Type;
130       Process   : not null access procedure (Element : in out Element_Type));
131
132    procedure Update_Element
133      (Container : in out Vector;
134       Position  : Cursor;
135       Process   : not null access procedure (Element : in out Element_Type));
136
137    procedure Move (Target : in out Vector; Source : in out Vector);
138
139    procedure Insert
140      (Container : in out Vector;
141       Before    : Extended_Index;
142       New_Item  : Vector);
143
144    procedure Insert
145      (Container : in out Vector;
146       Before    : Cursor;
147       New_Item  : Vector);
148
149    procedure Insert
150      (Container : in out Vector;
151       Before    : Cursor;
152       New_Item  : Vector;
153       Position  : out Cursor);
154
155    procedure Insert
156      (Container : in out Vector;
157       Before    : Extended_Index;
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       Count     : Count_Type := 1);
166
167    procedure Insert
168      (Container : in out Vector;
169       Before    : Cursor;
170       New_Item  : Element_Type;
171       Position  : out Cursor;
172       Count     : Count_Type := 1);
173
174    procedure Prepend
175      (Container : in out Vector;
176       New_Item  : Vector);
177
178    procedure Prepend
179      (Container : in out Vector;
180       New_Item  : Element_Type;
181       Count     : Count_Type := 1);
182
183    procedure Append
184      (Container : in out Vector;
185       New_Item  : Vector);
186
187    procedure Append
188      (Container : in out Vector;
189       New_Item  : Element_Type;
190       Count     : Count_Type := 1);
191
192    procedure Insert_Space
193      (Container : in out Vector;
194       Before    : Extended_Index;
195       Count     : Count_Type := 1);
196
197    procedure Insert_Space
198      (Container : in out Vector;
199       Before    : Cursor;
200       Position  : out Cursor;
201       Count     : Count_Type := 1);
202
203    procedure Delete
204      (Container : in out Vector;
205       Index     : Extended_Index;
206       Count     : Count_Type := 1);
207
208    procedure Delete
209      (Container : in out Vector;
210       Position  : in out Cursor;
211       Count     : Count_Type := 1);
212
213    procedure Delete_First
214      (Container : in out Vector;
215       Count     : Count_Type := 1);
216
217    procedure Delete_Last
218      (Container : in out Vector;
219       Count     : Count_Type := 1);
220
221    procedure Reverse_Elements (Container : in out Vector);
222
223    procedure Swap (Container : in out Vector; I, J : Index_Type);
224
225    procedure Swap (Container : in out Vector; I, J : Cursor);
226
227    function First_Index (Container : Vector) return Index_Type;
228
229    function First (Container : Vector) return Cursor;
230
231    function First_Element (Container : Vector) return Element_Type;
232
233    function Last_Index (Container : Vector) return Extended_Index;
234
235    function Last (Container : Vector) return Cursor;
236
237    function Last_Element (Container : Vector) return Element_Type;
238
239    function Next (Position : Cursor) return Cursor;
240
241    procedure Next (Position : in out Cursor);
242
243    function Previous (Position : Cursor) return Cursor;
244
245    procedure Previous (Position : in out Cursor);
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 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    generic
282       with function "<" (Left, Right : Element_Type) return Boolean is <>;
283    package Generic_Sorting is
284
285       function Is_Sorted (Container : Vector) return Boolean;
286
287       procedure Sort (Container : in out Vector);
288
289       procedure Merge (Target : in out Vector; Source : in out Vector);
290
291    end Generic_Sorting;
292
293 private
294
295    pragma Inline (First_Index);
296    pragma Inline (Last_Index);
297    pragma Inline (Element);
298    pragma Inline (First_Element);
299    pragma Inline (Last_Element);
300    pragma Inline (Query_Element);
301    pragma Inline (Update_Element);
302    pragma Inline (Replace_Element);
303    pragma Inline (Contains);
304
305    type Element_Access is access Element_Type;
306
307    type Elements_Type is array (Index_Type range <>) of Element_Access;
308
309    function "=" (L, R : Elements_Type) return Boolean is abstract;
310
311    type Elements_Access is access Elements_Type;
312
313    use Ada.Finalization;
314
315    type Vector is new Controlled with record
316       Elements : Elements_Access;
317       Last     : Extended_Index := No_Index;
318       Busy     : Natural := 0;
319       Lock     : Natural := 0;
320    end record;
321
322    procedure Adjust (Container : in out Vector);
323
324    procedure Finalize (Container : in out Vector);
325
326    use Ada.Streams;
327
328    procedure Write
329      (Stream    : not null access Root_Stream_Type'Class;
330       Container : Vector);
331
332    for Vector'Write use Write;
333
334    procedure Read
335      (Stream    : not null access Root_Stream_Type'Class;
336       Container : out Vector);
337
338    for Vector'Read use Read;
339
340    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
341
342    type Vector_Access is access constant Vector;
343    for Vector_Access'Storage_Size use 0;
344
345    type Cursor is record
346       Container : Vector_Access;
347       Index     : Index_Type := Index_Type'First;
348    end record;
349
350    procedure Write
351      (Stream   : not null access Root_Stream_Type'Class;
352       Position : Cursor);
353
354    for Cursor'Write use Write;
355
356    procedure Read
357      (Stream   : not null access Root_Stream_Type'Class;
358       Position : out Cursor);
359
360    for Cursor'Read use Read;
361
362    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
363
364 end Ada.Containers.Indefinite_Vectors;