OSDN Git Service

PR preprocessor/20348
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cidlli.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                      A D A . C O N T A I N E R S .                       --
6 --        I N D E F I N I T E _ D O U B L Y _ L I N K E D _ L I S T S       --
7 --                                                                          --
8 --                                 S p e c                                  --
9 --                                                                          --
10 --          Copyright (C) 2004-2005 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- This specification is derived from the Ada Reference Manual for use with --
13 -- GNAT. The copyright notice above, and the license provisions that follow --
14 -- apply solely to the  contents of the part following the private keyword. --
15 --                                                                          --
16 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
17 -- terms of the  GNU General Public License as published  by the Free Soft- --
18 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
19 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
20 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
21 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
22 -- for  more details.  You should have  received  a copy of the GNU General --
23 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
24 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
25 -- Boston, MA 02110-1301, USA.                                              --
26 --                                                                          --
27 -- As a special exception,  if other files  instantiate  generics from this --
28 -- unit, or you link  this unit with other files  to produce an executable, --
29 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
30 -- covered  by the  GNU  General  Public  License.  This exception does not --
31 -- however invalidate  any other reasons why  the executable file  might be --
32 -- covered by the  GNU Public License.                                      --
33 --                                                                          --
34 -- This unit was originally developed by Matthew J Heaney.                  --
35 ------------------------------------------------------------------------------
36
37 with Ada.Finalization;
38 with Ada.Streams;
39
40 generic
41
42    type Element_Type (<>) is private;
43
44    with function "=" (Left, Right : Element_Type)
45       return Boolean is <>;
46
47 package Ada.Containers.Indefinite_Doubly_Linked_Lists is
48    pragma Preelaborate (Indefinite_Doubly_Linked_Lists);
49
50    type List is tagged private;
51
52    type Cursor is private;
53
54    Empty_List : constant List;
55
56    No_Element : constant Cursor;
57
58    function "=" (Left, Right : List) return Boolean;
59
60    function Length (Container : List) return Count_Type;
61
62    function Is_Empty (Container : List) return Boolean;
63
64    procedure Clear (Container : in out List);
65
66    function Element (Position : Cursor)
67       return Element_Type;
68
69    procedure Query_Element
70      (Position : Cursor;
71       Process  : not null access procedure (Element : Element_Type));
72
73    procedure Update_Element
74      (Position : Cursor;
75       Process  : not null access procedure (Element : in out Element_Type));
76
77    procedure Replace_Element
78      (Position : Cursor;
79       By       : Element_Type);
80
81    procedure Move
82      (Target : in out List;
83       Source : in out List);
84
85    procedure Prepend
86      (Container : in out List;
87       New_Item  : Element_Type;
88       Count     : Count_Type := 1);
89
90    procedure Append
91      (Container : in out List;
92       New_Item  : Element_Type;
93       Count     : Count_Type := 1);
94
95    procedure Insert
96      (Container : in out List;
97       Before    : Cursor;
98       New_Item  : Element_Type;
99       Count     : Count_Type := 1);
100
101    procedure Insert
102      (Container : in out List;
103       Before    : Cursor;
104       New_Item  : Element_Type;
105       Position  : out Cursor;
106       Count     : Count_Type := 1);
107
108    procedure Delete
109      (Container : in out List;
110       Position  : in out Cursor;
111       Count     : Count_Type := 1);
112
113    procedure Delete_First
114      (Container : in out List;
115       Count     : Count_Type := 1);
116
117    procedure Delete_Last
118      (Container : in out List;
119       Count     : Count_Type := 1);
120
121    generic
122       with function "<" (Left, Right : Element_Type) return Boolean is <>;
123    package Generic_Sorting is
124
125       function Is_Sorted (Container : List) return Boolean;
126
127       procedure Sort (Container : in out List);
128
129       procedure Merge (Target, Source : in out List);
130
131    end Generic_Sorting;
132
133    procedure Reverse_List (Container : in out List);
134
135    procedure Swap (I, J : Cursor);
136
137    procedure Swap_Links (Container : in out List; I, J : Cursor);
138
139    procedure Splice
140      (Target : in out List;
141       Before : Cursor;
142       Source : in out List);
143
144    procedure Splice
145      (Target   : in out List;
146       Before   : Cursor;
147       Position : Cursor);
148
149    procedure Splice
150      (Target   : in out List;
151       Before   : Cursor;
152       Source   : in out List;
153       Position : in out Cursor);
154
155    function First (Container : List) return Cursor;
156
157    function First_Element (Container : List) return Element_Type;
158
159    function Last (Container : List) return Cursor;
160
161    function Last_Element (Container : List) return Element_Type;
162
163    function Contains
164      (Container : List;
165       Item      : Element_Type) return Boolean;
166
167    function Find
168      (Container : List;
169       Item      : Element_Type;
170       Position  : Cursor := No_Element) return Cursor;
171
172    function Reverse_Find
173      (Container : List;
174       Item      : Element_Type;
175       Position  : Cursor := No_Element) return Cursor;
176
177    function Next (Position : Cursor) return Cursor;
178
179    function Previous (Position : Cursor) return Cursor;
180
181    procedure Next (Position : in out Cursor);
182
183    procedure Previous (Position : in out Cursor);
184
185    function Has_Element (Position : Cursor) return Boolean;
186
187    procedure Iterate
188      (Container : List;
189       Process   : not null access procedure (Position : Cursor));
190
191    procedure Reverse_Iterate
192      (Container : List;
193       Process   : not null access procedure (Position : Cursor));
194
195 private
196    type Node_Type;
197    type Node_Access is access Node_Type;
198
199    type Element_Access is access Element_Type;
200
201    type Node_Type is
202       limited record
203          Element : Element_Access;
204          Next    : Node_Access;
205          Prev    : Node_Access;
206       end record;
207
208    use Ada.Finalization;
209
210    type List is
211      new Controlled with record
212         First  : Node_Access;
213         Last   : Node_Access;
214         Length : Count_Type := 0;
215         Busy   : Natural := 0;
216         Lock   : Natural := 0;
217      end record;
218
219    procedure Adjust (Container : in out List);
220
221    procedure Finalize (Container : in out List) renames Clear;
222
223    use Ada.Streams;
224
225    procedure Read
226      (Stream : access Root_Stream_Type'Class;
227       Item   : out List);
228
229    for List'Read use Read;
230
231    procedure Write
232      (Stream : access Root_Stream_Type'Class;
233       Item   : List);
234
235    for List'Write use Write;
236
237    Empty_List : constant List := List'(Controlled with null, null, 0, 0, 0);
238
239    type List_Access is access constant List;
240    for List_Access'Storage_Size use 0;
241
242    type Cursor is
243       record
244          Container : List_Access;
245          Node      : Node_Access;
246       end record;
247
248    No_Element : constant Cursor := Cursor'(null, null);
249
250 end Ada.Containers.Indefinite_Doubly_Linked_Lists;