1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_ORDERED_MAPS --
9 -- Copyright (C) 2004-2011, Free Software Foundation, Inc. --
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. --
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. --
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. --
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/>. --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada
.Iterator_Interfaces
;
35 private with Ada
.Containers
.Red_Black_Trees
;
36 private with Ada
.Finalization
;
37 private with Ada
.Streams
;
40 type Key_Type
(<>) is private;
41 type Element_Type
(<>) is private;
43 with function "<" (Left
, Right
: Key_Type
) return Boolean is <>;
44 with function "=" (Left
, Right
: Element_Type
) return Boolean is <>;
46 package Ada
.Containers
.Indefinite_Ordered_Maps
is
50 function Equivalent_Keys
(Left
, Right
: Key_Type
) return Boolean;
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
;
58 pragma Preelaborable_Initialization
(Map
);
60 type Cursor
is private;
61 pragma Preelaborable_Initialization
(Cursor
);
63 Empty_Map
: constant Map
;
65 No_Element
: constant Cursor
;
66 function Has_Element
(Position
: Cursor
) return Boolean;
68 package Map_Iterator_Interfaces
is new
69 Ada
.Iterator_Interfaces
(Cursor
, Has_Element
);
71 function "=" (Left
, Right
: Map
) return Boolean;
73 function Length
(Container
: Map
) return Count_Type
;
75 function Is_Empty
(Container
: Map
) return Boolean;
77 procedure Clear
(Container
: in out Map
);
79 function Key
(Position
: Cursor
) return Key_Type
;
81 function Element
(Position
: Cursor
) return Element_Type
;
83 procedure Replace_Element
84 (Container
: in out Map
;
86 New_Item
: Element_Type
);
88 procedure Query_Element
90 Process
: not null access procedure (Key
: Key_Type
;
91 Element
: Element_Type
));
93 procedure Update_Element
94 (Container
: in out Map
;
96 Process
: not null access procedure (Key
: Key_Type
;
97 Element
: in out Element_Type
));
99 procedure Assign
(Target
: in out Map
; Source
: Map
);
101 function Copy
(Source
: Map
) return Map
;
103 procedure Move
(Target
: in out Map
; Source
: in out Map
);
106 (Container
: in out Map
;
108 New_Item
: Element_Type
;
109 Position
: out Cursor
;
110 Inserted
: out Boolean);
113 (Container
: in out Map
;
115 New_Item
: Element_Type
);
118 (Container
: in out Map
;
120 New_Item
: Element_Type
);
123 (Container
: in out Map
;
125 New_Item
: Element_Type
);
127 procedure Exclude
(Container
: in out Map
; Key
: Key_Type
);
129 procedure Delete
(Container
: in out Map
; Key
: Key_Type
);
131 procedure Delete
(Container
: in out Map
; Position
: in out Cursor
);
133 procedure Delete_First
(Container
: in out Map
);
135 procedure Delete_Last
(Container
: in out Map
);
137 function First
(Container
: Map
) return Cursor
;
139 function First_Element
(Container
: Map
) return Element_Type
;
141 function First_Key
(Container
: Map
) return Key_Type
;
143 function Last
(Container
: Map
) return Cursor
;
145 function Last_Element
(Container
: Map
) return Element_Type
;
147 function Last_Key
(Container
: Map
) return Key_Type
;
149 function Next
(Position
: Cursor
) return Cursor
;
151 procedure Next
(Position
: in out Cursor
);
153 function Previous
(Position
: Cursor
) return Cursor
;
155 procedure Previous
(Position
: in out Cursor
);
157 function Find
(Container
: Map
; Key
: Key_Type
) return Cursor
;
159 function Element
(Container
: Map
; Key
: Key_Type
) return Element_Type
;
161 function Floor
(Container
: Map
; Key
: Key_Type
) return Cursor
;
163 function Ceiling
(Container
: Map
; Key
: Key_Type
) return Cursor
;
165 function Contains
(Container
: Map
; Key
: Key_Type
) return Boolean;
167 function "<" (Left
, Right
: Cursor
) return Boolean;
169 function ">" (Left
, Right
: Cursor
) return Boolean;
171 function "<" (Left
: Cursor
; Right
: Key_Type
) return Boolean;
173 function ">" (Left
: Cursor
; Right
: Key_Type
) return Boolean;
175 function "<" (Left
: Key_Type
; Right
: Cursor
) return Boolean;
177 function ">" (Left
: Key_Type
; Right
: Cursor
) return Boolean;
179 type Constant_Reference_Type
180 (Element
: not null access constant Element_Type
) is private
182 Implicit_Dereference
=> Element
;
184 type Reference_Type
(Element
: not null access Element_Type
) is private
186 Implicit_Dereference
=> Element
;
188 function Constant_Reference
190 Key
: Key_Type
) return Constant_Reference_Type
;
194 Key
: Key_Type
) return Reference_Type
;
198 Process
: not null access procedure (Position
: Cursor
));
200 procedure Reverse_Iterate
202 Process
: not null access procedure (Position
: Cursor
));
204 -- The map container supports iteration in both the forward and reverse
205 -- directions, hence these constructor functions return an object that
206 -- supports the Reversible_Iterator interface.
210 return Map_Iterator_Interfaces
.Reversible_Iterator
'Class;
215 return Map_Iterator_Interfaces
.Reversible_Iterator
'Class;
219 pragma Inline
(Next
);
220 pragma Inline
(Previous
);
223 type Node_Access
is access Node_Type
;
225 type Key_Access
is access Key_Type
;
226 type Element_Access
is access Element_Type
;
228 type Node_Type
is limited record
229 Parent
: Node_Access
;
232 Color
: Red_Black_Trees
.Color_Type
:= Red_Black_Trees
.Red
;
234 Element
: Element_Access
;
237 package Tree_Types
is new Red_Black_Trees
.Generic_Tree_Types
241 type Map
is new Ada
.Finalization
.Controlled
with record
242 Tree
: Tree_Types
.Tree_Type
;
245 overriding
procedure Adjust
(Container
: in out Map
);
247 overriding
procedure Finalize
(Container
: in out Map
) renames Clear
;
251 use Ada
.Finalization
;
254 type Map_Access
is access all Map
;
255 for Map_Access
'Storage_Size use 0;
257 type Cursor
is record
258 Container
: Map_Access
;
263 (Stream
: not null access Root_Stream_Type
'Class;
266 for Cursor
'Write use Write
;
269 (Stream
: not null access Root_Stream_Type
'Class;
272 for Cursor
'Read use Read
;
274 No_Element
: constant Cursor
:= Cursor
'(null, null);
277 (Stream : not null access Root_Stream_Type'Class;
280 for Map'Write use Write;
283 (Stream : not null access Root_Stream_Type'Class;
284 Container : out Map);
286 for Map'Read use Read;
288 type Constant_Reference_Type
289 (Element : not null access constant Element_Type) is null record;
292 (Stream : not null access Root_Stream_Type'Class;
293 Item : out Constant_Reference_Type);
295 for Constant_Reference_Type'Read use Read;
298 (Stream : not null access Root_Stream_Type'Class;
299 Item : Constant_Reference_Type);
301 for Constant_Reference_Type'Write use Write;
304 (Element : not null access Element_Type) is null record;
307 (Stream : not null access Root_Stream_Type'Class;
308 Item : out Reference_Type);
310 for Reference_Type'Read use Read;
313 (Stream : not null access Root_Stream_Type'Class;
314 Item : Reference_Type);
316 for Reference_Type'Write use Write;
318 Empty_Map : constant Map :=
319 (Controlled with Tree => (First => null,
326 end Ada.Containers.Indefinite_Ordered_Maps;