1. private with Ada.Finalization; 
  2. generic 
  3.  
  4.    type Element_Type is limited private; 
  5.    type Element_Type_Access is access Element_Type; 
  6.  
  7.    with procedure Initialize (item : in out Element_Type) is <>; 
  8.    with procedure Copy (target : in out Element_Type; source : in Element_Type) is <>; 
  9.    with procedure Finalize (item : in out Element_Type) is <>; 
  10.  
  11. package DDS.Limited_Holders_Generic is 
  12.  
  13.    --  This is a suport package intended to wrap limited DDS-datatypes 
  14.    --  in such a way that they coud be used as non limited types. 
  15.    --  The interface is modeled after Ada.Containers.Holders. 
  16.    -- 
  17.    --  declare 
  18.    --    use DDS; 
  19.    --    package String_Holders is new DDS.Limited_Holders_Generic 
  20.    --      (Element_Type        => DDS.String, 
  21.    --       Element_Type_Access => DDS.String_Ptr); 
  22.    -- 
  23.    --    H1   : String_Holders.Holder; 
  24.    --    Data : aliased DDS.String := DDS.To_DDS_String("Test Data"); 
  25.    --    H0   : String_Holders.Holder := String_Holders."+"(Data); 
  26.    --  begin 
  27.    --    H1 := H0; -- H1 will now contain a copy of the DDS.string Data; 
  28.    --  end; 
  29.    --  -- The content of the Holders H0 and H1 will be freed when the 
  30.    --  -- declare block gous out of scope. 
  31.    -- 
  32.    --  Note the the holder contains a full copy of the object and an assignment 
  33.    --  implies a deep copy of the object, it could result in hevy CPU usage: 
  34.  
  35.    type Holder is tagged private; 
  36.  
  37.    function To_Holder (New_Item : Element_Type) return Holder; 
  38.    function "+" (New_Item : Element_Type) return Holder renames To_Holder; 
  39.    --  Create a new holder the contains a copy of the object. 
  40.  
  41.    function Get (Container : Holder) return Element_Type_Access; 
  42.    --  Returns a reference to the stored object. 
  43.  
  44.    procedure Set (Container : in out Holder; New_Item  : Element_Type); 
  45.    --  Makes a new copy of the object and stores it in the Holder. 
  46.  
  47.    procedure References (Container : in out Holder; New_Item  : Element_Type_Access); 
  48.    --  Sets the holder to reference the object without copy. 
  49.  
  50.  
  51.  
  52. private 
  53.    type Holder is new Ada.Finalization.Controlled with record 
  54.       impl         : Element_Type_Access; 
  55.       Is_Reference : Boolean := False; 
  56.    end record; 
  57.  
  58.    procedure Initialize (Object : in out Holder); 
  59.    procedure Adjust     (Object : in out Holder); 
  60.    procedure Finalize   (Object : in out Holder); 
  61.  
  62. end DDS.Limited_Holders_Generic;