1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
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 --
9 -- Copyright (C) 2004-2012, Free Software Foundation, Inc. --
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. --
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. --
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. --
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/>. --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada
.Iterator_Interfaces
;
36 private with Ada
.Streams
;
39 type Index_Type
is range <>;
40 type Element_Type
is private;
42 with function "=" (Left
, Right
: Element_Type
) return Boolean is <>;
44 package Ada
.Containers
.Bounded_Vectors
is
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;
52 No_Index : constant Extended_Index := Extended_Index'First;
54 type Vector (Capacity : Count_Type) is tagged private with
55 Constant_Indexing => Constant_Reference,
56 Variable_Indexing => Reference,
57 Default_Iterator => Iterate,
58 Iterator_Element => Element_Type;
60 pragma Preelaborable_Initialization (Vector);
62 type Cursor is private;
63 pragma Preelaborable_Initialization (Cursor);
65 Empty_Vector : constant Vector;
67 No_Element : constant Cursor;
69 function Has_Element (Position : Cursor) return Boolean;
71 package Vector_Iterator_Interfaces is new
72 Ada.Iterator_Interfaces (Cursor, Has_Element);
74 overriding function "=" (Left, Right : Vector) return Boolean;
76 function To_Vector (Length : Count_Type) return Vector;
79 (New_Item : Element_Type;
80 Length : Count_Type) return Vector;
82 function "&" (Left, Right : Vector) return Vector;
84 function "&" (Left : Vector; Right : Element_Type) return Vector;
86 function "&" (Left : Element_Type; Right : Vector) return Vector;
88 function "&" (Left, Right : Element_Type) return Vector;
90 function Capacity (Container : Vector) return Count_Type;
92 procedure Reserve_Capacity
93 (Container : in out Vector;
94 Capacity : Count_Type);
96 function Length (Container : Vector) return Count_Type;
99 (Container : in out Vector;
100 Length : Count_Type);
102 function Is_Empty (Container : Vector) return Boolean;
104 procedure Clear (Container : in out Vector);
108 Index : Extended_Index) return Cursor;
110 function To_Index (Position : Cursor) return Extended_Index;
114 Index : Index_Type) return Element_Type;
116 function Element (Position : Cursor) return Element_Type;
118 procedure Replace_Element
119 (Container : in out Vector;
121 New_Item : Element_Type);
123 procedure Replace_Element
124 (Container : in out Vector;
126 New_Item : Element_Type);
128 procedure Query_Element
131 Process : not null access procedure (Element : Element_Type));
133 procedure Query_Element
135 Process : not null access procedure (Element : Element_Type));
137 procedure Update_Element
138 (Container : in out Vector;
140 Process : not null access procedure (Element : in out Element_Type));
142 procedure Update_Element
143 (Container : in out Vector;
145 Process : not null access procedure (Element : in out Element_Type));
147 type Constant_Reference_Type
148 (Element : not null access constant Element_Type) is
151 Implicit_Dereference => Element;
153 type Reference_Type (Element : not null access Element_Type) is private
155 Implicit_Dereference => Element;
157 function Constant_Reference
158 (Container : aliased Vector;
159 Position : Cursor) return Constant_Reference_Type;
162 (Container : aliased in out Vector;
163 Position : Cursor) return Reference_Type;
165 function Constant_Reference
166 (Container : aliased Vector;
167 Index : Index_Type) return Constant_Reference_Type;
170 (Container : aliased in out Vector;
171 Index : Index_Type) return Reference_Type;
173 procedure Assign (Target : in out Vector; Source : Vector);
175 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
177 procedure Move (Target : in out Vector; Source : in out Vector);
180 (Container : in out Vector;
181 Before : Extended_Index;
185 (Container : in out Vector;
190 (Container : in out Vector;
193 Position : out Cursor);
196 (Container : in out Vector;
197 Before : Extended_Index;
198 New_Item : Element_Type;
199 Count : Count_Type := 1);
202 (Container : in out Vector;
204 New_Item : Element_Type;
205 Count : Count_Type := 1);
208 (Container : in out Vector;
210 New_Item : Element_Type;
211 Position : out Cursor;
212 Count : Count_Type := 1);
215 (Container : in out Vector;
216 Before : Extended_Index;
217 Count : Count_Type := 1);
220 (Container : in out Vector;
222 Position : out Cursor;
223 Count : Count_Type := 1);
226 (Container : in out Vector;
230 (Container : in out Vector;
231 New_Item : Element_Type;
232 Count : Count_Type := 1);
235 (Container : in out Vector;
239 (Container : in out Vector;
240 New_Item : Element_Type;
241 Count : Count_Type := 1);
243 procedure Insert_Space
244 (Container : in out Vector;
245 Before : Extended_Index;
246 Count : Count_Type := 1);
248 procedure Insert_Space
249 (Container : in out Vector;
251 Position : out Cursor;
252 Count : Count_Type := 1);
255 (Container : in out Vector;
256 Index : Extended_Index;
257 Count : Count_Type := 1);
260 (Container : in out Vector;
261 Position : in out Cursor;
262 Count : Count_Type := 1);
264 procedure Delete_First
265 (Container : in out Vector;
266 Count : Count_Type := 1);
268 procedure Delete_Last
269 (Container : in out Vector;
270 Count : Count_Type := 1);
272 procedure Reverse_Elements (Container : in out Vector);
274 procedure Swap (Container : in out Vector; I, J : Index_Type);
276 procedure Swap (Container : in out Vector; I, J : Cursor);
278 function First_Index (Container : Vector) return Index_Type;
280 function First (Container : Vector) return Cursor;
282 function First_Element (Container : Vector) return Element_Type;
284 function Last_Index (Container : Vector) return Extended_Index;
286 function Last (Container : Vector) return Cursor;
288 function Last_Element (Container : Vector) return Element_Type;
290 function Next (Position : Cursor) return Cursor;
292 procedure Next (Position : in out Cursor);
294 function Previous (Position : Cursor) return Cursor;
296 procedure Previous (Position : in out Cursor);
301 Index : Index_Type := Index_Type'First) return Extended_Index;
306 Position : Cursor := No_Element) return Cursor;
308 function Reverse_Find_Index
311 Index : Index_Type := Index_Type'Last) return Extended_Index;
313 function Reverse_Find
316 Position : Cursor := No_Element) return Cursor;
320 Item : Element_Type) return Boolean;
324 Process : not null access procedure (Position : Cursor));
326 procedure Reverse_Iterate
328 Process : not null access procedure (Position : Cursor));
332 return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
337 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
340 with function "<" (Left, Right : Element_Type) return Boolean is <>;
341 package Generic_Sorting is
343 function Is_Sorted (Container : Vector) return Boolean;
345 procedure Sort (Container : in out Vector);
347 procedure Merge (Target : in out Vector; Source : in out Vector);
353 pragma Inline (First_Index);
354 pragma Inline (Last_Index);
355 pragma Inline (Element);
356 pragma Inline (First_Element);
357 pragma Inline (Last_Element);
358 pragma Inline (Query_Element);
359 pragma Inline (Update_Element);
360 pragma Inline (Replace_Element);
361 pragma Inline (Is_Empty);
362 pragma Inline (Contains);
363 pragma Inline (Next);
364 pragma Inline (Previous);
368 type Elements_Array is array (Count_Type range <>) of aliased Element_Type;
369 function "=" (L, R : Elements_Array) return Boolean is abstract;
371 type Vector (Capacity : Count_Type) is tagged record
372 Elements : Elements_Array (1 .. Capacity) := (others => <>);
373 Last : Extended_Index := No_Index;
379 (Stream : not null access Root_Stream_Type'Class;
382 for Vector'Write use Write;
385 (Stream : not null access Root_Stream_Type'Class;
386 Container : out Vector);
388 for Vector'Read use Read;
390 type Vector_Access is access all Vector;
391 for Vector_Access'Storage_Size use 0;
393 type Cursor is record
394 Container : Vector_Access;
395 Index : Index_Type := Index_Type'First;
399 (Stream : not null access Root_Stream_Type'Class;
402 for Cursor'Write use Write;
405 (Stream : not null access Root_Stream_Type'Class;
406 Position : out Cursor);
408 for Cursor'Read use Read;
410 type Constant_Reference_Type
411 (Element : not null access constant Element_Type) is null record;
414 (Stream : not null access Root_Stream_Type'Class;
415 Item : out Constant_Reference_Type);
417 for Constant_Reference_Type'Read use Read;
420 (Stream : not null access Root_Stream_Type'Class;
421 Item : Constant_Reference_Type);
423 for Constant_Reference_Type'Write use Write;
426 (Element : not null access Element_Type) is null record;
429 (Stream : not null access Root_Stream_Type'Class;
430 Item : out Reference_Type);
432 for Reference_Type'Read use Read;
435 (Stream : not null access Root_Stream_Type'Class;
436 Item : Reference_Type);
438 for Reference_Type'Write use Write;
440 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
442 No_Element : constant Cursor := Cursor'(null, Index_Type
'First);
444 end Ada
.Containers
.Bounded_Vectors
;