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-2010, 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 private with Ada
.Streams
;
37 type Index_Type
is range <>;
38 type Element_Type
is private;
40 with function "=" (Left
, Right
: Element_Type
) return Boolean is <>;
42 package Ada
.Containers
.Bounded_Vectors
is
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;
50 No_Index : constant Extended_Index := Extended_Index'First;
52 type Vector (Capacity : Count_Type) is tagged private;
53 pragma Preelaborable_Initialization (Vector);
55 type Cursor is private;
56 pragma Preelaborable_Initialization (Cursor);
58 Empty_Vector : constant Vector;
60 No_Element : constant Cursor;
62 overriding function "=" (Left, Right : Vector) return Boolean;
64 function To_Vector (Length : Count_Type) return Vector;
67 (New_Item : Element_Type;
68 Length : Count_Type) return Vector;
70 function "&" (Left, Right : Vector) return Vector;
72 function "&" (Left : Vector; Right : Element_Type) return Vector;
74 function "&" (Left : Element_Type; Right : Vector) return Vector;
76 function "&" (Left, Right : Element_Type) return Vector;
78 function Capacity (Container : Vector) return Count_Type;
80 procedure Reserve_Capacity
81 (Container : in out Vector;
82 Capacity : Count_Type);
84 function Length (Container : Vector) return Count_Type;
87 (Container : in out Vector;
90 function Is_Empty (Container : Vector) return Boolean;
92 procedure Clear (Container : in out Vector);
96 Index : Extended_Index) return Cursor;
98 function To_Index (Position : Cursor) return Extended_Index;
102 Index : Index_Type) return Element_Type;
104 function Element (Position : Cursor) return Element_Type;
106 procedure Replace_Element
107 (Container : in out Vector;
109 New_Item : Element_Type);
111 procedure Replace_Element
112 (Container : in out Vector;
114 New_Item : Element_Type);
116 procedure Query_Element
119 Process : not null access procedure (Element : Element_Type));
121 procedure Query_Element
123 Process : not null access procedure (Element : Element_Type));
125 procedure Update_Element
126 (Container : in out Vector;
128 Process : not null access procedure (Element : in out Element_Type));
130 procedure Update_Element
131 (Container : in out Vector;
133 Process : not null access procedure (Element : in out Element_Type));
135 procedure Assign (Target : in out Vector; Source : Vector);
137 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
139 procedure Move (Target : in out Vector; Source : in out Vector);
142 (Container : in out Vector;
143 Before : Extended_Index;
147 (Container : in out Vector;
152 (Container : in out Vector;
155 Position : out Cursor);
158 (Container : in out Vector;
159 Before : Extended_Index;
160 New_Item : Element_Type;
161 Count : Count_Type := 1);
164 (Container : in out Vector;
166 New_Item : Element_Type;
167 Count : Count_Type := 1);
170 (Container : in out Vector;
172 New_Item : Element_Type;
173 Position : out Cursor;
174 Count : Count_Type := 1);
177 (Container : in out Vector;
178 Before : Extended_Index;
179 Count : Count_Type := 1);
182 (Container : in out Vector;
184 Position : out Cursor;
185 Count : Count_Type := 1);
188 (Container : in out Vector;
192 (Container : in out Vector;
193 New_Item : Element_Type;
194 Count : Count_Type := 1);
197 (Container : in out Vector;
201 (Container : in out Vector;
202 New_Item : Element_Type;
203 Count : Count_Type := 1);
205 procedure Insert_Space
206 (Container : in out Vector;
207 Before : Extended_Index;
208 Count : Count_Type := 1);
210 procedure Insert_Space
211 (Container : in out Vector;
213 Position : out Cursor;
214 Count : Count_Type := 1);
217 (Container : in out Vector;
218 Index : Extended_Index;
219 Count : Count_Type := 1);
222 (Container : in out Vector;
223 Position : in out Cursor;
224 Count : Count_Type := 1);
226 procedure Delete_First
227 (Container : in out Vector;
228 Count : Count_Type := 1);
230 procedure Delete_Last
231 (Container : in out Vector;
232 Count : Count_Type := 1);
234 procedure Reverse_Elements (Container : in out Vector);
236 procedure Swap (Container : in out Vector; I, J : Index_Type);
238 procedure Swap (Container : in out Vector; I, J : Cursor);
240 function First_Index (Container : Vector) return Index_Type;
242 function First (Container : Vector) return Cursor;
244 function First_Element (Container : Vector) return Element_Type;
246 function Last_Index (Container : Vector) return Extended_Index;
248 function Last (Container : Vector) return Cursor;
250 function Last_Element (Container : Vector) return Element_Type;
252 function Next (Position : Cursor) return Cursor;
254 procedure Next (Position : in out Cursor);
256 function Previous (Position : Cursor) return Cursor;
258 procedure Previous (Position : in out Cursor);
263 Index : Index_Type := Index_Type'First) return Extended_Index;
268 Position : Cursor := No_Element) return Cursor;
270 function Reverse_Find_Index
273 Index : Index_Type := Index_Type'Last) return Extended_Index;
275 function Reverse_Find
278 Position : Cursor := No_Element) return Cursor;
282 Item : Element_Type) return Boolean;
284 function Has_Element (Position : Cursor) return Boolean;
288 Process : not null access procedure (Position : Cursor));
290 procedure Reverse_Iterate
292 Process : not null access procedure (Position : Cursor));
295 with function "<" (Left, Right : Element_Type) return Boolean is <>;
296 package Generic_Sorting is
298 function Is_Sorted (Container : Vector) return Boolean;
300 procedure Sort (Container : in out Vector);
302 procedure Merge (Target : in out Vector; Source : in out Vector);
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);
321 type Elements_Array is array (Count_Type range <>) of Element_Type;
322 function "=" (L, R : Elements_Array) return Boolean is abstract;
324 type Vector (Capacity : Count_Type) is tagged record
325 Elements : Elements_Array (1 .. Capacity);
326 Last : Extended_Index := No_Index;
334 (Stream : not null access Root_Stream_Type'Class;
337 for Vector'Write use Write;
340 (Stream : not null access Root_Stream_Type'Class;
341 Container : out Vector);
343 for Vector'Read use Read;
345 type Vector_Access is access all Vector;
346 for Vector_Access'Storage_Size use 0;
348 type Cursor is record
349 Container : Vector_Access;
350 Index : Index_Type := Index_Type'First;
354 (Stream : not null access Root_Stream_Type'Class;
357 for Cursor'Write use Write;
360 (Stream : not null access Root_Stream_Type'Class;
361 Position : out Cursor);
363 for Cursor'Read use Read;
365 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
367 No_Element : constant Cursor := Cursor'(null, Index_Type
'First);
369 end Ada
.Containers
.Bounded_Vectors
;