]>
Commit | Line | Data |
---|---|---|
11775988 AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT LIBRARY COMPONENTS -- | |
4 | -- -- | |
5 | -- ADA.CONTAINERS.FUNCTIONAL_VECTORS -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
9 | -- Copyright (C) 2016-2017, 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 | ||
32 | pragma Ada_2012; | |
33 | package body Ada.Containers.Functional_Vectors with SPARK_Mode => Off is | |
34 | use Containers; | |
35 | ||
11775988 AC |
36 | --------- |
37 | -- "<" -- | |
38 | --------- | |
39 | ||
6cbfce7e AC |
40 | function "<" (Left : Sequence; Right : Sequence) return Boolean is |
41 | (Length (Left.Content) < Length (Right.Content) | |
42 | and then (for all I in Index_Type'First .. Last (Left) => | |
43 | Get (Left.Content, I) = Get (Right.Content, I))); | |
11775988 AC |
44 | |
45 | ---------- | |
46 | -- "<=" -- | |
47 | ---------- | |
48 | ||
6cbfce7e AC |
49 | function "<=" (Left : Sequence; Right : Sequence) return Boolean is |
50 | (Length (Left.Content) <= Length (Right.Content) | |
51 | and then (for all I in Index_Type'First .. Last (Left) => | |
52 | Get (Left.Content, I) = Get (Right.Content, I))); | |
11775988 AC |
53 | |
54 | --------- | |
6cbfce7e | 55 | -- "=" -- |
11775988 AC |
56 | --------- |
57 | ||
6cbfce7e AC |
58 | function "=" (Left : Sequence; Right : Sequence) return Boolean is |
59 | (Left.Content = Right.Content); | |
11775988 AC |
60 | |
61 | --------- | |
6cbfce7e | 62 | -- Add -- |
11775988 AC |
63 | --------- |
64 | ||
6cbfce7e | 65 | function Add (Container : Sequence; New_Item : Element_Type) return Sequence |
e77e2429 | 66 | is |
6cbfce7e AC |
67 | (Content => Add (Container.Content, |
68 | Index_Type'Val | |
69 | (Index_Type'Pos (Index_Type'First) + | |
70 | Length (Container.Content)), | |
71 | New_Item)); | |
11775988 | 72 | |
6cbfce7e AC |
73 | function Add |
74 | (Container : Sequence; | |
75 | Position : Index_Type; | |
76 | New_Item : Element_Type) return Sequence | |
77 | is | |
78 | (Content => Add (Container.Content, Position, New_Item)); | |
79 | ||
80 | -------------------- | |
81 | -- Constant_Range -- | |
82 | -------------------- | |
83 | ||
84 | function Constant_Range | |
85 | (Container : Sequence; | |
86 | Fst : Index_Type; | |
87 | Lst : Extended_Index; | |
88 | Item : Element_Type) return Boolean is | |
89 | begin | |
90 | for I in Fst .. Lst loop | |
91 | if Get (Container.Content, I) /= Item then | |
92 | return False; | |
93 | end if; | |
94 | end loop; | |
95 | return True; | |
96 | end Constant_Range; | |
97 | ||
98 | -------------- | |
99 | -- Contains -- | |
100 | -------------- | |
101 | ||
102 | function Contains | |
103 | (Container : Sequence; | |
104 | Fst : Index_Type; | |
105 | Lst : Extended_Index; | |
106 | Item : Element_Type) return Boolean | |
e77e2429 | 107 | is |
6cbfce7e AC |
108 | begin |
109 | for I in Fst .. Lst loop | |
110 | if Get (Container.Content, I) = Item then | |
111 | return True; | |
112 | end if; | |
113 | end loop; | |
114 | return False; | |
115 | end Contains; | |
116 | ||
117 | ------------------ | |
118 | -- Range_Except -- | |
119 | ------------------ | |
120 | ||
121 | function Equal_Except | |
122 | (Left : Sequence; | |
123 | Right : Sequence; | |
124 | Position : Index_Type) return Boolean | |
125 | is | |
126 | begin | |
127 | if Length (Left.Content) /= Length (Right.Content) then | |
128 | return False; | |
129 | end if; | |
130 | ||
131 | for I in Index_Type'First .. Last (Left) loop | |
132 | if I /= Position | |
133 | and then Get (Left.Content, I) /= Get (Right.Content, I) | |
134 | then | |
135 | return False; | |
136 | end if; | |
137 | end loop; | |
138 | ||
139 | return True; | |
140 | end Equal_Except; | |
141 | ||
142 | function Equal_Except | |
143 | (Left : Sequence; | |
144 | Right : Sequence; | |
145 | X, Y : Index_Type) return Boolean | |
146 | is | |
147 | begin | |
148 | if Length (Left.Content) /= Length (Right.Content) then | |
149 | return False; | |
150 | end if; | |
151 | ||
152 | for I in Index_Type'First .. Last (Left) loop | |
153 | if I /= X and then I /= Y | |
154 | and then Get (Left.Content, I) /= Get (Right.Content, I) | |
155 | then | |
156 | return False; | |
157 | end if; | |
158 | end loop; | |
159 | ||
160 | return True; | |
161 | end Equal_Except; | |
11775988 | 162 | |
6cbfce7e AC |
163 | --------- |
164 | -- Get -- | |
165 | --------- | |
11775988 | 166 | |
6cbfce7e AC |
167 | function Get (Container : Sequence; |
168 | Position : Extended_Index) return Element_Type | |
e77e2429 | 169 | is |
6cbfce7e | 170 | (Get (Container.Content, Position)); |
11775988 AC |
171 | |
172 | ---------- | |
173 | -- Last -- | |
174 | ---------- | |
175 | ||
6cbfce7e AC |
176 | function Last (Container : Sequence) return Extended_Index is |
177 | (Index_Type'Val ((Index_Type'Pos (Index_Type'First) - 1) | |
178 | + Length (Container))); | |
11775988 AC |
179 | |
180 | ------------ | |
181 | -- Length -- | |
182 | ------------ | |
183 | ||
6cbfce7e AC |
184 | function Length (Container : Sequence) return Count_Type is |
185 | (Length (Container.Content)); | |
186 | ||
187 | ----------------- | |
188 | -- Range_Equal -- | |
189 | ----------------- | |
190 | ||
191 | function Range_Equal | |
192 | (Left : Sequence; | |
193 | Right : Sequence; | |
194 | Fst : Index_Type; | |
195 | Lst : Extended_Index) return Boolean | |
196 | is | |
197 | begin | |
198 | for I in Fst .. Lst loop | |
199 | if Get (Left, I) /= Get (Right, I) then | |
200 | return False; | |
201 | end if; | |
202 | end loop; | |
203 | return True; | |
204 | end Range_Equal; | |
205 | ||
206 | ------------------- | |
207 | -- Range_Shifted -- | |
208 | ------------------- | |
209 | ||
210 | function Range_Shifted | |
211 | (Left : Sequence; | |
212 | Right : Sequence; | |
213 | Fst : Index_Type; | |
214 | Lst : Extended_Index; | |
215 | Offset : Count_Type'Base) return Boolean | |
216 | is | |
217 | begin | |
218 | for I in Fst .. Lst loop | |
219 | if Get (Left, I) | |
220 | /= Get (Right, Index_Type'Val (Index_Type'Pos (I) + Offset)) | |
221 | then | |
222 | return False; | |
223 | end if; | |
224 | end loop; | |
225 | return True; | |
226 | end Range_Shifted; | |
11775988 | 227 | |
394fa9f5 CD |
228 | ------------ |
229 | -- Remove -- | |
230 | ------------ | |
231 | ||
6cbfce7e AC |
232 | function Remove (Container : Sequence; |
233 | Position : Index_Type) return Sequence | |
234 | is | |
235 | (Content => Remove (Container.Content, Position)); | |
394fa9f5 | 236 | |
11775988 AC |
237 | --------- |
238 | -- Set -- | |
239 | --------- | |
240 | ||
e77e2429 | 241 | function Set |
6cbfce7e AC |
242 | (Container : Sequence; |
243 | Position : Index_Type; | |
244 | New_Item : Element_Type) return Sequence | |
e77e2429 | 245 | is |
6cbfce7e | 246 | (Content => Set (Container.Content, Position, New_Item)); |
e77e2429 | 247 | |
11775988 | 248 | end Ada.Containers.Functional_Vectors; |