OSDN Git Service

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