OSDN Git Service

2011-09-06 Ed Schonberg <schonberg@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-2011, 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 3,  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.                                     --
21 --                                                                          --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception,   --
24 -- version 3.1, as published by the Free Software Foundation.               --
25 --                                                                          --
26 -- You should have received a copy of the GNU General Public License and    --
27 -- a copy of the GCC Runtime Library Exception along with this program;     --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29 -- <http://www.gnu.org/licenses/>.                                          --
30 --                                                                          --
31 -- This unit was originally developed by Matthew J Heaney.                  --
32 ------------------------------------------------------------------------------
33
34 private with Ada.Finalization;
35
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
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    pragma Remote_Types;
48
49    subtype Extended_Index is Index_Type'Base
50      range Index_Type'First - 1 ..
51            Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
52
53    No_Index : constant Extended_Index := Extended_Index'First;
54
55    type Vector is tagged private
56    with
57      Constant_Indexing => Constant_Reference,
58      Variable_Indexing => Reference,
59      Default_Iterator  => Iterate,
60      Iterator_Element  => Element_Type;
61
62    pragma Preelaborable_Initialization (Vector);
63
64    type Cursor is private;
65    pragma Preelaborable_Initialization (Cursor);
66
67    Empty_Vector : constant Vector;
68
69    No_Element : constant Cursor;
70    function Has_Element (Position : Cursor) return Boolean;
71
72    procedure Read
73      (Stream   : not null access Root_Stream_Type'Class;
74       Position : out Cursor);
75
76    for Cursor'Read use Read;
77
78    procedure Write
79      (Stream   : not null access Root_Stream_Type'Class;
80       Position : Cursor);
81
82    for Cursor'Write use Write;
83
84    package Vector_Iterator_Interfaces is new
85      Ada.Iterator_Interfaces (Cursor, Has_Element);
86
87    overriding function "=" (Left, Right : Vector) return Boolean;
88
89    function To_Vector (Length : Count_Type) return Vector;
90
91    function To_Vector
92      (New_Item : Element_Type;
93       Length   : Count_Type) return Vector;
94
95    function "&" (Left, Right : Vector) return Vector;
96
97    function "&" (Left : Vector; Right : Element_Type) return Vector;
98
99    function "&" (Left : Element_Type; Right : Vector) return Vector;
100
101    function "&" (Left, Right : Element_Type) return Vector;
102
103    function Capacity (Container : Vector) return Count_Type;
104
105    procedure Reserve_Capacity
106      (Container : in out Vector;
107       Capacity  : Count_Type);
108
109    function Length (Container : Vector) return Count_Type;
110
111    procedure Set_Length
112      (Container : in out Vector;
113       Length    : Count_Type);
114
115    function Is_Empty (Container : Vector) return Boolean;
116
117    procedure Clear (Container : in out Vector);
118
119    type Constant_Reference_Type
120       (Element : not null access constant Element_Type) is private
121    with
122       Implicit_Dereference => Element;
123
124    procedure Write
125      (Stream : not null access Root_Stream_Type'Class;
126       Item   : Constant_Reference_Type);
127
128    for Constant_Reference_Type'Write use Write;
129
130    procedure Read
131      (Stream : not null access Root_Stream_Type'Class;
132       Item   : out Constant_Reference_Type);
133
134    for Constant_Reference_Type'Read use Read;
135
136    type Reference_Type (Element : not null access Element_Type) is private
137    with
138       Implicit_Dereference => Element;
139
140    procedure Write
141      (Stream : not null access Root_Stream_Type'Class;
142       Item   : Reference_Type);
143
144    for Reference_Type'Write use Write;
145
146    procedure Read
147      (Stream : not null access Root_Stream_Type'Class;
148       Item   : out Reference_Type);
149
150    for Reference_Type'Read use Read;
151
152    function Constant_Reference
153      (Container : Vector; Position : Cursor)    --  SHOULD BE ALIASED
154    return Constant_Reference_Type;
155
156    function Constant_Reference
157      (Container : Vector; Position : Index_Type)
158    return Constant_Reference_Type;
159
160    function Reference (Container : Vector; Position : Cursor)
161    return Reference_Type;
162
163    function Reference (Container : Vector; Position : Index_Type)
164    return Reference_Type;
165
166    function To_Cursor
167      (Container : Vector;
168       Index     : Extended_Index) return Cursor;
169
170    function To_Index (Position : Cursor) return Extended_Index;
171
172    function Element
173      (Container : Vector;
174       Index     : Index_Type) return Element_Type;
175
176    function Element (Position : Cursor) return Element_Type;
177
178    procedure Replace_Element
179      (Container : in out Vector;
180       Index     : Index_Type;
181       New_Item  : Element_Type);
182
183    procedure Replace_Element
184      (Container : in out Vector;
185       Position  : Cursor;
186       New_Item  : Element_Type);
187
188    procedure Query_Element
189      (Container : Vector;
190       Index     : Index_Type;
191       Process   : not null access procedure (Element : Element_Type));
192
193    procedure Query_Element
194      (Position : Cursor;
195       Process  : not null access procedure (Element : Element_Type));
196
197    procedure Update_Element
198      (Container : in out Vector;
199       Index     : Index_Type;
200       Process   : not null access procedure (Element : in out Element_Type));
201
202    procedure Update_Element
203      (Container : in out Vector;
204       Position  : Cursor;
205       Process   : not null access procedure (Element : in out Element_Type));
206
207    procedure Move (Target : in out Vector; Source : in out Vector);
208
209    procedure Insert
210      (Container : in out Vector;
211       Before    : Extended_Index;
212       New_Item  : Vector);
213
214    procedure Insert
215      (Container : in out Vector;
216       Before    : Cursor;
217       New_Item  : Vector);
218
219    procedure Insert
220      (Container : in out Vector;
221       Before    : Cursor;
222       New_Item  : Vector;
223       Position  : out Cursor);
224
225    procedure Insert
226      (Container : in out Vector;
227       Before    : Extended_Index;
228       New_Item  : Element_Type;
229       Count     : Count_Type := 1);
230
231    procedure Insert
232      (Container : in out Vector;
233       Before    : Cursor;
234       New_Item  : Element_Type;
235       Count     : Count_Type := 1);
236
237    procedure Insert
238      (Container : in out Vector;
239       Before    : Cursor;
240       New_Item  : Element_Type;
241       Position  : out Cursor;
242       Count     : Count_Type := 1);
243
244    procedure Prepend
245      (Container : in out Vector;
246       New_Item  : Vector);
247
248    procedure Prepend
249      (Container : in out Vector;
250       New_Item  : Element_Type;
251       Count     : Count_Type := 1);
252
253    procedure Append
254      (Container : in out Vector;
255       New_Item  : Vector);
256
257    procedure Append
258      (Container : in out Vector;
259       New_Item  : Element_Type;
260       Count     : Count_Type := 1);
261
262    procedure Insert_Space
263      (Container : in out Vector;
264       Before    : Extended_Index;
265       Count     : Count_Type := 1);
266
267    procedure Insert_Space
268      (Container : in out Vector;
269       Before    : Cursor;
270       Position  : out Cursor;
271       Count     : Count_Type := 1);
272
273    procedure Delete
274      (Container : in out Vector;
275       Index     : Extended_Index;
276       Count     : Count_Type := 1);
277
278    procedure Delete
279      (Container : in out Vector;
280       Position  : in out Cursor;
281       Count     : Count_Type := 1);
282
283    procedure Delete_First
284      (Container : in out Vector;
285       Count     : Count_Type := 1);
286
287    procedure Delete_Last
288      (Container : in out Vector;
289       Count     : Count_Type := 1);
290
291    procedure Reverse_Elements (Container : in out Vector);
292
293    procedure Swap (Container : in out Vector; I, J : Index_Type);
294
295    procedure Swap (Container : in out Vector; I, J : Cursor);
296
297    function First_Index (Container : Vector) return Index_Type;
298
299    function First (Container : Vector) return Cursor;
300
301    function First_Element (Container : Vector) return Element_Type;
302
303    function Last_Index (Container : Vector) return Extended_Index;
304
305    function Last (Container : Vector) return Cursor;
306
307    function Last_Element (Container : Vector) return Element_Type;
308
309    function Next (Position : Cursor) return Cursor;
310
311    procedure Next (Position : in out Cursor);
312
313    function Previous (Position : Cursor) return Cursor;
314
315    procedure Previous (Position : in out Cursor);
316
317    function Find_Index
318      (Container : Vector;
319       Item      : Element_Type;
320       Index     : Index_Type := Index_Type'First) return Extended_Index;
321
322    function Find
323      (Container : Vector;
324       Item      : Element_Type;
325       Position  : Cursor := No_Element) return Cursor;
326
327    function Reverse_Find_Index
328      (Container : Vector;
329       Item      : Element_Type;
330       Index     : Index_Type := Index_Type'Last) return Extended_Index;
331
332    function Reverse_Find
333      (Container : Vector;
334       Item      : Element_Type;
335       Position  : Cursor := No_Element) return Cursor;
336
337    function Contains
338      (Container : Vector;
339       Item      : Element_Type) return Boolean;
340
341    procedure Iterate
342      (Container : Vector;
343       Process   : not null access procedure (Position : Cursor));
344
345    function Iterate (Container : Vector)
346       return Vector_Iterator_Interfaces.Reversible_Iterator'class;
347
348    function Iterate
349      (Container : Vector;
350       Start     : Cursor)
351       return Vector_Iterator_Interfaces.Reversible_Iterator'class;
352
353    procedure Reverse_Iterate
354      (Container : Vector;
355       Process   : not null access procedure (Position : Cursor));
356
357    generic
358       with function "<" (Left, Right : Element_Type) return Boolean is <>;
359    package Generic_Sorting is
360
361       function Is_Sorted (Container : Vector) return Boolean;
362
363       procedure Sort (Container : in out Vector);
364
365       procedure Merge (Target : in out Vector; Source : in out Vector);
366
367    end Generic_Sorting;
368
369 private
370
371    pragma Inline (First_Index);
372    pragma Inline (Last_Index);
373    pragma Inline (Element);
374    pragma Inline (First_Element);
375    pragma Inline (Last_Element);
376    pragma Inline (Query_Element);
377    pragma Inline (Update_Element);
378    pragma Inline (Replace_Element);
379    pragma Inline (Contains);
380    pragma Inline (Next);
381    pragma Inline (Previous);
382
383    type Element_Access is access Element_Type;
384
385    type Elements_Array is array (Index_Type range <>) of Element_Access;
386    function "=" (L, R : Elements_Array) return Boolean is abstract;
387
388    type Elements_Type (Last : Index_Type) is limited record
389       EA : Elements_Array (Index_Type'First .. Last);
390    end record;
391
392    type Elements_Access is access Elements_Type;
393
394    use Ada.Finalization;
395
396    type Vector is new Controlled with record
397       Elements : Elements_Access;
398       Last     : Extended_Index := No_Index;
399       Busy     : Natural := 0;
400       Lock     : Natural := 0;
401    end record;
402
403    type Constant_Reference_Type
404      (Element : not null access constant Element_Type) is null record;
405
406    type Reference_Type
407      (Element : not null access Element_Type) is null record;
408
409    overriding procedure Adjust (Container : in out Vector);
410
411    overriding procedure Finalize (Container : in out Vector);
412
413    procedure Write
414      (Stream    : not null access Root_Stream_Type'Class;
415       Container : Vector);
416
417    for Vector'Write use Write;
418
419    procedure Read
420      (Stream    : not null access Root_Stream_Type'Class;
421       Container : out Vector);
422
423    for Vector'Read use Read;
424
425    type Vector_Access is access constant Vector;
426    for Vector_Access'Storage_Size use 0;
427
428    type Cursor is record
429       Container : Vector_Access;
430       Index     : Index_Type := Index_Type'First;
431    end record;
432
433    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
434
435    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
436
437 end Ada.Containers.Indefinite_Vectors;