agpl_1.0.0_b5da3320/src/agpl-indefinite_protected_value.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 

--  Protected container for values of any private type.

with Ada.Finalization;

generic
   type Element_type (<>) is private;
package Agpl.Indefinite_Protected_Value is

   pragma Preelaborate;

   type Functor is abstract tagged null record;
   procedure Operate (This : in out Functor; Value : in out Element_Type)
   is abstract;

   type Object is limited private;

   type Object_Access is access Object;

   function Empty (This : in Object) return Boolean;
   --  Says if no value has been still stored.

   function Get (This : in Object) return Element_Type;

   procedure Set (This : in out Object; That : Element_Type);

   procedure Operate (This : in out Object; Using : in out Functor'Class);

private

   type Element_Access is access all Element_Type;

   protected type Internal_Object is
      function  Empty return Boolean;
      function  Get return Element_Type;
      procedure Set     (This  : in Element_Type);
      procedure Operate (Using : in out Functor'Class);
      --  Will call Functor.Operate (Value)
      procedure Free;
   private
      Value : Element_Access;
   end Internal_Object;

   type Object is new Ada.Finalization.Limited_Controlled with record
      Internal : Internal_Object;
   end record;

   procedure Finalize (This : in out Object);

end Agpl.Indefinite_Protected_Value;