OSDN Git Service

2012-01-10 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-coorma.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --           A D A . C O N T A I N E R S . O R D E R E D _ M A P S          --
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 private with Ada.Containers.Red_Black_Trees;
35 private with Ada.Finalization;
36
37 with Ada.Streams; use Ada.Streams;
38 with Ada.Iterator_Interfaces;
39
40 generic
41    type Key_Type is private;
42    type Element_Type is private;
43
44    with function "<" (Left, Right : Key_Type) return Boolean is <>;
45    with function "=" (Left, Right : Element_Type) return Boolean is <>;
46
47 package Ada.Containers.Ordered_Maps is
48    pragma Preelaborate;
49    pragma Remote_Types;
50
51    function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
52
53    type Map is tagged private with
54       Constant_Indexing => Constant_Reference,
55       Variable_Indexing => Reference,
56       Default_Iterator  => Iterate,
57       Iterator_Element  => Element_Type;
58
59    type Cursor is private;
60    pragma Preelaborable_Initialization (Cursor);
61
62    Empty_Map : constant Map;
63
64    No_Element : constant Cursor;
65
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
91                    procedure (Key : Key_Type; Element : Element_Type));
92
93    procedure Update_Element
94      (Container : in out Map;
95       Position  : Cursor;
96       Process   : not null access
97                    procedure (Key : Key_Type; 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       Position  : out Cursor;
141       Inserted  : out Boolean);
142
143    procedure Insert
144      (Container : in out Map;
145       Key       : Key_Type;
146       New_Item  : Element_Type);
147
148    procedure Include
149      (Container : in out Map;
150       Key       : Key_Type;
151       New_Item  : Element_Type);
152
153    procedure Replace
154      (Container : in out Map;
155       Key       : Key_Type;
156       New_Item  : Element_Type);
157
158    procedure Exclude (Container : in out Map; Key : Key_Type);
159
160    procedure Delete (Container : in out Map; Key : Key_Type);
161
162    procedure Delete (Container : in out Map; Position : in out Cursor);
163
164    procedure Delete_First (Container : in out Map);
165
166    procedure Delete_Last (Container : in out Map);
167
168    function First (Container : Map) return Cursor;
169
170    function First_Element (Container : Map) return Element_Type;
171
172    function First_Key (Container : Map) return Key_Type;
173
174    function Last (Container : Map) return Cursor;
175
176    function Last_Element (Container : Map) return Element_Type;
177
178    function Last_Key (Container : Map) return Key_Type;
179
180    function Next (Position : Cursor) return Cursor;
181
182    procedure Next (Position : in out Cursor);
183
184    function Previous (Position : Cursor) return Cursor;
185
186    procedure Previous (Position : in out Cursor);
187
188    function Find (Container : Map; Key : Key_Type) return Cursor;
189
190    function Element (Container : Map; Key : Key_Type) return Element_Type;
191
192    function Floor (Container : Map; Key : Key_Type) return Cursor;
193
194    function Ceiling (Container : Map; Key : Key_Type) return Cursor;
195
196    function Contains (Container : Map; Key : Key_Type) return Boolean;
197
198    function "<" (Left, Right : Cursor) return Boolean;
199
200    function ">" (Left, Right : Cursor) return Boolean;
201
202    function "<" (Left : Cursor; Right : Key_Type) return Boolean;
203
204    function ">" (Left : Cursor; Right : Key_Type) return Boolean;
205
206    function "<" (Left : Key_Type; Right : Cursor) return Boolean;
207
208    function ">" (Left : Key_Type; Right : Cursor) return Boolean;
209
210    procedure Iterate
211      (Container : Map;
212       Process   : not null access procedure (Position : Cursor));
213
214    procedure Reverse_Iterate
215      (Container : Map;
216       Process   : not null access procedure (Position : Cursor));
217
218    --  The map container supports iteration in both the forward and reverse
219    --  directions, hence these constructor functions return an object that
220    --  supports the Reversible_Iterator interface.
221
222    function Iterate
223      (Container : Map)
224       return Map_Iterator_Interfaces.Reversible_Iterator'class;
225
226    function Iterate
227      (Container : Map;
228       Start     : Cursor)
229       return Map_Iterator_Interfaces.Reversible_Iterator'class;
230
231 private
232
233    pragma Inline (Next);
234    pragma Inline (Previous);
235
236    type Node_Type;
237    type Node_Access is access Node_Type;
238
239    type Node_Type is limited record
240       Parent  : Node_Access;
241       Left    : Node_Access;
242       Right   : Node_Access;
243       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
244       Key     : Key_Type;
245       Element : aliased Element_Type;
246    end record;
247
248    package Tree_Types is
249      new Red_Black_Trees.Generic_Tree_Types (Node_Type, Node_Access);
250
251    type Map is new Ada.Finalization.Controlled with record
252       Tree : Tree_Types.Tree_Type;
253    end record;
254
255    overriding procedure Adjust (Container : in out Map);
256
257    overriding procedure Finalize (Container : in out Map) renames Clear;
258
259    use Red_Black_Trees;
260    use Tree_Types;
261    use Ada.Finalization;
262
263    type Map_Access is access all Map;
264    for Map_Access'Storage_Size use 0;
265
266    type Cursor is record
267       Container : Map_Access;
268       Node      : Node_Access;
269    end record;
270
271    procedure Write
272      (Stream : not null access Root_Stream_Type'Class;
273       Item   : Cursor);
274
275    for Cursor'Write use Write;
276
277    procedure Read
278      (Stream : not null access Root_Stream_Type'Class;
279       Item   : out Cursor);
280
281    for Cursor'Read use Read;
282
283    No_Element : constant Cursor := Cursor'(null, null);
284
285    procedure Write
286      (Stream    : not null access Root_Stream_Type'Class;
287       Container : Map);
288
289    for Map'Write use Write;
290
291    procedure Read
292      (Stream    : not null access Root_Stream_Type'Class;
293       Container : out Map);
294
295    for Map'Read use Read;
296
297    type Constant_Reference_Type
298       (Element : not null access constant Element_Type) is null record;
299
300    type Reference_Type
301       (Element : not null access Element_Type) is null record;
302
303    procedure Read
304      (Stream : not null access Root_Stream_Type'Class;
305       Item   : out Reference_Type);
306
307    for Reference_Type'Read use Read;
308
309    procedure Write
310      (Stream : not null access Root_Stream_Type'Class;
311       Item   : Reference_Type);
312
313    for Reference_Type'Write use Write;
314
315    procedure Read
316      (Stream : not null access Root_Stream_Type'Class;
317       Item   : out Constant_Reference_Type);
318
319    for Constant_Reference_Type'Read use Read;
320
321    procedure Write
322      (Stream : not null access Root_Stream_Type'Class;
323       Item   : Constant_Reference_Type);
324
325    for Constant_Reference_Type'Write use Write;
326
327    Empty_Map : constant Map :=
328                  (Controlled with Tree => (First  => null,
329                                            Last   => null,
330                                            Root   => null,
331                                            Length => 0,
332                                            Busy   => 0,
333                                            Lock   => 0));
334 end Ada.Containers.Ordered_Maps;