A.8.5 Direct Input-Output Operations
Static Semantics
The operations available for direct input and output
are described in this subclause. The exception Status_Error is propagated
if any of these operations is attempted for a file that is not open.
procedure Read(File : in File_Type; Item : out Element_Type;
From : in Positive_Count);
procedure Read(File : in File_Type; Item : out Element_Type);
Operates on a file of mode In_File or Inout_File.
In the case of the first form, sets the current index of the given file
to the index value given by the parameter From. Then (for both forms)
returns, in the parameter Item, the value of the element whose position
in the given file is specified by the current index of the file; finally,
increases the current index by one.
The exception Mode_Error
is propagated if the mode of the given file is Out_File. The exception
End_Error is propagated if the index to be used exceeds the size of the
external file. The exception Data_Error can be propagated if the element
read cannot be interpreted as a value of the subtype Element_Type (see
A.13).
procedure Write(File : in File_Type; Item : in Element_Type;
To : in Positive_Count);
procedure Write(File : in File_Type; Item : in Element_Type);
Operates on a file of mode Inout_File or Out_File.
In the case of the first form, sets the index of the given file to the
index value given by the parameter To. Then (for both forms) gives the
value of the parameter Item to the element whose position in the given
file is specified by the current index of the file; finally, increases
the current index by one.
The exception Mode_Error
is propagated if the mode of the given file is In_File. The exception
Use_Error is propagated if the capacity of the external file is exceeded.
procedure Set_Index(File : in File_Type; To : in Positive_Count);
Operates on a file
of any mode. Sets the current index of the given file to the given index
value (which may exceed the current size of the file).
function Index(File : in File_Type) return Positive_Count;
Operates on a file
of any mode. Returns the current index of the given file.
function Size(File : in File_Type) return Count;
Operates on a file
of any mode. Returns the current size of the external file that is associated
with the given file.
function End_Of_File(File : in File_Type) return Boolean;
Operates on a file of mode In_File or Inout_File.
Returns True if the current index exceeds the size of the external file;
otherwise, returns False.
The exception Mode_Error is propagated if the
mode of the given file is Out_File.
NOTE Append_File mode is not supported
for the generic package Direct_IO.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe