1
-------------------------------------------------------------------------------
3
-- <STRONG>Copyright (c) 2001-2003 by Thomas Wolf.</STRONG>
5
-- This piece of software is free software; you can redistribute it and/or
6
-- modify it under the terms of the GNU General Public License as published
7
-- by the Free Software Foundation; either version 2, or (at your option)
8
-- any later version. This unit is distributed in the hope that it will be
9
-- useful, but <EM>without any warranty</EM>; without even the implied
10
-- warranty of <EM>merchantability or fitness for a particular purpose.</EM>
11
-- See the GNU General Public License for more details. You should have
12
-- received a copy of the GNU General Public License with this distribution,
13
-- see file "<A HREF="GPL.txt">GPL.txt</A>". If not, write to the Free
14
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18
-- As a special exception from the GPL, if other files instantiate generics
19
-- from this unit, or you link this unit with other files to produce an
20
-- executable, this unit does not by itself cause the resulting executable
21
-- to be covered by the GPL. This exception does not however invalidate any
22
-- other reasons why the executable file might be covered by the GPL.
26
-- Author:</STRONG><DD>
28
-- <ADDRESS><A HREF="mailto:twolf@acm.org">twolf@acm.org</A></ADDRESS></DL>
31
-- Purpose:</STRONG><DD>
32
-- Simple dynamic container, implemented as a very simple singly linked list.
33
-- Only operations are adding items, sorting, and finally traversing. It's
34
-- truly simple, but captures a very common case.
38
-- Tasking semantics:</STRONG><DD>
39
-- N/A. Not abortion-safe.</DL>
42
-- Storage semantics:</STRONG><DD>
43
-- Dynamic storage allocation in a user-supplied storage pool.</DL>
48
-- 16-JUN-2003 TW Initial version.
50
-------------------------------------------------------------------------------
52
pragma License (Modified_GPL);
54
with Ada.Finalization;
57
with GAL.Storage.Memory;
62
with package Memory is new GAL.Storage.Memory (<>);
64
package GAL.Containers.Simple is
66
pragma Elaborate_Body;
68
type Simple_Container is private;
70
Null_Container : constant Simple_Container;
73
(Left, Right : in out Simple_Container);
76
(Container : in Simple_Container)
80
(Container : in Simple_Container)
85
To : in out Simple_Container);
88
(Container : in out Simple_Container);
90
type Visitor is abstract tagged private;
95
Quit : in out Boolean)
97
-- 'Quit' is False upon entry; traversal continues until either all items
98
-- in the hash table have been processed or 'Quit' is set to True.
101
(Container : in Simple_Container;
102
V : in out Visitor'Class);
103
-- Calls 'Execute (V)' for all items currently in the container, until
104
-- either all items have been processed or 'Execute' sets 'Quit' to True.
107
with procedure Execute
108
(Value : in out Item;
109
Quit : in out Boolean);
111
(Container : in Simple_Container);
114
type Auxiliary (<>) is limited private;
115
with procedure Execute
116
(Value : in out Item;
117
Data : in out Auxiliary;
118
Quit : in out Boolean);
119
procedure Traverse_Aux_G
120
(Container : in Simple_Container;
121
Data : in out Auxiliary);
124
(Left, Right : in Simple_Container)
127
-- Equality on @Simple_Container@s is not supported. Because a
128
-- @Simple_Container@ has explicit or implicit ordering of items, a
129
-- meaningful equality meaning "the two containers contain the same
130
-- items" would be rather expensive (O(n**2)) to implement. And an
131
-- equality meaning "the two containers are the same" would be quite
132
-- different from equality on other containers.
135
with function "<" (Left, Right : in Item) return Boolean is <>;
137
(Container : in out Simple_Container);
142
type Link is access all Node;
143
for Link'Storage_Pool use Memory.Pool;
150
type True_Container is
151
new Ada.Finalization.Controlled with
154
Count : Natural := 0;
157
procedure Adjust (Container : in out True_Container);
158
procedure Finalize (Container : in out True_Container);
162
To : in out True_Container);
165
(Container : in out True_Container);
167
type Simple_Container is
171
-- @Simple_Container@ itself must not be a tagged type, or we cannot
172
-- declare @"="@ as abstract! Note that a @Simple_Container@ is still
173
-- a pass-by-reference type (see RM 6.2(8)).
176
(Stream : access Ada.Streams.Root_Stream_Type'Class;
177
Container : in Simple_Container);
180
(Stream : access Ada.Streams.Root_Stream_Type'Class;
181
Container : out Simple_Container);
183
for Simple_Container'Write use Write;
184
for Simple_Container'Read use Read;
186
Null_Container : constant Simple_Container :=
187
(C => (Ada.Finalization.Controlled with
192
type Visitor is abstract tagged null record;
194
end GAL.Containers.Simple;