PR ada/18819
[official-gcc.git] / gcc / ada / a-crdlli.ads
blob0e768a4557eb11c11062f3ae092a98d4e3e98f06
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . --
6 -- R E S R I C T E D _ 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-2006, 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 ------------------------------------------------------------------------------
37 generic
38 type Element_Type is private;
40 with function "=" (Left, Right : Element_Type)
41 return Boolean is <>;
43 package Ada.Containers.Restricted_Doubly_Linked_Lists is
44 pragma Pure;
46 type List (Capacity : Count_Type) is tagged limited private;
47 pragma Preelaborable_Initialization (List);
49 type Cursor is private;
50 pragma Preelaborable_Initialization (Cursor);
52 Empty_List : constant List;
54 No_Element : constant Cursor;
56 function "=" (Left, Right : List) return Boolean;
58 procedure Assign (Target : in out List; Source : List);
60 function Length (Container : List) return Count_Type;
62 function Is_Empty (Container : List) return Boolean;
64 procedure Clear (Container : in out List);
66 function Element (Position : Cursor) return Element_Type;
68 procedure Replace_Element
69 (Container : in out List;
70 Position : Cursor;
71 New_Item : Element_Type);
73 procedure Query_Element
74 (Position : Cursor;
75 Process : not null access procedure (Element : Element_Type));
77 procedure Update_Element
78 (Container : in out List;
79 Position : Cursor;
80 Process : not null access procedure (Element : in out Element_Type));
82 procedure Insert
83 (Container : in out List;
84 Before : Cursor;
85 New_Item : Element_Type;
86 Count : Count_Type := 1);
88 procedure Insert
89 (Container : in out List;
90 Before : Cursor;
91 New_Item : Element_Type;
92 Position : out Cursor;
93 Count : Count_Type := 1);
95 procedure Insert
96 (Container : in out List;
97 Before : Cursor;
98 Position : out Cursor;
99 Count : Count_Type := 1);
101 procedure Prepend
102 (Container : in out List;
103 New_Item : Element_Type;
104 Count : Count_Type := 1);
106 procedure Append
107 (Container : in out List;
108 New_Item : Element_Type;
109 Count : Count_Type := 1);
111 procedure Delete
112 (Container : in out List;
113 Position : in out Cursor;
114 Count : Count_Type := 1);
116 procedure Delete_First
117 (Container : in out List;
118 Count : Count_Type := 1);
120 procedure Delete_Last
121 (Container : in out List;
122 Count : Count_Type := 1);
124 procedure Reverse_Elements (Container : in out List);
126 procedure Swap
127 (Container : in out List;
128 I, J : Cursor);
130 procedure Swap_Links
131 (Container : in out List;
132 I, J : Cursor);
134 procedure Splice
135 (Container : in out List;
136 Before : Cursor;
137 Position : in out Cursor);
139 function First (Container : List) return Cursor;
141 function First_Element (Container : List) return Element_Type;
143 function Last (Container : List) return Cursor;
145 function Last_Element (Container : List) return Element_Type;
147 function Next (Position : Cursor) return Cursor;
149 procedure Next (Position : in out Cursor);
151 function Previous (Position : Cursor) return Cursor;
153 procedure Previous (Position : in out Cursor);
155 function Find
156 (Container : List;
157 Item : Element_Type;
158 Position : Cursor := No_Element) return Cursor;
160 function Reverse_Find
161 (Container : List;
162 Item : Element_Type;
163 Position : Cursor := No_Element) return Cursor;
165 function Contains
166 (Container : List;
167 Item : Element_Type) return Boolean;
169 function Has_Element (Position : Cursor) return Boolean;
171 procedure Iterate
172 (Container : List;
173 Process : not null access procedure (Position : Cursor));
175 procedure Reverse_Iterate
176 (Container : List;
177 Process : not null access procedure (Position : Cursor));
179 generic
180 with function "<" (Left, Right : Element_Type) return Boolean is <>;
181 package Generic_Sorting is
183 function Is_Sorted (Container : List) return Boolean;
185 procedure Sort (Container : in out List);
187 end Generic_Sorting;
189 private
191 type Node_Type is limited record
192 Prev : Count_Type'Base;
193 Next : Count_Type;
194 Element : Element_Type;
195 end record;
197 type Node_Array is array (Count_Type range <>) of Node_Type;
199 type List (Capacity : Count_Type) is tagged limited record
200 Nodes : Node_Array (1 .. Capacity) := (others => <>);
201 Free : Count_Type'Base := -1;
202 First : Count_Type := 0;
203 Last : Count_Type := 0;
204 Length : Count_Type := 0;
205 end record;
207 Empty_List : constant List := (0, others => <>);
209 type List_Access is access all List;
210 for List_Access'Storage_Size use 0;
212 type Cursor is
213 record
214 Container : List_Access;
215 Node : Count_Type := 0;
216 end record;
218 No_Element : constant Cursor := (null, 0);
220 end Ada.Containers.Restricted_Doubly_Linked_Lists;