OSDN Git Service

2008-03-24 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-crdlli.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --              ADA.CONTAINERS.RESTRICTED_DOUBLY_LINKED_LISTS               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2004-2007, 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,  51  Franklin  Street,  Fifth  Floor, --
24 -- Boston, MA 02110-1301, 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 --  Documentation required for this unit ???
37
38 generic
39    type Element_Type is private;
40
41    with function "=" (Left, Right : Element_Type)
42       return Boolean is <>;
43
44 package Ada.Containers.Restricted_Doubly_Linked_Lists is
45    pragma Pure;
46
47    type List (Capacity : Count_Type) is tagged limited private;
48    pragma Preelaborable_Initialization (List);
49
50    type Cursor is private;
51    pragma Preelaborable_Initialization (Cursor);
52
53    Empty_List : constant List;
54
55    No_Element : constant Cursor;
56
57    function "=" (Left, Right : List) return Boolean;
58
59    procedure Assign (Target : in out List; Source : List);
60
61    function Length (Container : List) return Count_Type;
62
63    function Is_Empty (Container : List) return Boolean;
64
65    procedure Clear (Container : in out List);
66
67    function Element (Position : Cursor) return Element_Type;
68
69    procedure Replace_Element
70      (Container : in out List;
71       Position  : Cursor;
72       New_Item  : Element_Type);
73
74    procedure Query_Element
75      (Position : Cursor;
76       Process  : not null access procedure (Element : Element_Type));
77
78    procedure Update_Element
79      (Container : in out List;
80       Position  : Cursor;
81       Process   : not null access procedure (Element : in out Element_Type));
82
83    procedure Insert
84      (Container : in out List;
85       Before    : Cursor;
86       New_Item  : Element_Type;
87       Count     : Count_Type := 1);
88
89    procedure Insert
90      (Container : in out List;
91       Before    : Cursor;
92       New_Item  : Element_Type;
93       Position  : out Cursor;
94       Count     : Count_Type := 1);
95
96    procedure Insert
97      (Container : in out List;
98       Before    : Cursor;
99       Position  : out Cursor;
100       Count     : Count_Type := 1);
101
102    procedure Prepend
103      (Container : in out List;
104       New_Item  : Element_Type;
105       Count     : Count_Type := 1);
106
107    procedure Append
108      (Container : in out List;
109       New_Item  : Element_Type;
110       Count     : Count_Type := 1);
111
112    procedure Delete
113      (Container : in out List;
114       Position  : in out Cursor;
115       Count     : Count_Type := 1);
116
117    procedure Delete_First
118      (Container : in out List;
119       Count     : Count_Type := 1);
120
121    procedure Delete_Last
122      (Container : in out List;
123       Count     : Count_Type := 1);
124
125    procedure Reverse_Elements (Container : in out List);
126
127    procedure Swap
128      (Container : in out List;
129       I, J      : Cursor);
130
131    procedure Swap_Links
132      (Container : in out List;
133       I, J      : Cursor);
134
135    procedure Splice
136      (Container : in out List;
137       Before    : Cursor;
138       Position  : in out Cursor);
139
140    function First (Container : List) return Cursor;
141
142    function First_Element (Container : List) return Element_Type;
143
144    function Last (Container : List) return Cursor;
145
146    function Last_Element (Container : List) return Element_Type;
147
148    function Next (Position : Cursor) return Cursor;
149
150    procedure Next (Position : in out Cursor);
151
152    function Previous (Position : Cursor) return Cursor;
153
154    procedure Previous (Position : in out Cursor);
155
156    function Find
157      (Container : List;
158       Item      : Element_Type;
159       Position  : Cursor := No_Element) return Cursor;
160
161    function Reverse_Find
162      (Container : List;
163       Item      : Element_Type;
164       Position  : Cursor := No_Element) return Cursor;
165
166    function Contains
167      (Container : List;
168       Item      : Element_Type) return Boolean;
169
170    function Has_Element (Position : Cursor) return Boolean;
171
172    procedure Iterate
173      (Container : List;
174       Process   : not null access procedure (Position : Cursor));
175
176    procedure Reverse_Iterate
177      (Container : List;
178       Process   : not null access procedure (Position : Cursor));
179
180    generic
181       with function "<" (Left, Right : Element_Type) return Boolean is <>;
182    package Generic_Sorting is
183
184       function Is_Sorted (Container : List) return Boolean;
185
186       procedure Sort (Container : in out List);
187
188    end Generic_Sorting;
189
190 private
191
192    type Node_Type is limited record
193       Prev    : Count_Type'Base;
194       Next    : Count_Type;
195       Element : Element_Type;
196    end record;
197
198    type Node_Array is array (Count_Type range <>) of Node_Type;
199
200    type List (Capacity : Count_Type) is tagged limited record
201       Nodes  : Node_Array (1 .. Capacity) := (others => <>);
202       Free   : Count_Type'Base := -1;
203       First  : Count_Type := 0;
204       Last   : Count_Type := 0;
205       Length : Count_Type := 0;
206    end record;
207
208    Empty_List : constant List := (0, others => <>);
209
210    type List_Access is access all List;
211    for List_Access'Storage_Size use 0;
212
213    type Cursor is
214       record
215          Container : List_Access;
216          Node      : Count_Type := 0;
217       end record;
218
219    No_Element : constant Cursor := (null, 0);
220
221 end Ada.Containers.Restricted_Doubly_Linked_Lists;