OSDN Git Service

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