fixing pr42337
[official-gcc.git] / gcc / ada / a-ciorma.ads
blob1ef581554dcb51aa84816fa4ffe657f7f9723f3a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.INDEFINITE_ORDERED_MAPS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2009, 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 ------------------------------------------------------------------------------
34 private with Ada.Containers.Red_Black_Trees;
35 private with Ada.Finalization;
36 private with Ada.Streams;
38 generic
39 type Key_Type (<>) is private;
40 type Element_Type (<>) is private;
42 with function "<" (Left, Right : Key_Type) return Boolean is <>;
43 with function "=" (Left, Right : Element_Type) return Boolean is <>;
45 package Ada.Containers.Indefinite_Ordered_Maps is
46 pragma Preelaborate;
47 pragma Remote_Types;
49 function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
51 type Map is tagged private;
52 pragma Preelaborable_Initialization (Map);
54 type Cursor is private;
55 pragma Preelaborable_Initialization (Cursor);
57 Empty_Map : constant Map;
59 No_Element : constant Cursor;
61 function "=" (Left, Right : Map) return Boolean;
63 function Length (Container : Map) return Count_Type;
65 function Is_Empty (Container : Map) return Boolean;
67 procedure Clear (Container : in out Map);
69 function Key (Position : Cursor) return Key_Type;
71 function Element (Position : Cursor) return Element_Type;
73 procedure Replace_Element
74 (Container : in out Map;
75 Position : Cursor;
76 New_Item : Element_Type);
78 procedure Query_Element
79 (Position : Cursor;
80 Process : not null access procedure (Key : Key_Type;
81 Element : Element_Type));
83 procedure Update_Element
84 (Container : in out Map;
85 Position : Cursor;
86 Process : not null access procedure (Key : Key_Type;
87 Element : in out Element_Type));
89 procedure Move (Target : in out Map; Source : in out Map);
91 procedure Insert
92 (Container : in out Map;
93 Key : Key_Type;
94 New_Item : Element_Type;
95 Position : out Cursor;
96 Inserted : out Boolean);
98 procedure Insert
99 (Container : in out Map;
100 Key : Key_Type;
101 New_Item : Element_Type);
103 procedure Include
104 (Container : in out Map;
105 Key : Key_Type;
106 New_Item : Element_Type);
108 procedure Replace
109 (Container : in out Map;
110 Key : Key_Type;
111 New_Item : Element_Type);
113 procedure Exclude (Container : in out Map; Key : Key_Type);
115 procedure Delete (Container : in out Map; Key : Key_Type);
117 procedure Delete (Container : in out Map; Position : in out Cursor);
119 procedure Delete_First (Container : in out Map);
121 procedure Delete_Last (Container : in out Map);
123 function First (Container : Map) return Cursor;
125 function First_Element (Container : Map) return Element_Type;
127 function First_Key (Container : Map) return Key_Type;
129 function Last (Container : Map) return Cursor;
131 function Last_Element (Container : Map) return Element_Type;
133 function Last_Key (Container : Map) return Key_Type;
135 function Next (Position : Cursor) return Cursor;
137 procedure Next (Position : in out Cursor);
139 function Previous (Position : Cursor) return Cursor;
141 procedure Previous (Position : in out Cursor);
143 function Find (Container : Map; Key : Key_Type) return Cursor;
145 function Element (Container : Map; Key : Key_Type) return Element_Type;
147 function Floor (Container : Map; Key : Key_Type) return Cursor;
149 function Ceiling (Container : Map; Key : Key_Type) return Cursor;
151 function Contains (Container : Map; Key : Key_Type) return Boolean;
153 function Has_Element (Position : Cursor) return Boolean;
155 function "<" (Left, Right : Cursor) return Boolean;
157 function ">" (Left, Right : Cursor) return Boolean;
159 function "<" (Left : Cursor; Right : Key_Type) return Boolean;
161 function ">" (Left : Cursor; Right : Key_Type) return Boolean;
163 function "<" (Left : Key_Type; Right : Cursor) return Boolean;
165 function ">" (Left : Key_Type; Right : Cursor) return Boolean;
167 procedure Iterate
168 (Container : Map;
169 Process : not null access procedure (Position : Cursor));
171 procedure Reverse_Iterate
172 (Container : Map;
173 Process : not null access procedure (Position : Cursor));
175 private
177 pragma Inline (Next);
178 pragma Inline (Previous);
180 type Node_Type;
181 type Node_Access is access Node_Type;
183 type Key_Access is access Key_Type;
184 type Element_Access is access Element_Type;
186 type Node_Type is limited record
187 Parent : Node_Access;
188 Left : Node_Access;
189 Right : Node_Access;
190 Color : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
191 Key : Key_Access;
192 Element : Element_Access;
193 end record;
195 package Tree_Types is new Red_Black_Trees.Generic_Tree_Types
196 (Node_Type,
197 Node_Access);
199 type Map is new Ada.Finalization.Controlled with record
200 Tree : Tree_Types.Tree_Type;
201 end record;
203 overriding
204 procedure Adjust (Container : in out Map);
206 overriding
207 procedure Finalize (Container : in out Map) renames Clear;
209 use Red_Black_Trees;
210 use Tree_Types;
211 use Ada.Finalization;
212 use Ada.Streams;
214 type Map_Access is access all Map;
215 for Map_Access'Storage_Size use 0;
217 type Cursor is record
218 Container : Map_Access;
219 Node : Node_Access;
220 end record;
222 procedure Write
223 (Stream : not null access Root_Stream_Type'Class;
224 Item : Cursor);
226 for Cursor'Write use Write;
228 procedure Read
229 (Stream : not null access Root_Stream_Type'Class;
230 Item : out Cursor);
232 for Cursor'Read use Read;
234 No_Element : constant Cursor := Cursor'(null, null);
236 procedure Write
237 (Stream : not null access Root_Stream_Type'Class;
238 Container : Map);
240 for Map'Write use Write;
242 procedure Read
243 (Stream : not null access Root_Stream_Type'Class;
244 Container : out Map);
246 for Map'Read use Read;
248 Empty_Map : constant Map :=
249 (Controlled with Tree => (First => null,
250 Last => null,
251 Root => null,
252 Length => 0,
253 Busy => 0,
254 Lock => 0));
256 end Ada.Containers.Indefinite_Ordered_Maps;