I want to put a wrapper or façade on Ada.sequential_IO. This is a bit ugly but I'm trying to work with some auto-translated code. So I've got:
with Ada.sequential_IO;
generic
type element_type is private;
package queue_file is
package implementation is new Ada.sequential_IO (element_type);
subtype instance is implementation.file_type;
function eofQ (channel : instance) return Boolean renames implementation.end_of_file;
procedure readQ (channel : in instance; item : out element_type) renames implementation.read;
-- etc.
end queue_file;
which is all very well but the name queue_file.implementation is visible. I tried to move it into the private part and write package implementation is private but it's not having it. So is there any way to hide the name ?
You cannot do what you're trying to do, at least not w/o breaking the visible dependence on implementation
given by subtype instance is implementation.file_type;
Example:
private with Ada.Sequential_IO;
generic
type element_type is private;
package queue_file is
type instance is limited private;
function eofQ (channel : instance) return Boolean;
procedure readQ (channel : in instance; item : out element_type);
-- SUBPROGRAMS FOR SEQUENTIAL_IO INTERFACE --
procedure Open
(File : in out instance;
Name : String;
Write: Boolean;
Form : String := "");
procedure Read (File : instance; Item : out Element_Type);
procedure Write (File : instance; Item : Element_Type);
-- etc.
private
package implementation is new Ada.sequential_IO (element_type);
type instance is new implementation.file_type;
end queue_file;
and
Pragma Ada_2012;
package body queue_file is
function eofQ (channel : instance) return Boolean is
( implementation.end_of_file( implementation.File_Type(channel) ) );
procedure readQ (channel : in instance; item : out element_type) is
use implementation;
begin
implementation.read( File_Type(Channel), item );
end readQ;
procedure Open
(File : in out instance;
Name : String;
Write: Boolean;
Form : String := "") is
use implementation;
begin
Open(
File => File_Type(File),
Mode => (if Write then Out_File else In_File),
Name => Name,
Form => Form
);
end Open;
-- left as an exercise
procedure Read (File : instance; Item : out Element_Type) is null;
procedure Write (File : instance; Item : Element_Type) is null;
-- etc.
end queue_file;