with Persistence_Types; use Persistence_Types; private with Ada.Streams; package P is type T is limited private; function Persistence (O : not null access T) return not null access Persistence_Type'Class; private use Ada.Streams; type Persistence_View (O : not null access T) is new Persistence_Type with null record; overriding procedure Write (Persistence : in Persistence_View; Stream : not null access Root_Stream_Type'Class); overriding procedure Read (Persistence : in out Persistence_View; Stream : not null access Root_Stream_Type'Class); type T is limited record Persistence : aliased Persistence_View (T'Access); end record; end P; with Persistence_Types2; use Persistence_Types2; with Ada.Streams; use Ada.Streams; package P2 is type T is limited new Persistence_Type with null record; overriding procedure Write (Persistence : in T; Stream : not null access Root_Stream_Type'Class); overriding procedure Read (Persistence : in out T; Stream : not null access Root_Stream_Type'Class); end P2; with Persistence_Types; use Persistence_Types; package Persistence_IO is pragma Elaborate_Body; procedure Init; procedure Save (Persistence : in Persistence_Type'Class); end Persistence_IO; with Persistence_Types2; use Persistence_Types2; package Persistence_IO2 is pragma Elaborate_Body; procedure Init; procedure Save (Persistence : in Persistence_Type'Class); end Persistence_IO2; with Ada.Streams; use Ada.Streams; package Persistence_Types is pragma Pure; type Persistence_Type is abstract tagged limited null record; procedure Write (Persistence : in Persistence_Type; Stream : not null access Root_Stream_Type'Class) is abstract; procedure Read (Persistence : in out Persistence_Type; Stream : not null access Root_Stream_Type'Class) is abstract; end Persistence_Types; with Ada.Streams; use Ada.Streams; package Persistence_Types2 is pragma Pure; type Persistence_Type is limited interface; procedure Write (Persistence : in Persistence_Type; Stream : not null access Root_Stream_Type'Class) is abstract; procedure Read (Persistence : in out Persistence_Type; Stream : not null access Root_Stream_Type'Class) is abstract; end Persistence_Types2; package body P is function Persistence (O : not null access T) return not null access Persistence_Type'Class is begin return O.Persistence'Access; end; procedure Write (Persistence : in Persistence_View; Stream : not null access Root_Stream_Type'Class) is begin null; end; procedure Read (Persistence : in out Persistence_View; Stream : not null access Root_Stream_Type'Class) is begin null; end; end P; package body P2 is procedure Write (Persistence : not null access T; Stream : not null access Root_Stream_Type'Class) is begin null; end; procedure Read (Persistence : not null access T; Stream : not null access Root_Stream_Type'Class) is begin null; end; end P2; with Ada.Streams.Stream_IO; package body Persistence_IO is File : Ada.Streams.Stream_IO.File_Type; use Ada.Streams.Stream_IO; procedure Init is begin Create (File, Name => "test.dat"); end; procedure Save (Persistence : in Persistence_Type'Class) is begin Persistence.Write (Stream (File)); end Save; end Persistence_IO; with Ada.Streams.Stream_IO; package body Persistence_IO2 is File : Ada.Streams.Stream_IO.File_Type; use Ada.Streams.Stream_IO; procedure Init is begin Create (File, Name => "test.dat"); end; procedure Save (Persistence : in Persistence_Type'Class) is begin Persistence.Write (Stream (File)); end Save; end Persistence_IO2; with P; use P; with Persistence_Types; use Persistence_Types; with Persistence_IO; procedure Test_Persistence is O : aliased T; begin Persistence_IO.Init; Persistence_IO.Save (Persistence (O'Access).all); end; with P2; use P2; with Persistence_Types2; use Persistence_Types2; with Persistence_IO2; procedure Test_Persistence2 is O : T; begin Persistence_IO2.Init; Persistence_IO2.Save (O); end;