OSDN Git Service

ada:
[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 Move (Target : in out Vector; Source : in out Vector);
206    procedure Insert
207      (Container : in out Vector;
208       Before    : Extended_Index;
209       New_Item  : Vector);
210
211    procedure Insert
212      (Container : in out Vector;
213       Before    : Cursor;
214       New_Item  : Vector);
215
216    procedure Insert
217      (Container : in out Vector;
218       Before    : Cursor;
219       New_Item  : Vector;
220       Position  : out Cursor);
221
222    procedure Insert
223      (Container : in out Vector;
224       Before    : Extended_Index;
225       New_Item  : Element_Type;
226       Count     : Count_Type := 1);
227
228    procedure Insert
229      (Container : in out Vector;
230       Before    : Cursor;
231       New_Item  : Element_Type;
232       Count     : Count_Type := 1);
233
234    procedure Insert
235      (Container : in out Vector;
236       Before    : Cursor;
237       New_Item  : Element_Type;
238       Position  : out Cursor;
239       Count     : Count_Type := 1);
240
241    procedure Insert
242      (Container : in out Vector;
243       Before    : Extended_Index;
244       Count     : Count_Type := 1);
245
246    procedure Insert
247      (Container : in out Vector;
248       Before    : Cursor;
249       Position  : out Cursor;
250       Count     : Count_Type := 1);
251
252    procedure Prepend
253      (Container : in out Vector;
254       New_Item  : Vector);
255
256    procedure Prepend
257      (Container : in out Vector;
258       New_Item  : Element_Type;
259       Count     : Count_Type := 1);
260
261    procedure Append
262      (Container : in out Vector;
263       New_Item  : Vector);
264
265    procedure Append
266      (Container : in out Vector;
267       New_Item  : Element_Type;
268       Count     : Count_Type := 1);
269
270    procedure Insert_Space
271      (Container : in out Vector;
272       Before    : Extended_Index;
273       Count     : Count_Type := 1);
274
275    procedure Insert_Space
276      (Container : in out Vector;
277       Before    : Cursor;
278       Position  : out Cursor;
279       Count     : Count_Type := 1);
280
281    procedure Delete
282      (Container : in out Vector;
283       Index     : Extended_Index;
284       Count     : Count_Type := 1);
285
286    procedure Delete
287      (Container : in out Vector;
288       Position  : in out Cursor;
289       Count     : Count_Type := 1);
290
291    procedure Delete_First
292      (Container : in out Vector;
293       Count     : Count_Type := 1);
294
295    procedure Delete_Last
296      (Container : in out Vector;
297       Count     : Count_Type := 1);
298
299    procedure Reverse_Elements (Container : in out Vector);
300
301    procedure Swap (Container : in out Vector; I, J : Index_Type);
302
303    procedure Swap (Container : in out Vector; I, J : Cursor);
304
305    function First_Index (Container : Vector) return Index_Type;
306
307    function First (Container : Vector) return Cursor;
308
309    function First_Element (Container : Vector) return Element_Type;
310
311    function Last_Index (Container : Vector) return Extended_Index;
312
313    function Last (Container : Vector) return Cursor;
314
315    function Last_Element (Container : Vector) return Element_Type;
316
317    function Next (Position : Cursor) return Cursor;
318
319    procedure Next (Position : in out Cursor);
320
321    function Previous (Position : Cursor) return Cursor;
322
323    procedure Previous (Position : in out Cursor);
324
325    function Find_Index
326      (Container : Vector;
327       Item      : Element_Type;
328       Index     : Index_Type := Index_Type'First) return Extended_Index;
329
330    function Find
331      (Container : Vector;
332       Item      : Element_Type;
333       Position  : Cursor := No_Element) return Cursor;
334
335    function Reverse_Find_Index
336      (Container : Vector;
337       Item      : Element_Type;
338       Index     : Index_Type := Index_Type'Last) return Extended_Index;
339
340    function Reverse_Find
341      (Container : Vector;
342       Item      : Element_Type;
343       Position  : Cursor := No_Element) return Cursor;
344
345    function Contains
346      (Container : Vector;
347       Item      : Element_Type) return Boolean;
348
349    procedure Iterate
350      (Container : Vector;
351       Process   : not null access procedure (Position : Cursor));
352
353    procedure Reverse_Iterate
354      (Container : Vector;
355       Process   : not null access procedure (Position : Cursor));
356
357    function Iterate (Container : Vector)
358       return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
359
360    function Iterate (Container : Vector; Start : Cursor)
361       return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
362
363    generic
364       with function "<" (Left, Right : Element_Type) return Boolean is <>;
365    package Generic_Sorting is
366
367       function Is_Sorted (Container : Vector) return Boolean;
368
369       procedure Sort (Container : in out Vector);
370
371       procedure Merge (Target : in out Vector; Source : in out Vector);
372
373    end Generic_Sorting;
374
375 private
376
377    pragma Inline (First_Index);
378    pragma Inline (Last_Index);
379    pragma Inline (Element);
380    pragma Inline (First_Element);
381    pragma Inline (Last_Element);
382    pragma Inline (Query_Element);
383    pragma Inline (Update_Element);
384    pragma Inline (Replace_Element);
385    pragma Inline (Is_Empty);
386    pragma Inline (Contains);
387    pragma Inline (Next);
388    pragma Inline (Previous);
389
390    type Elements_Array is array (Index_Type range <>) of aliased Element_Type;
391    function "=" (L, R : Elements_Array) return Boolean is abstract;
392
393    type Elements_Type (Last : Index_Type) is limited record
394       EA : Elements_Array (Index_Type'First .. Last);
395    end record;
396
397    type Elements_Access is access Elements_Type;
398
399    use Ada.Finalization;
400
401    type Vector is new Controlled with record
402       Elements : Elements_Access;
403       Last     : Extended_Index := No_Index;
404       Busy     : Natural := 0;
405       Lock     : Natural := 0;
406    end record;
407
408    type Vector_Access is access constant Vector;
409    for Vector_Access'Storage_Size use 0;
410
411    type Cursor is record
412       Container   : Vector_Access;
413       Index       : Index_Type := Index_Type'First;
414    end record;
415
416    procedure Write
417      (Stream    : not null access Root_Stream_Type'Class;
418       Container : Vector);
419
420    for Vector'Write use Write;
421
422    procedure Read
423      (Stream    : not null access Root_Stream_Type'Class;
424       Container : out Vector);
425
426    for Vector'Read use Read;
427
428    type Constant_Reference_Type
429       (Element : not null access constant Element_Type) is null record;
430
431    type Reference_Type
432       (Element : not null access Element_Type) is null record;
433
434    overriding procedure Adjust (Container : in out Vector);
435
436    overriding procedure Finalize (Container : in out Vector);
437
438    No_Element   : constant Cursor := Cursor'(null, Index_Type'First);
439    Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
440
441 end Ada.Containers.Vectors;