Make your own free website on Tripod.com

File : reference_finalization.adb


with Ada.Unchecked_Deallocation;
--with Text_IO; Use text_IO;
package body Reference_Finalization is

   procedure Free is new Ada.Unchecked_Deallocation(Ref_Count,Access_Count);

   ------------
   -- Adjust --
   ------------

   procedure Adjust (Object : in out Controlled_Reference) is
   begin
      Object.Refer.All := Object.Refer.All+1;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   procedure Finalize (Object : in out Controlled_Reference) is
     internal_error : exception;
   begin
      if Object.Refer.All=0 then
         Destroy(Controlled_Reference'Class(Object));
         Free(Object.Refer);
      elsif Object.Refer.All>0 then
         Object.Refer.All := Object.Refer.All-1;
      else raise Internal_Error;   
      end if;
   end Finalize;

end Reference_Finalization;