OSDN Git Service

2007-09-26 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-crdlli.ads
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 ------------------------------------------------------------------------------
36
37 generic
38    type Element_Type is private;
39
40    with function "=" (Left, Right : Element_Type)
41       return Boolean is <>;
42
43 package Ada.Containers.Restricted_Doubly_Linked_Lists is
44    pragma Pure;
45
46    type List (Capacity : Count_Type) is tagged limited 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    procedure Assign (Target : in out List; Source : List);
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) return Element_Type;
67
68    procedure Replace_Element
69      (Container : in out List;
70       Position  : Cursor;
71       New_Item  : Element_Type);
72
73    procedure Query_Element
74      (Position : Cursor;
75       Process  : not null access procedure (Element : Element_Type));
76
77    procedure Update_Element
78      (Container : in out List;
79       Position  : Cursor;
80       Process   : not null access procedure (Element : in out Element_Type));
81
82    procedure Insert
83      (Container : in out List;
84       Before    : Cursor;
85       New_Item  : Element_Type;
86       Count     : Count_Type := 1);
87
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);
94
95    procedure Insert
96      (Container : in out List;
97       Before    : Cursor;
98       Position  : out Cursor;
99       Count     : Count_Type := 1);
100
101    procedure Prepend
102      (Container : in out List;
103       New_Item  : Element_Type;
104       Count     : Count_Type := 1);
105
106    procedure Append
107      (Container : in out List;
108       New_Item  : Element_Type;
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    procedure Reverse_Elements (Container : in out List);
125
126    procedure Swap
127      (Container : in out List;
128       I, J      : Cursor);
129
130    procedure Swap_Links
131      (Container : in out List;
132       I, J      : Cursor);
133
134    procedure Splice
135      (Container : in out List;
136       Before    : Cursor;
137       Position  : in out Cursor);
138
139    function First (Container : List) return Cursor;
140
141    function First_Element (Container : List) return Element_Type;
142
143    function Last (Container : List) return Cursor;
144
145    function Last_Element (Container : List) return Element_Type;
146
147    function Next (Position : Cursor) return Cursor;
148
149    procedure Next (Position : in out Cursor);
150
151    function Previous (Position : Cursor) return Cursor;
152
153    procedure Previous (Position : in out Cursor);
154
155    function Find
156      (Container : List;
157       Item      : Element_Type;
158       Position  : Cursor := No_Element) return Cursor;
159
160    function Reverse_Find
161      (Container : List;
162       Item      : Element_Type;
163       Position  : Cursor := No_Element) return Cursor;
164
165    function Contains
166      (Container : List;
167       Item      : Element_Type) return Boolean;
168
169    function Has_Element (Position : Cursor) return Boolean;
170
171    procedure Iterate
172      (Container : List;
173       Process   : not null access procedure (Position : Cursor));
174
175    procedure Reverse_Iterate
176      (Container : List;
177       Process   : not null access procedure (Position : Cursor));
178
179    generic
180       with function "<" (Left, Right : Element_Type) return Boolean is <>;
181    package Generic_Sorting is
182
183       function Is_Sorted (Container : List) return Boolean;
184
185       procedure Sort (Container : in out List);
186
187    end Generic_Sorting;
188
189 private
190
191    type Node_Type is limited record
192       Prev    : Count_Type'Base;
193       Next    : Count_Type;
194       Element : Element_Type;
195    end record;
196
197    type Node_Array is array (Count_Type range <>) of Node_Type;
198
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;
206
207    Empty_List : constant List := (0, others => <>);
208
209    type List_Access is access all List;
210    for List_Access'Storage_Size use 0;
211
212    type Cursor is
213       record
214          Container : List_Access;
215          Node      : Count_Type := 0;
216       end record;
217
218    No_Element : constant Cursor := (null, 0);
219
220 end Ada.Containers.Restricted_Doubly_Linked_Lists;