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