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-2020, 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; 34private with Ada.Strings.Text_Output; 35 36generic 37 type Element_Type (<>) is private; 38 with function "=" (Left, Right : Element_Type) return Boolean is <>; 39 40package Ada.Containers.Indefinite_Holders is 41 pragma Annotate (CodePeer, Skip_Analysis); 42 pragma Preelaborate (Indefinite_Holders); 43 pragma Remote_Types (Indefinite_Holders); 44 45 type Holder is tagged private; 46 pragma Preelaborable_Initialization (Holder); 47 48 Empty_Holder : constant Holder; 49 50 function "=" (Left, Right : Holder) return Boolean; 51 52 function To_Holder (New_Item : Element_Type) return Holder; 53 54 function Is_Empty (Container : Holder) return Boolean; 55 56 procedure Clear (Container : in out Holder); 57 58 function Element (Container : Holder) return Element_Type; 59 60 procedure Replace_Element 61 (Container : in out Holder; 62 New_Item : Element_Type); 63 64 procedure Query_Element 65 (Container : Holder; 66 Process : not null access procedure (Element : Element_Type)); 67 68 procedure Update_Element 69 (Container : in out Holder; 70 Process : not null access procedure (Element : in out Element_Type)); 71 72 type Constant_Reference_Type 73 (Element : not null access constant Element_Type) is private 74 with 75 Implicit_Dereference => Element; 76 77 type Reference_Type 78 (Element : not null access Element_Type) is private 79 with 80 Implicit_Dereference => Element; 81 82 function Constant_Reference 83 (Container : aliased Holder) return Constant_Reference_Type; 84 pragma Inline (Constant_Reference); 85 86 function Reference 87 (Container : aliased in out Holder) return Reference_Type; 88 pragma Inline (Reference); 89 90 procedure Assign (Target : in out Holder; Source : Holder); 91 92 function Copy (Source : Holder) return Holder; 93 94 procedure Move (Target : in out Holder; Source : in out Holder); 95 96 procedure Swap (Left, Right : in out Holder); 97 98private 99 100 use Ada.Finalization; 101 use Ada.Streams; 102 103 type Element_Access is access all Element_Type; 104 105 type Holder_Access is access all Holder; 106 for Holder_Access'Storage_Size use 0; 107 108 procedure Read 109 (Stream : not null access Ada.Streams.Root_Stream_Type'Class; 110 Container : out Holder); 111 112 procedure Write 113 (Stream : not null access Ada.Streams.Root_Stream_Type'Class; 114 Container : Holder); 115 116 type Holder is new Ada.Finalization.Controlled with record 117 Element : Element_Access; 118 Busy : Natural := 0; 119 end record with Put_Image => Put_Image; 120 121 procedure Put_Image 122 (S : in out Ada.Strings.Text_Output.Sink'Class; V : Holder); 123 124 for Holder'Read use Read; 125 for Holder'Write use Write; 126 127 overriding procedure Adjust (Container : in out Holder); 128 overriding procedure Finalize (Container : in out Holder); 129 130 type Reference_Control_Type is new Controlled with 131 record 132 Container : Holder_Access; 133 end record; 134 135 overriding procedure Adjust (Control : in out Reference_Control_Type); 136 pragma Inline (Adjust); 137 138 overriding procedure Finalize (Control : in out Reference_Control_Type); 139 pragma Inline (Finalize); 140 141 type Constant_Reference_Type 142 (Element : not null access constant Element_Type) is 143 record 144 Control : Reference_Control_Type := 145 raise Program_Error with "uninitialized reference"; 146 -- The RM says, "The default initialization of an object of 147 -- type Constant_Reference_Type or Reference_Type propagates 148 -- Program_Error." 149 end record; 150 151 procedure Write 152 (Stream : not null access Root_Stream_Type'Class; 153 Item : Constant_Reference_Type); 154 155 for Constant_Reference_Type'Write use Write; 156 157 procedure Read 158 (Stream : not null access Root_Stream_Type'Class; 159 Item : out Constant_Reference_Type); 160 161 for Constant_Reference_Type'Read use Read; 162 163 type Reference_Type (Element : not null access Element_Type) is record 164 Control : Reference_Control_Type := 165 raise Program_Error with "uninitialized reference"; 166 -- The RM says, "The default initialization of an object of 167 -- type Constant_Reference_Type or Reference_Type propagates 168 -- Program_Error." 169 end record; 170 171 procedure Write 172 (Stream : not null access Root_Stream_Type'Class; 173 Item : Reference_Type); 174 175 for Reference_Type'Write use Write; 176 177 procedure Read 178 (Stream : not null access Root_Stream_Type'Class; 179 Item : out Reference_Type); 180 181 for Reference_Type'Read use Read; 182 183 Empty_Holder : constant Holder := (Controlled with null, 0); 184 185end Ada.Containers.Indefinite_Holders; 186