OSDN Git Service

2010-10-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cborma.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --   A D A . C O N T A I N E R S . B O U N D E D _ O R D E R E D _ M A P S  --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2010, 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.Streams;
36
37 generic
38    type Key_Type is private;
39    type Element_Type is private;
40
41    with function "<" (Left, Right : Key_Type) return Boolean is <>;
42    with function "=" (Left, Right : Element_Type) return Boolean is <>;
43
44 package Ada.Containers.Bounded_Ordered_Maps is
45    pragma Pure;
46    pragma Remote_Types;
47
48    function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
49
50    type Map (Capacity : Count_Type) is tagged private;
51    pragma Preelaborable_Initialization (Map);
52
53    type Cursor is private;
54    pragma Preelaborable_Initialization (Cursor);
55
56    Empty_Map : constant Map;
57
58    No_Element : constant Cursor;
59
60    function "=" (Left, Right : Map) return Boolean;
61
62    function Length (Container : Map) return Count_Type;
63
64    function Is_Empty (Container : Map) return Boolean;
65
66    procedure Clear (Container : in out Map);
67
68    function Key (Position : Cursor) return Key_Type;
69
70    function Element (Position : Cursor) return Element_Type;
71
72    procedure Replace_Element
73      (Container : in out Map;
74       Position  : Cursor;
75       New_Item  : Element_Type);
76
77    procedure Query_Element
78      (Position : Cursor;
79       Process  : not null access
80                    procedure (Key : Key_Type; Element : Element_Type));
81
82    procedure Update_Element
83      (Container : in out Map;
84       Position  : Cursor;
85       Process   : not null access
86                    procedure (Key : Key_Type; Element : in out Element_Type));
87
88    procedure Assign (Target : in out Map; Source : Map);
89
90    function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
91
92    procedure Move (Target : in out Map; Source : in out Map);
93
94    procedure Insert
95      (Container : in out Map;
96       Key       : Key_Type;
97       New_Item  : Element_Type;
98       Position  : out Cursor;
99       Inserted  : out Boolean);
100
101    procedure Insert
102      (Container : in out Map;
103       Key       : Key_Type;
104       Position  : out Cursor;
105       Inserted  : out Boolean);
106
107    procedure Insert
108      (Container : in out Map;
109       Key       : Key_Type;
110       New_Item  : Element_Type);
111
112    procedure Include
113      (Container : in out Map;
114       Key       : Key_Type;
115       New_Item  : Element_Type);
116
117    procedure Replace
118      (Container : in out Map;
119       Key       : Key_Type;
120       New_Item  : Element_Type);
121
122    procedure Exclude (Container : in out Map; Key : Key_Type);
123
124    procedure Delete (Container : in out Map; Key : Key_Type);
125
126    procedure Delete (Container : in out Map; Position : in out Cursor);
127
128    procedure Delete_First (Container : in out Map);
129
130    procedure Delete_Last (Container : in out Map);
131
132    function First (Container : Map) return Cursor;
133
134    function First_Element (Container : Map) return Element_Type;
135
136    function First_Key (Container : Map) return Key_Type;
137
138    function Last (Container : Map) return Cursor;
139
140    function Last_Element (Container : Map) return Element_Type;
141
142    function Last_Key (Container : Map) return Key_Type;
143
144    function Next (Position : Cursor) return Cursor;
145
146    procedure Next (Position : in out Cursor);
147
148    function Previous (Position : Cursor) return Cursor;
149
150    procedure Previous (Position : in out Cursor);
151
152    function Find (Container : Map; Key : Key_Type) return Cursor;
153
154    function Element (Container : Map; Key : Key_Type) return Element_Type;
155
156    function Floor (Container : Map; Key : Key_Type) return Cursor;
157
158    function Ceiling (Container : Map; Key : Key_Type) return Cursor;
159
160    function Contains (Container : Map; Key : Key_Type) return Boolean;
161
162    function Has_Element (Position : Cursor) return Boolean;
163
164    function "<" (Left, Right : Cursor) return Boolean;
165
166    function ">" (Left, Right : Cursor) return Boolean;
167
168    function "<" (Left : Cursor; Right : Key_Type) return Boolean;
169
170    function ">" (Left : Cursor; Right : Key_Type) return Boolean;
171
172    function "<" (Left : Key_Type; Right : Cursor) return Boolean;
173
174    function ">" (Left : Key_Type; Right : Cursor) return Boolean;
175
176    procedure Iterate
177      (Container : Map;
178       Process   : not null access procedure (Position : Cursor));
179
180    procedure Reverse_Iterate
181      (Container : Map;
182       Process   : not null access procedure (Position : Cursor));
183
184 private
185
186    pragma Inline (Next);
187    pragma Inline (Previous);
188
189    type Node_Type is record
190       Parent  : Count_Type;
191       Left    : Count_Type;
192       Right   : Count_Type;
193       Color   : Red_Black_Trees.Color_Type := Red_Black_Trees.Red;
194       Key     : Key_Type;
195       Element : Element_Type;
196    end record;
197
198    package Tree_Types is
199      new Red_Black_Trees.Generic_Bounded_Tree_Types (Node_Type);
200
201    type Map (Capacity : Count_Type) is
202      new Tree_Types.Tree_Type (Capacity) with null record;
203
204    type Map_Access is access all Map;
205    for Map_Access'Storage_Size use 0;
206
207    use Red_Black_Trees;
208    use Tree_Types;
209    use Ada.Streams;
210
211    type Cursor is record
212       Container : Map_Access;
213       Node      : Count_Type;
214    end record;
215
216    procedure Write
217      (Stream : not null access Root_Stream_Type'Class;
218       Item   : Cursor);
219
220    for Cursor'Write use Write;
221
222    procedure Read
223      (Stream : not null access Root_Stream_Type'Class;
224       Item   : out Cursor);
225
226    for Cursor'Read use Read;
227
228    No_Element : constant Cursor := Cursor'(null, 0);
229
230    procedure Write
231      (Stream    : not null access Root_Stream_Type'Class;
232       Container : Map);
233
234    for Map'Write use Write;
235
236    procedure Read
237      (Stream    : not null access Root_Stream_Type'Class;
238       Container : out Map);
239
240    for Map'Read use Read;
241
242    Empty_Map : constant Map := Map'(Tree_Type with Capacity => 0);
243
244 end Ada.Containers.Bounded_Ordered_Maps;