OSDN Git Service

2010-12-09 Steven G. Kargl <kargl@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cbdlli.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --               ADA.CONTAINERS.BOUNDED_DOUBLY_LINKED_LISTS                 --
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.Streams;
35
36 generic
37    type Element_Type is private;
38
39    with function "=" (Left, Right : Element_Type)
40       return Boolean is <>;
41
42 package Ada.Containers.Bounded_Doubly_Linked_Lists is
43    pragma Pure;
44    pragma Remote_Types;
45
46    type List (Capacity : Count_Type) is tagged private;
47    pragma Preelaborable_Initialization (List);
48
49    type Cursor is private;
50    pragma Preelaborable_Initialization (Cursor);
51
52    Empty_List : constant List;
53
54    No_Element : constant Cursor;
55
56    function "=" (Left, Right : List) return Boolean;
57
58    function Length (Container : List) return Count_Type;
59
60    function Is_Empty (Container : List) return Boolean;
61
62    procedure Clear (Container : in out List);
63
64    function Element (Position : Cursor) return Element_Type;
65
66    procedure Replace_Element
67      (Container : in out List;
68       Position  : Cursor;
69       New_Item  : Element_Type);
70
71    procedure Query_Element
72      (Position : Cursor;
73       Process  : not null access procedure (Element : Element_Type));
74
75    procedure Update_Element
76      (Container : in out List;
77       Position  : Cursor;
78       Process   : not null access procedure (Element : in out Element_Type));
79
80    procedure Assign (Target : in out List; Source : List);
81
82    function Copy (Source : List; Capacity : Count_Type := 0) return List;
83
84    procedure Move
85      (Target : in out List;
86       Source : in out List);
87
88    procedure Insert
89      (Container : in out List;
90       Before    : Cursor;
91       New_Item  : Element_Type;
92       Count     : Count_Type := 1);
93
94    procedure Insert
95      (Container : in out List;
96       Before    : Cursor;
97       New_Item  : Element_Type;
98       Position  : out Cursor;
99       Count     : Count_Type := 1);
100
101    procedure Insert
102      (Container : in out List;
103       Before    : Cursor;
104       Position  : out Cursor;
105       Count     : Count_Type := 1);
106
107    procedure Prepend
108      (Container : in out List;
109       New_Item  : Element_Type;
110       Count     : Count_Type := 1);
111
112    procedure Append
113      (Container : in out List;
114       New_Item  : Element_Type;
115       Count     : Count_Type := 1);
116
117    procedure Delete
118      (Container : in out List;
119       Position  : in out Cursor;
120       Count     : Count_Type := 1);
121
122    procedure Delete_First
123      (Container : in out List;
124       Count     : Count_Type := 1);
125
126    procedure Delete_Last
127      (Container : in out List;
128       Count     : Count_Type := 1);
129
130    procedure Reverse_Elements (Container : in out List);
131
132    procedure Swap
133      (Container : in out List;
134       I, J      : Cursor);
135
136    procedure Swap_Links
137      (Container : in out List;
138       I, J      : Cursor);
139
140    procedure Splice
141      (Target : in out List;
142       Before : Cursor;
143       Source : in out List);
144
145    procedure Splice
146      (Target   : in out List;
147       Before   : Cursor;
148       Source   : in out List;
149       Position : in out Cursor);
150
151    procedure Splice
152      (Container : in out List;
153       Before    : Cursor;
154       Position  : Cursor);
155
156    function First (Container : List) return Cursor;
157
158    function First_Element (Container : List) return Element_Type;
159
160    function Last (Container : List) return Cursor;
161
162    function Last_Element (Container : List) return Element_Type;
163
164    function Next (Position : Cursor) return Cursor;
165
166    procedure Next (Position : in out Cursor);
167
168    function Previous (Position : Cursor) return Cursor;
169
170    procedure Previous (Position : in out Cursor);
171
172    function Find
173      (Container : List;
174       Item      : Element_Type;
175       Position  : Cursor := No_Element) return Cursor;
176
177    function Reverse_Find
178      (Container : List;
179       Item      : Element_Type;
180       Position  : Cursor := No_Element) return Cursor;
181
182    function Contains
183      (Container : List;
184       Item      : Element_Type) return Boolean;
185
186    function Has_Element (Position : Cursor) return Boolean;
187
188    procedure Iterate
189      (Container : List;
190       Process   : not null access procedure (Position : Cursor));
191
192    procedure Reverse_Iterate
193      (Container : List;
194       Process   : not null access procedure (Position : Cursor));
195
196    generic
197       with function "<" (Left, Right : Element_Type) return Boolean is <>;
198    package Generic_Sorting is
199
200       function Is_Sorted (Container : List) return Boolean;
201
202       procedure Sort (Container : in out List);
203
204       procedure Merge (Target, Source : in out List);
205
206    end Generic_Sorting;
207
208 private
209
210    pragma Inline (Next);
211    pragma Inline (Previous);
212
213    type Node_Type is record
214       Prev    : Count_Type'Base;
215       Next    : Count_Type;
216       Element : Element_Type;
217    end record;
218
219    type Node_Array is array (Count_Type range <>) of Node_Type;
220
221    type List (Capacity : Count_Type) is tagged record
222       Nodes  : Node_Array (1 .. Capacity) := (others => <>);
223       Free   : Count_Type'Base := -1;
224       First  : Count_Type := 0;
225       Last   : Count_Type := 0;
226       Length : Count_Type := 0;
227       Busy   : Natural := 0;
228       Lock   : Natural := 0;
229    end record;
230
231    use Ada.Streams;
232
233    procedure Read
234      (Stream : not null access Root_Stream_Type'Class;
235       Item   : out List);
236
237    for List'Read use Read;
238
239    procedure Write
240      (Stream : not null access Root_Stream_Type'Class;
241       Item   : List);
242
243    for List'Write use Write;
244
245    type List_Access is access all List;
246    for List_Access'Storage_Size use 0;
247
248    type Cursor is
249       record
250          Container : List_Access;
251          Node      : Count_Type := 0;
252       end record;
253
254    procedure Read
255      (Stream : not null access Root_Stream_Type'Class;
256       Item   : out Cursor);
257
258    for Cursor'Read use Read;
259
260    procedure Write
261      (Stream : not null access Root_Stream_Type'Class;
262       Item   : Cursor);
263
264    for Cursor'Write use Write;
265
266    Empty_List : constant List := (Capacity => 0, others => <>);
267
268    No_Element : constant Cursor := Cursor'(null, 0);
269
270 end Ada.Containers.Bounded_Doubly_Linked_Lists;