with Ada.Finalization;

generic

  type Uncontrolled (<>) is abstract tagged private;

--with procedure Initialize (Object: in out Uncontrolled);
  with procedure Adjust     (Object: in out Uncontrolled);
  with procedure Finalize   (Object: in out Uncontrolled);

package Add_Finalization.To_Uncontrolled_Sequential is

  type Controlled is new Uncontrolled with private;

private

  type Controlled_Ptr is access all Controlled;

  type Component is new Ada.Finalization.Controlled with record
    Parent: Controlled_Ptr;
  end record;

  type Controlled is new Uncontrolled with record
    Controller: Component := (Ada.Finalization.Controlled with
                              Controlled'Some_Access_Attribute);
  end record;

  procedure Adjust   (Object: in out Component);
  procedure Finalize (Object: in out Component);

end Add_Finalization.To_Uncontrolled_Sequential;

package body Add_Finalization.To_Uncontrolled_Sequential is

  Store: Controlled_Ptr;

  procedure Adjust (Object: in out Component) is
  begin
    Object.Parent := Store;
    Adjust (Uncontrolled (Object.Parent.all));
  end Adjust;

  procedure Finalize (Object: in out Component) is
  begin
    Store := Object.Parent;
    Finalize (Uncontrolled (Object.Parent.all));
  end Finalize;

end Add_Finalization.To_Uncontrolled_Sequential;

Back to text.
Zurück zum Text.