1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT LIBRARY COMPONENTS                          --
4--                                                                          --
5--    A D A . C O N T A I N E R S . I N D E F I N I T E _ H O L D E R S     --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 2011-2014, 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 3,  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.                                     --
21--                                                                          --
22-- As a special exception under Section 7 of GPL version 3, you are granted --
23-- additional permissions described in the GCC Runtime Library Exception,   --
24-- version 3.1, as published by the Free Software Foundation.               --
25--                                                                          --
26-- You should have received a copy of the GNU General Public License and    --
27-- a copy of the GCC Runtime Library Exception along with this program;     --
28-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29-- <http://www.gnu.org/licenses/>.                                          --
30------------------------------------------------------------------------------
31
32private with Ada.Finalization;
33private with Ada.Streams;
34
35generic
36   type Element_Type (<>) is private;
37   with function "=" (Left, Right : Element_Type) return Boolean is <>;
38
39package Ada.Containers.Indefinite_Holders is
40   pragma Preelaborate (Indefinite_Holders);
41   pragma Remote_Types (Indefinite_Holders);
42
43   type Holder is tagged private;
44   pragma Preelaborable_Initialization (Holder);
45
46   Empty_Holder : constant Holder;
47
48   function "=" (Left, Right : Holder) return Boolean;
49
50   function To_Holder (New_Item : Element_Type) return Holder;
51
52   function Is_Empty (Container : Holder) return Boolean;
53
54   procedure Clear (Container : in out Holder);
55
56   function Element (Container : Holder) return Element_Type;
57
58   procedure Replace_Element
59     (Container : in out Holder;
60      New_Item  : Element_Type);
61
62   procedure Query_Element
63     (Container : Holder;
64      Process   : not null access procedure (Element : Element_Type));
65
66   procedure Update_Element
67     (Container : in out Holder;
68      Process   : not null access procedure (Element : in out Element_Type));
69
70   type Constant_Reference_Type
71      (Element : not null access constant Element_Type) is private
72   with
73      Implicit_Dereference => Element;
74
75   type Reference_Type
76     (Element : not null access Element_Type) is private
77   with
78      Implicit_Dereference => Element;
79
80   function Constant_Reference
81     (Container : aliased Holder) return Constant_Reference_Type;
82   pragma Inline (Constant_Reference);
83
84   function Reference
85     (Container : aliased in out Holder) return Reference_Type;
86   pragma Inline (Reference);
87
88   procedure Assign (Target : in out Holder; Source : Holder);
89
90   function Copy (Source : Holder) return Holder;
91
92   procedure Move (Target : in out Holder; Source : in out Holder);
93
94private
95
96   use Ada.Finalization;
97   use Ada.Streams;
98
99   type Element_Access is access all Element_Type;
100
101   type Holder_Access is access all Holder;
102   for Holder_Access'Storage_Size use 0;
103
104   procedure Read
105     (Stream    : not null access Ada.Streams.Root_Stream_Type'Class;
106      Container : out Holder);
107
108   procedure Write
109     (Stream    : not null access Ada.Streams.Root_Stream_Type'Class;
110      Container : Holder);
111
112   type Holder is new Ada.Finalization.Controlled with record
113      Element : Element_Access;
114      Busy    : Natural := 0;
115   end record;
116   for Holder'Read use Read;
117   for Holder'Write use Write;
118
119   overriding procedure Adjust (Container : in out Holder);
120   overriding procedure Finalize (Container : in out Holder);
121
122   type Reference_Control_Type is new Controlled with
123   record
124      Container : Holder_Access;
125   end record;
126
127   overriding procedure Adjust (Control : in out Reference_Control_Type);
128   pragma Inline (Adjust);
129
130   overriding procedure Finalize (Control : in out Reference_Control_Type);
131   pragma Inline (Finalize);
132
133   type Constant_Reference_Type
134      (Element : not null access constant Element_Type) is
135   record
136      Control : Reference_Control_Type;
137   end record;
138
139   procedure Write
140     (Stream : not null access Root_Stream_Type'Class;
141      Item   : Constant_Reference_Type);
142
143   for Constant_Reference_Type'Write use Write;
144
145   procedure Read
146     (Stream : not null access Root_Stream_Type'Class;
147      Item   : out Constant_Reference_Type);
148
149   for Constant_Reference_Type'Read use Read;
150
151   type Reference_Type (Element : not null access Element_Type) is record
152      Control : Reference_Control_Type;
153   end record;
154
155   procedure Write
156     (Stream : not null access Root_Stream_Type'Class;
157      Item   : Reference_Type);
158
159   for Reference_Type'Write use Write;
160
161   procedure Read
162     (Stream : not null access Root_Stream_Type'Class;
163      Item   : out Reference_Type);
164
165   for Reference_Type'Read use Read;
166
167   Empty_Holder : constant Holder := (Controlled with null, 0);
168
169end Ada.Containers.Indefinite_Holders;
170