OSDN Git Service

2012-01-10 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-ciorma.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                 ADA.CONTAINERS.INDEFINITE_ORDERED_MAPS                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2011, 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 with Ada.Iterator_Interfaces;
35 private with Ada.Containers.Red_Black_Trees;
36 private with Ada.Finalization;
37 private with Ada.Streams;
38
39 generic
40    type Key_Type (<>) is private;
41    type Element_Type (<>) is private;
42
43    with function "<" (Left, Right : Key_Type) return Boolean is <>;
44    with function "=" (Left, Right : Element_Type) return Boolean is <>;
45
46 package Ada.Containers.Indefinite_Ordered_Maps is
47    pragma Preelaborate;
48    pragma Remote_Types;
49
50    function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
51
52    type Map is tagged private
53    with Constant_Indexing => Constant_Reference,
54         Variable_Indexing => Reference,
55         Default_Iterator  => Iterate,
56         Iterator_Element  => Element_Type;
57
58    pragma Preelaborable_Initialization (Map);
59
60    type Cursor is private;
61    pragma Preelaborable_Initialization (Cursor);
62
63    Empty_Map : constant Map;
64
65    No_Element : constant Cursor;
66    function Has_Element (Position : Cursor) return Boolean;
67
68    package Map_Iterator_Interfaces is new
69      Ada.Iterator_Interfaces (Cursor, Has_Element);
70
71    function "=" (Left, Right : Map) return Boolean;
72
73    function Length (Container : Map) return Count_Type;
74
75    function Is_Empty (Container : Map) return Boolean;
76
77    procedure Clear (Container : in out Map);
78
79    function Key (Position : Cursor) return Key_Type;
80
81    function Element (Position : Cursor) return Element_Type;
82
83    procedure Replace_Element
84      (Container : in out Map;
85       Position  : Cursor;
86       New_Item  : Element_Type);
87
88    procedure Query_Element
89      (Position : Cursor;
90       Process  : not null access procedure (Key     : Key_Type;
91                                             Element : Element_Type));
92
93    procedure Update_Element
94      (Container : in out Map;
95       Position  : Cursor;
96       Process   : not null access procedure (Key     : Key_Type;
97                                              Element : in out Element_Type));
98
99    type Constant_Reference_Type
100       (Element : not null access constant Element_Type) is private
101    with
102       Implicit_Dereference => Element;
103
104    type Reference_Type (Element : not null access Element_Type) is private
105    with
106       Implicit_Dereference => Element;
107
108    function Constant_Reference
109      (Container : aliased Map;
110       Position  : Cursor) return Constant_Reference_Type;
111
112    function Reference
113      (Container : aliased in out Map;
114       Position  : Cursor) return Reference_Type;
115
116    function Constant_Reference
117      (Container : aliased Map;
118       Key       : Key_Type) return Constant_Reference_Type;
119
120    function Reference
121      (Container : aliased in out Map;
122       Key       : Key_Type) return Reference_Type;
123
124    procedure Assign (Target : in out Map; Source : Map);
125
126    function Copy (Source : Map) return Map;
127
128    procedure Move (Target : in out Map; Source : in out Map);
129
130    procedure Insert
131      (Container : in out Map;
132       Key       : Key_Type;
133       New_Item  : Element_Type;
134       Position  : out Cursor;
135       Inserted  : out Boolean);
136
137    procedure Insert
138      (Container : in out Map;
139       Key       : Key_Type;
140       New_Item  : Element_Type);
141
142    procedure Include
143      (Container : in out Map;
144       Key       : Key_Type;
145       New_Item  : Element_Type);
146
147    procedure Replace
148      (Container : in out Map;
149       Key       : Key_Type;
150       New_Item  : Element_Type);
151
152    procedure Exclude (Container : in out Map; Key : Key_Type);
153
154    procedure Delete (Container : in out Map; Key : Key_Type);
155
156    procedure Delete (Container : in out Map; Position : in out Cursor);
157
158    procedure Delete_First (Container : in out Map);
159
160    procedure Delete_Last (Container : in out Map);
161
162    function First (Container : Map) return Cursor;
163
164    function First_Element (Container : Map) return Element_Type;
165
166    function First_Key (Container : Map) return Key_Type;
167
168    function Last (Container : Map) return Cursor;
169
170    function Last_Element (Container : Map) return Element_Type;
171
172    function Last_Key (Container : Map) return Key_Type;
173
174    function Next (Position : Cursor) return Cursor;
175
176    procedure Next (Position : in out Cursor);
177
178    function Previous (Position : Cursor) return Cursor;
179
180    procedure Previous (Position : in out Cursor);
181
182    function Find (Container : Map; Key : Key_Type) return Cursor;
183
184    function Element (Container : Map; Key : Key_Type) return Element_Type;
185
186    function Floor (Container : Map; Key : Key_Type) return Cursor;
187
188    function Ceiling (Container : Map; Key : Key_Type) return Cursor;
189
190    function Contains (Container : Map; Key : Key_Type) return Boolean;
191
192    function "<" (Left, Right : Cursor) return Boolean;
193
194    function ">" (Left, Right : Cursor) return Boolean;
195
196    function "<" (Left : Cursor; Right : Key_Type) return Boolean;
197
198    function ">" (Left : Cursor; Right : Key_Type) return Boolean;
199
200    function "<" (Left : Key_Type; Right : Cursor) return Boolean;
201
202    function ">" (Left : Key_Type; Right : Cursor) return Boolean;
203
204    procedure Iterate
205      (Container : Map;
206       Process   : not null access procedure (Position : Cursor));
207
208    procedure Reverse_Iterate
209      (Container : Map;
210       Process   : not null access procedure (Position : Cursor));
211
212    --  The map container supports iteration in both the forward and reverse
213    --  directions, hence these constructor functions return an object that
214    --  supports the Reversible_Iterator interface.
215
216    function Iterate
217      (Container : Map)
218       return Map_Iterator_Interfaces.Reversible_Iterator'Class;
219
220    function Iterate
221      (Container : Map;
222       Start     : Cursor)
223       return Map_Iterator_Interfaces.Reversible_Iterator'Class;
224
225 private
226
227    pragma Inline (Next);
228    pragma Inline (Previous);
229
230    type Node_Type;
231    type Node_Access is access Node_Type;
232
233    type Key_Access is access Key_Type;
234    type Element_Access is access Element_Type;
235
236    type Node_Type is limited record
237       Parent  : Node_Access;
238       Left    : Node_Access;
239       Right   : Node_Access;
240       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
241       Key     : Key_Access;
242       Element : Element_Access;
243    end record;
244
245    package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
246      (Node_Type,
247       Node_Access);
248
249    type Map is new Ada.Finalization.Controlled with record
250       Tree : Tree_Types.Tree_Type;
251    end record;
252
253    overriding procedure Adjust (Container : in out Map);
254
255    overriding procedure Finalize (Container : in out Map) renames Clear;
256
257    use Red_Black_Trees;
258    use Tree_Types;
259    use Ada.Finalization;
260    use Ada.Streams;
261
262    type Map_Access is access all Map;
263    for Map_Access'Storage_Size use 0;
264
265    type Cursor is record
266       Container : Map_Access;
267       Node      : Node_Access;
268    end record;
269
270    procedure Write
271      (Stream : not null access Root_Stream_Type'Class;
272       Item   : Cursor);
273
274    for Cursor'Write use Write;
275
276    procedure Read
277      (Stream : not null access Root_Stream_Type'Class;
278       Item   : out Cursor);
279
280    for Cursor'Read use Read;
281
282    No_Element : constant Cursor := Cursor'(null, null);
283
284    procedure Write
285      (Stream    : not null access Root_Stream_Type'Class;
286       Container : Map);
287
288    for Map'Write use Write;
289
290    procedure Read
291      (Stream    : not null access Root_Stream_Type'Class;
292       Container : out Map);
293
294    for Map'Read use Read;
295
296    type Constant_Reference_Type
297       (Element : not null access constant Element_Type) is null record;
298
299    procedure Read
300      (Stream : not null access Root_Stream_Type'Class;
301       Item   : out Constant_Reference_Type);
302
303    for Constant_Reference_Type'Read use Read;
304
305    procedure Write
306      (Stream : not null access Root_Stream_Type'Class;
307       Item   : Constant_Reference_Type);
308
309    for Constant_Reference_Type'Write use Write;
310
311    type Reference_Type
312       (Element : not null access Element_Type) is null record;
313
314    procedure Read
315      (Stream : not null access Root_Stream_Type'Class;
316       Item   : out Reference_Type);
317
318    for Reference_Type'Read use Read;
319
320    procedure Write
321      (Stream : not null access Root_Stream_Type'Class;
322       Item   : Reference_Type);
323
324    for Reference_Type'Write use Write;
325
326    Empty_Map : constant Map :=
327                  (Controlled with Tree => (First  => null,
328                                            Last   => null,
329                                            Root   => null,
330                                            Length => 0,
331                                            Busy   => 0,
332                                            Lock   => 0));
333
334 end Ada.Containers.Indefinite_Ordered_Maps;