OSDN Git Service

2010-10-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cobove.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --       A D A . C O N T A I N E R S . B O U N D E D _ V E C T O R S        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2010, 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.Streams;
35
36 generic
37    type Index_Type is range <>;
38    type Element_Type is private;
39
40    with function "=" (Left, Right : Element_Type) return Boolean is <>;
41
42 package Ada.Containers.Bounded_Vectors is
43    pragma Pure;
44    pragma Remote_Types;
45
46    subtype Extended_Index is Index_Type'Base
47      range Index_Type'First - 1 ..
48            Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
49
50    No_Index : constant Extended_Index := Extended_Index'First;
51
52    type Vector (Capacity : Count_Type) is tagged private;
53    pragma Preelaborable_Initialization (Vector);
54
55    type Cursor is private;
56    pragma Preelaborable_Initialization (Cursor);
57
58    Empty_Vector : constant Vector;
59
60    No_Element : constant Cursor;
61
62    overriding function "=" (Left, Right : Vector) return Boolean;
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 Capacity (Container : Vector) return Count_Type;
79
80    procedure Reserve_Capacity
81      (Container : in out Vector;
82       Capacity  : Count_Type);
83
84    function Length (Container : Vector) return Count_Type;
85
86    procedure Set_Length
87      (Container : in out Vector;
88       Length    : Count_Type);
89
90    function Is_Empty (Container : Vector) return Boolean;
91
92    procedure Clear (Container : in out Vector);
93
94    function To_Cursor
95      (Container : Vector;
96       Index     : Extended_Index) return Cursor;
97
98    function To_Index (Position : Cursor) return Extended_Index;
99
100    function Element
101      (Container : Vector;
102       Index     : Index_Type) return Element_Type;
103
104    function Element (Position : Cursor) return Element_Type;
105
106    procedure Replace_Element
107      (Container : in out Vector;
108       Index     : Index_Type;
109       New_Item  : Element_Type);
110
111    procedure Replace_Element
112      (Container : in out Vector;
113       Position  : Cursor;
114       New_Item  : Element_Type);
115
116    procedure Query_Element
117      (Container : Vector;
118       Index     : Index_Type;
119       Process   : not null access procedure (Element : Element_Type));
120
121    procedure Query_Element
122      (Position : Cursor;
123       Process  : not null access procedure (Element : Element_Type));
124
125    procedure Update_Element
126      (Container : in out Vector;
127       Index     : Index_Type;
128       Process   : not null access procedure (Element : in out Element_Type));
129
130    procedure Update_Element
131      (Container : in out Vector;
132       Position  : Cursor;
133       Process   : not null access procedure (Element : in out Element_Type));
134
135    procedure Assign (Target : in out Vector; Source : Vector);
136
137    function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
138
139    procedure Move (Target : in out Vector; Source : in out Vector);
140
141    procedure Insert
142      (Container : in out Vector;
143       Before    : Extended_Index;
144       New_Item  : Vector);
145
146    procedure Insert
147      (Container : in out Vector;
148       Before    : Cursor;
149       New_Item  : Vector);
150
151    procedure Insert
152      (Container : in out Vector;
153       Before    : Cursor;
154       New_Item  : Vector;
155       Position  : out Cursor);
156
157    procedure Insert
158      (Container : in out Vector;
159       Before    : Extended_Index;
160       New_Item  : Element_Type;
161       Count     : Count_Type := 1);
162
163    procedure Insert
164      (Container : in out Vector;
165       Before    : Cursor;
166       New_Item  : Element_Type;
167       Count     : Count_Type := 1);
168
169    procedure Insert
170      (Container : in out Vector;
171       Before    : Cursor;
172       New_Item  : Element_Type;
173       Position  : out Cursor;
174       Count     : Count_Type := 1);
175
176    procedure Insert
177      (Container : in out Vector;
178       Before    : Extended_Index;
179       Count     : Count_Type := 1);
180
181    procedure Insert
182      (Container : in out Vector;
183       Before    : Cursor;
184       Position  : out Cursor;
185       Count     : Count_Type := 1);
186
187    procedure Prepend
188      (Container : in out Vector;
189       New_Item  : Vector);
190
191    procedure Prepend
192      (Container : in out Vector;
193       New_Item  : Element_Type;
194       Count     : Count_Type := 1);
195
196    procedure Append
197      (Container : in out Vector;
198       New_Item  : Vector);
199
200    procedure Append
201      (Container : in out Vector;
202       New_Item  : Element_Type;
203       Count     : Count_Type := 1);
204
205    procedure Insert_Space
206      (Container : in out Vector;
207       Before    : Extended_Index;
208       Count     : Count_Type := 1);
209
210    procedure Insert_Space
211      (Container : in out Vector;
212       Before    : Cursor;
213       Position  : out Cursor;
214       Count     : Count_Type := 1);
215
216    procedure Delete
217      (Container : in out Vector;
218       Index     : Extended_Index;
219       Count     : Count_Type := 1);
220
221    procedure Delete
222      (Container : in out Vector;
223       Position  : in out Cursor;
224       Count     : Count_Type := 1);
225
226    procedure Delete_First
227      (Container : in out Vector;
228       Count     : Count_Type := 1);
229
230    procedure Delete_Last
231      (Container : in out Vector;
232       Count     : Count_Type := 1);
233
234    procedure Reverse_Elements (Container : in out Vector);
235
236    procedure Swap (Container : in out Vector; I, J : Index_Type);
237
238    procedure Swap (Container : in out Vector; I, J : Cursor);
239
240    function First_Index (Container : Vector) return Index_Type;
241
242    function First (Container : Vector) return Cursor;
243
244    function First_Element (Container : Vector) return Element_Type;
245
246    function Last_Index (Container : Vector) return Extended_Index;
247
248    function Last (Container : Vector) return Cursor;
249
250    function Last_Element (Container : Vector) return Element_Type;
251
252    function Next (Position : Cursor) return Cursor;
253
254    procedure Next (Position : in out Cursor);
255
256    function Previous (Position : Cursor) return Cursor;
257
258    procedure Previous (Position : in out Cursor);
259
260    function Find_Index
261      (Container : Vector;
262       Item      : Element_Type;
263       Index     : Index_Type := Index_Type'First) return Extended_Index;
264
265    function Find
266      (Container : Vector;
267       Item      : Element_Type;
268       Position  : Cursor := No_Element) return Cursor;
269
270    function Reverse_Find_Index
271      (Container : Vector;
272       Item      : Element_Type;
273       Index     : Index_Type := Index_Type'Last) return Extended_Index;
274
275    function Reverse_Find
276      (Container : Vector;
277       Item      : Element_Type;
278       Position  : Cursor := No_Element) return Cursor;
279
280    function Contains
281      (Container : Vector;
282       Item      : Element_Type) return Boolean;
283
284    function Has_Element (Position : Cursor) return Boolean;
285
286    procedure Iterate
287      (Container : Vector;
288       Process   : not null access procedure (Position : Cursor));
289
290    procedure Reverse_Iterate
291      (Container : Vector;
292       Process   : not null access procedure (Position : Cursor));
293
294    generic
295       with function "<" (Left, Right : Element_Type) return Boolean is <>;
296    package Generic_Sorting is
297
298       function Is_Sorted (Container : Vector) return Boolean;
299
300       procedure Sort (Container : in out Vector);
301
302       procedure Merge (Target : in out Vector; Source : in out Vector);
303
304    end Generic_Sorting;
305
306 private
307
308    pragma Inline (First_Index);
309    pragma Inline (Last_Index);
310    pragma Inline (Element);
311    pragma Inline (First_Element);
312    pragma Inline (Last_Element);
313    pragma Inline (Query_Element);
314    pragma Inline (Update_Element);
315    pragma Inline (Replace_Element);
316    pragma Inline (Is_Empty);
317    pragma Inline (Contains);
318    pragma Inline (Next);
319    pragma Inline (Previous);
320
321    type Elements_Array is array (Count_Type range <>) of Element_Type;
322    function "=" (L, R : Elements_Array) return Boolean is abstract;
323
324    type Vector (Capacity : Count_Type) is tagged record
325       Elements : Elements_Array (1 .. Capacity);
326       Last     : Extended_Index := No_Index;
327       Busy     : Natural := 0;
328       Lock     : Natural := 0;
329    end record;
330
331    use Ada.Streams;
332
333    procedure Write
334      (Stream    : not null access Root_Stream_Type'Class;
335       Container : Vector);
336
337    for Vector'Write use Write;
338
339    procedure Read
340      (Stream    : not null access Root_Stream_Type'Class;
341       Container : out Vector);
342
343    for Vector'Read use Read;
344
345    type Vector_Access is access all Vector;
346    for Vector_Access'Storage_Size use 0;
347
348    type Cursor is record
349       Container : Vector_Access;
350       Index     : Index_Type := Index_Type'First;
351    end record;
352
353    procedure Write
354      (Stream   : not null access Root_Stream_Type'Class;
355       Position : Cursor);
356
357    for Cursor'Write use Write;
358
359    procedure Read
360      (Stream   : not null access Root_Stream_Type'Class;
361       Position : out Cursor);
362
363    for Cursor'Read use Read;
364
365    Empty_Vector : constant Vector := (Capacity => 0, others => <>);
366
367    No_Element : constant Cursor := Cursor'(null, Index_Type'First);
368
369 end Ada.Containers.Bounded_Vectors;