OSDN Git Service

2005-06-14 Matthew Heaney <heaney@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-cdlili.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --   A D A . C O N T A I N E R S . D O U B L Y _ L I N K E D _ L I S T S    --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2005 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 2,  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.  See the GNU General Public License --
21 -- for  more details.  You should have  received  a copy of the GNU General --
22 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
23 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
24 -- MA 02111-1307, USA.                                                      --
25 --                                                                          --
26 -- As a special exception,  if other files  instantiate  generics from this --
27 -- unit, or you link  this unit with other files  to produce an executable, --
28 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
29 -- covered  by the  GNU  General  Public  License.  This exception does not --
30 -- however invalidate  any other reasons why  the executable file  might be --
31 -- covered by the  GNU Public License.                                      --
32 --                                                                          --
33 -- This unit was originally developed by Matthew J Heaney.                  --
34 ------------------------------------------------------------------------------
35
36 with Ada.Finalization;
37 with Ada.Streams;
38
39 generic
40    type Element_Type is private;
41
42    with function "=" (Left, Right : Element_Type)
43       return Boolean is <>;
44
45 package Ada.Containers.Doubly_Linked_Lists is
46    pragma Preelaborate (Doubly_Linked_Lists);
47
48    type List is tagged private;
49
50    type Cursor is private;
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 Query_Element
67      (Position : Cursor;
68       Process  : not null access procedure (Element : Element_Type));
69
70    procedure Update_Element
71      (Position : Cursor;
72       Process  : not null access procedure (Element : in out Element_Type));
73
74    procedure Replace_Element
75      (Position : Cursor;
76       By       : Element_Type);
77
78    procedure Move
79      (Target : in out List;
80       Source : in out List);
81
82    procedure Prepend
83      (Container : in out List;
84       New_Item  : Element_Type;
85       Count     : Count_Type := 1);
86
87    procedure Append
88      (Container : in out List;
89       New_Item  : Element_Type;
90       Count     : Count_Type := 1);
91
92    procedure Insert
93      (Container : in out List;
94       Before    : Cursor;
95       New_Item  : Element_Type;
96       Count     : Count_Type := 1);
97
98    procedure Insert
99      (Container : in out List;
100       Before    : Cursor;
101       New_Item  : Element_Type;
102       Position  : out Cursor;
103       Count     : Count_Type := 1);
104
105    procedure Insert
106      (Container : in out List;
107       Before    : Cursor;
108       Position  : out Cursor;
109       Count     : Count_Type := 1);
110
111    procedure Delete
112      (Container : in out List;
113       Position  : in out Cursor;
114       Count     : Count_Type := 1);
115
116    procedure Delete_First
117      (Container : in out List;
118       Count     : Count_Type := 1);
119
120    procedure Delete_Last
121      (Container : in out List;
122       Count     : Count_Type := 1);
123
124    generic
125       with function "<" (Left, Right : Element_Type) return Boolean is <>;
126    package Generic_Sorting is
127
128       function Is_Sorted (Container : List) return Boolean;
129
130       procedure Sort (Container : in out List);
131
132       procedure Merge (Target, Source : in out List);
133
134    end Generic_Sorting;
135
136    procedure Reverse_List (Container : in out List);
137
138    procedure Swap (I, J : Cursor);
139
140    procedure Swap_Links
141      (Container : in out List;
142       I, J      : Cursor);
143
144    procedure Splice
145      (Target : in out List;
146       Before : Cursor;
147       Source : in out List);
148
149    procedure Splice
150      (Target   : in out List;
151       Before   : Cursor;
152       Position : Cursor);
153
154    procedure Splice
155      (Target   : in out List;
156       Before   : Cursor;
157       Source   : in out List;
158       Position : in out Cursor);
159
160    function First (Container : List) return Cursor;
161
162    function First_Element (Container : List) return Element_Type;
163
164    function Last (Container : List) return Cursor;
165
166    function Last_Element (Container : List) return Element_Type;
167
168    function Contains
169      (Container : List;
170       Item      : Element_Type) return Boolean;
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 Next (Position : Cursor) return Cursor;
183
184    function Previous (Position : Cursor) return Cursor;
185
186    procedure Next (Position : in out Cursor);
187
188    procedure Previous (Position : in out Cursor);
189
190    function Has_Element (Position : Cursor) return Boolean;
191
192    procedure Iterate
193      (Container : List;
194       Process   : not null access procedure (Position : Cursor));
195
196    procedure Reverse_Iterate
197      (Container : List;
198       Process   : not null access procedure (Position : Cursor));
199
200 private
201    type Node_Type;
202    type Node_Access is access Node_Type;
203
204    type Node_Type is
205       limited record
206          Element : Element_Type;
207          Next    : Node_Access;
208          Prev    : Node_Access;
209       end record;
210
211    use Ada.Finalization;
212
213    type List is
214      new Controlled with record
215         First  : Node_Access;
216         Last   : Node_Access;
217         Length : Count_Type := 0;
218         Busy   : Natural := 0;
219         Lock   : Natural := 0;
220      end record;
221
222    procedure Adjust (Container : in out List);
223
224    procedure Finalize (Container : in out List) renames Clear;
225
226    use Ada.Streams;
227
228    procedure Read
229      (Stream : access Root_Stream_Type'Class;
230       Item   : out List);
231
232    for List'Read use Read;
233
234    procedure Write
235      (Stream : access Root_Stream_Type'Class;
236       Item   : List);
237
238    for List'Write use Write;
239
240    Empty_List : constant List := (Controlled with null, null, 0, 0, 0);
241
242    type List_Access is access constant List;
243    for List_Access'Storage_Size use 0;
244
245    type Cursor is
246       record
247          Container : List_Access;
248          Node      : Node_Access;
249       end record;
250
251    No_Element : constant Cursor := Cursor'(null, null);
252
253 end Ada.Containers.Doubly_Linked_Lists;