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-2011, 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.Streams; use Ada.Streams;
35 with Ada.Iterator_Interfaces;
38 type Index_Type is range <>;
39 type Element_Type is private;
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
43 package Ada.Containers.Bounded_Vectors is
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
49 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
51 No_Index : constant Extended_Index := Extended_Index'First;
53 type Vector (Capacity : Count_Type) is tagged private with
54 Constant_Indexing => Constant_Reference,
55 Variable_Indexing => Reference,
56 Default_Iterator => Iterate,
57 Iterator_Element => Element_Type;
59 pragma Preelaborable_Initialization (Vector);
61 type Cursor is private;
62 pragma Preelaborable_Initialization (Cursor);
64 Empty_Vector : constant Vector;
66 No_Element : constant Cursor;
67 function Has_Element (Position : Cursor) return Boolean;
69 package Vector_Iterator_Interfaces is new
70 Ada.Iterator_Interfaces (Cursor, Has_Element);
72 overriding function "=" (Left, Right : Vector) return Boolean;
74 function To_Vector (Length : Count_Type) return Vector;
77 (New_Item : Element_Type;
78 Length : Count_Type) return Vector;
80 function "&" (Left, Right : Vector) return Vector;
82 function "&" (Left : Vector; Right : Element_Type) return Vector;
84 function "&" (Left : Element_Type; Right : Vector) return Vector;
86 function "&" (Left, Right : Element_Type) return Vector;
88 function Capacity (Container : Vector) return Count_Type;
90 procedure Reserve_Capacity
91 (Container : in out Vector;
92 Capacity : Count_Type);
94 function Length (Container : Vector) return Count_Type;
97 (Container : in out Vector;
100 function Is_Empty (Container : Vector) return Boolean;
102 procedure Clear (Container : in out Vector);
106 Index : Extended_Index) return Cursor;
108 function To_Index (Position : Cursor) return Extended_Index;
112 Index : Index_Type) return Element_Type;
114 function Element (Position : Cursor) return Element_Type;
116 procedure Replace_Element
117 (Container : in out Vector;
119 New_Item : Element_Type);
121 procedure Replace_Element
122 (Container : in out Vector;
124 New_Item : Element_Type);
126 procedure Query_Element
129 Process : not null access procedure (Element : Element_Type));
131 procedure Query_Element
133 Process : not null access procedure (Element : Element_Type));
135 procedure Update_Element
136 (Container : in out Vector;
138 Process : not null access procedure (Element : in out Element_Type));
140 procedure Update_Element
141 (Container : in out Vector;
143 Process : not null access procedure (Element : in out Element_Type));
145 procedure Assign (Target : in out Vector; Source : Vector);
147 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
149 procedure Move (Target : in out Vector; Source : in out Vector);
152 (Container : in out Vector;
153 Before : Extended_Index;
157 (Container : in out Vector;
162 (Container : in out Vector;
165 Position : out Cursor);
168 (Container : in out Vector;
169 Before : Extended_Index;
170 New_Item : Element_Type;
171 Count : Count_Type := 1);
174 (Container : in out Vector;
176 New_Item : Element_Type;
177 Count : Count_Type := 1);
180 (Container : in out Vector;
182 New_Item : Element_Type;
183 Position : out Cursor;
184 Count : Count_Type := 1);
187 (Container : in out Vector;
188 Before : Extended_Index;
189 Count : Count_Type := 1);
192 (Container : in out Vector;
194 Position : out Cursor;
195 Count : Count_Type := 1);
198 (Container : in out Vector;
202 (Container : in out Vector;
203 New_Item : Element_Type;
204 Count : Count_Type := 1);
207 (Container : in out Vector;
211 (Container : in out Vector;
212 New_Item : Element_Type;
213 Count : Count_Type := 1);
215 procedure Insert_Space
216 (Container : in out Vector;
217 Before : Extended_Index;
218 Count : Count_Type := 1);
220 procedure Insert_Space
221 (Container : in out Vector;
223 Position : out Cursor;
224 Count : Count_Type := 1);
227 (Container : in out Vector;
228 Index : Extended_Index;
229 Count : Count_Type := 1);
232 (Container : in out Vector;
233 Position : in out Cursor;
234 Count : Count_Type := 1);
236 procedure Delete_First
237 (Container : in out Vector;
238 Count : Count_Type := 1);
240 procedure Delete_Last
241 (Container : in out Vector;
242 Count : Count_Type := 1);
244 procedure Reverse_Elements (Container : in out Vector);
246 procedure Swap (Container : in out Vector; I, J : Index_Type);
248 procedure Swap (Container : in out Vector; I, J : Cursor);
250 function First_Index (Container : Vector) return Index_Type;
252 function First (Container : Vector) return Cursor;
254 function First_Element (Container : Vector) return Element_Type;
256 function Last_Index (Container : Vector) return Extended_Index;
258 function Last (Container : Vector) return Cursor;
260 function Last_Element (Container : Vector) return Element_Type;
262 function Next (Position : Cursor) return Cursor;
264 procedure Next (Position : in out Cursor);
266 function Previous (Position : Cursor) return Cursor;
268 procedure Previous (Position : in out Cursor);
273 Index : Index_Type := Index_Type'First) return Extended_Index;
278 Position : Cursor := No_Element) return Cursor;
280 function Reverse_Find_Index
283 Index : Index_Type := Index_Type'Last) return Extended_Index;
285 function Reverse_Find
288 Position : Cursor := No_Element) return Cursor;
292 Item : Element_Type) return Boolean;
296 Process : not null access procedure (Position : Cursor));
298 procedure Reverse_Iterate
300 Process : not null access procedure (Position : Cursor));
304 return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
309 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
311 type Constant_Reference_Type
312 (Element : not null access constant Element_Type) is
315 Implicit_Dereference => Element;
318 (Stream : not null access Root_Stream_Type'Class;
319 Item : out Constant_Reference_Type);
321 for Constant_Reference_Type'Read use Read;
324 (Stream : not null access Root_Stream_Type'Class;
325 Item : Constant_Reference_Type);
327 for Constant_Reference_Type'Write use Write;
329 type Reference_Type (Element : not null access Element_Type) is private
331 Implicit_Dereference => Element;
334 (Stream : not null access Root_Stream_Type'Class;
335 Item : out Reference_Type);
337 for Reference_Type'Read use Read;
340 (Stream : not null access Root_Stream_Type'Class;
341 Item : Reference_Type);
343 for Reference_Type'Write use Write;
345 function Constant_Reference
346 (Container : Vector; Position : Cursor) -- SHOULD BE ALIASED
347 return Constant_Reference_Type;
349 function Constant_Reference
350 (Container : Vector; Position : Index_Type)
351 return Constant_Reference_Type;
353 function Reference (Container : Vector; Position : Cursor)
354 return Reference_Type;
356 function Reference (Container : Vector; Position : Index_Type)
357 return Reference_Type;
360 with function "<" (Left, Right : Element_Type) return Boolean is <>;
361 package Generic_Sorting is
363 function Is_Sorted (Container : Vector) return Boolean;
365 procedure Sort (Container : in out Vector);
367 procedure Merge (Target : in out Vector; Source : in out Vector);
373 pragma Inline (First_Index);
374 pragma Inline (Last_Index);
375 pragma Inline (Element);
376 pragma Inline (First_Element);
377 pragma Inline (Last_Element);
378 pragma Inline (Query_Element);
379 pragma Inline (Update_Element);
380 pragma Inline (Replace_Element);
381 pragma Inline (Is_Empty);
382 pragma Inline (Contains);
383 pragma Inline (Next);
384 pragma Inline (Previous);
386 type Elements_Array is array (Count_Type range <>) of aliased Element_Type;
387 function "=" (L, R : Elements_Array) return Boolean is abstract;
389 type Vector (Capacity : Count_Type) is tagged record
390 Elements : Elements_Array (1 .. Capacity) := (others => <>);
391 Last : Extended_Index := No_Index;
397 (Stream : not null access Root_Stream_Type'Class;
400 for Vector'Write use Write;
403 (Stream : not null access Root_Stream_Type'Class;
404 Container : out Vector);
406 for Vector'Read use Read;
408 type Vector_Access is access all Vector;
409 for Vector_Access'Storage_Size use 0;
411 type Cursor is record
412 Container : Vector_Access;
413 Index : Index_Type := Index_Type'First;
417 (Stream : not null access Root_Stream_Type'Class;
420 for Cursor'Write use Write;
423 (Stream : not null access Root_Stream_Type'Class;
424 Position : out Cursor);
426 for Cursor'Read use Read;
428 type Constant_Reference_Type
429 (Element : not null access constant Element_Type) is null record;
432 (Element : not null access Element_Type) is null record;
434 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
436 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
438 end Ada.Containers.Bounded_Vectors;