A.10.1 The Package Text_IO
Static Semantics
The library package
Text_IO has the following declaration:
{
AI12-0302-1}
with Ada.IO_Exceptions;
package Ada.Text_IO
with Global =>
in out synchronized is
type File_Type
is limited private;
type File_Mode
is (In_File, Out_File, Append_File);
type Count
is range 0 ..
implementation-defined;
subtype Positive_Count
is Count
range 1 .. Count'Last;
Unbounded :
constant Count := 0; --
line and page length
subtype Field
is Integer
range 0 ..
implementation-defined;
subtype Number_Base
is Integer
range 2 .. 16;
type Type_Set
is (Lower_Case, Upper_Case);
-- File Management
procedure Create (File :
in out File_Type;
Mode :
in File_Mode := Out_File;
Name :
in String := "";
Form :
in String := "");
procedure Open (File :
in out File_Type;
Mode :
in File_Mode;
Name :
in String;
Form :
in String := "");
procedure Close (File :
in out File_Type);
procedure Delete (File :
in out File_Type);
procedure Reset (File :
in out File_Type; Mode :
in File_Mode);
procedure Reset (File :
in out File_Type);
function Mode (File :
in File_Type)
return File_Mode;
function Name (File :
in File_Type)
return String;
function Form (File :
in File_Type)
return String;
function Is_Open(File :
in File_Type)
return Boolean;
-- Control of default input and output files
procedure Set_Input (File :
in File_Type);
procedure Set_Output(File :
in File_Type);
procedure Set_Error (File :
in File_Type);
function Standard_Input
return File_Type;
function Standard_Output
return File_Type;
function Standard_Error
return File_Type;
function Current_Input
return File_Type;
function Current_Output
return File_Type;
function Current_Error
return File_Type;
type File_Access
is access constant File_Type;
function Standard_Input
return File_Access;
function Standard_Output
return File_Access;
function Standard_Error
return File_Access;
function Current_Input
return File_Access;
function Current_Output
return File_Access;
function Current_Error
return File_Access;
{
8652/0051}
{
AI95-00057-01}
{
AI12-0302-1}
--
Buffer control
procedure Flush (File :
in File_Type)
with Global =>
overriding in out File;
procedure Flush
with Global =>
in out all;
-- Specification of line and page lengths
{
AI12-0302-1}
procedure Set_Line_Length(File :
in File_Type; To :
in Count)
with Global =>
overriding in out File;
procedure Set_Line_Length(To :
in Count)
with Global =>
in out all;
{
AI12-0302-1}
procedure Set_Page_Length(File :
in File_Type; To :
in Count)
with Global =>
overriding in out File;
procedure Set_Page_Length(To :
in Count)
with Global =>
in out all;
{
AI12-0302-1}
function Line_Length(File :
in File_Type)
return Count;
function Line_Length
return Count
with Global =>
in all;
{
AI12-0302-1}
function Page_Length(File :
in File_Type)
return Count;
function Page_Length
return Count
with Global =>
in all;
-- Column, Line, and Page Control
{
AI12-0302-1}
procedure New_Line (File :
in File_Type;
Spacing :
in Positive_Count := 1)
with Global =>
overriding in out File;
procedure New_Line (Spacing :
in Positive_Count := 1)
with Global =>
in out all;
{
AI12-0302-1}
procedure Skip_Line (File :
in File_Type;
Spacing :
in Positive_Count := 1)
with Global =>
overriding in out File;
procedure Skip_Line (Spacing :
in Positive_Count := 1)
with Global =>
in out all;
{
AI12-0302-1}
function End_Of_Line(File :
in File_Type)
return Boolean;
function End_Of_Line
return Boolean;
{
AI12-0302-1}
procedure New_Page (File :
in File_Type)
with Global =>
overriding in out File;
procedure New_Page
with Global =>
in out all;
{
AI12-0302-1}
procedure Skip_Page (File :
in File_Type)
with Global =>
overriding in out File;
procedure Skip_Page
with Global =>
in out all;
{
AI12-0302-1}
function End_Of_Page(File :
in File_Type)
return Boolean;
function End_Of_Page
return Boolean
with Global =>
in all;
{
AI12-0302-1}
function End_Of_File(File :
in File_Type)
return Boolean;
function End_Of_File
return Boolean
with Global =>
in all;
{
AI12-0302-1}
procedure Set_Col (File :
in File_Type; To :
in Positive_Count)
with Global =>
overriding in out File;
procedure Set_Col (To :
in Positive_Count)
with Global =>
in out all;
{
AI12-0302-1}
procedure Set_Line(File :
in File_Type; To :
in Positive_Count)
with Global =>
overriding in out File;
procedure Set_Line(To :
in Positive_Count)
with Global =>
in out all;
{
AI12-0302-1}
function Col (File :
in File_Type)
return Positive_Count;
function Col
return Positive_Count
with Global =>
in all;
{
AI12-0302-1}
function Line(File :
in File_Type)
return Positive_Count;
function Line
return Positive_Count
with Global =>
in all;
{
AI12-0302-1}
function Page(File :
in File_Type)
return Positive_Count;
function Page
return Positive_Count
with Global =>
in all;
-- Character Input-Output
{
AI12-0302-1}
procedure Get(File :
in File_Type; Item :
out Character)
with Global =>
overriding in out File;
procedure Get(Item :
out Character)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type; Item :
in Character)
with Global =>
overriding in out File;
procedure Put(Item :
in Character)
with Global =>
in out all;
{
AI12-0302-1}
procedure Look_Ahead (File :
in File_Type;
Item :
out Character;
End_Of_Line :
out Boolean)
with Global =>
overriding in out File;
procedure Look_Ahead (Item :
out Character;
End_Of_Line :
out Boolean)
with Global =>
in out all;
{
AI12-0302-1}
procedure Get_Immediate(File :
in File_Type;
Item :
out Character)
with Global =>
overriding in out File;
procedure Get_Immediate(Item :
out Character)
with Global =>
in out all;
{
AI12-0302-1}
procedure Get_Immediate(File :
in File_Type;
Item :
out Character;
Available :
out Boolean)
with Global =>
overriding in out File;
procedure Get_Immediate(Item :
out Character;
Available :
out Boolean)
with Global =>
in out all;
-- String Input-Output
{
AI12-0302-1}
procedure Get(File :
in File_Type; Item :
out String)
with Global =>
overriding in out File;
procedure Get(Item :
out String)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type; Item :
in String)
with Global =>
overriding in out File;
procedure Put(Item :
in String)
with Global =>
in out all;
{
AI12-0302-1}
procedure Get_Line(File :
in File_Type;
Item :
out String;
Last :
out Natural)
with Global =>
overriding in out File;
procedure Get_Line(Item :
out String; Last :
out Natural)
with Global =>
in out all;
{
AI95-00301-01}
{
AI12-0302-1}
function Get_Line(File :
in File_Type)
return String
with Global =>
overriding in out File;
function Get_Line
return String
with Global =>
in out all;
{
AI12-0302-1}
procedure Put_Line(File :
in File_Type; Item :
in String)
with Global =>
overriding in out File;
procedure Put_Line(Item :
in String)
with Global =>
in out all;
-- Generic packages for Input-Output of Integer Types
generic
type Num
is range <>;
package Integer_IO
is
Default_Width : Field := Num'Width;
Default_Base : Number_Base := 10;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Num;
Width :
in Field := 0)
with Global =>
overriding in out File;
procedure Get(Item :
out Num;
Width :
in Field := 0)
with Global =>
in out all;
{
AI12-0241-1}
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Num;
Width :
in Field := Default_Width;
Base :
in Number_Base := Default_Base)
with Global =>
overriding in out File;
procedure Put(Item :
in Num;
Width :
in Field := Default_Width;
Base :
in Number_Base := Default_Base)
with Global =>
in out all;
procedure Get(From :
in String;
Item :
out Num;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Num;
Base :
in Number_Base := Default_Base)
with Nonblocking;
end Integer_IO;
generic
type Num
is mod <>;
package Modular_IO
is
Default_Width : Field := Num'Width;
Default_Base : Number_Base := 10;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Num;
Width :
in Field := 0)
with Global =>
overriding in out File;
procedure Get(Item :
out Num;
Width :
in Field := 0)
with Global =>
in out all;
{
AI12-0241-1}
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Num;
Width :
in Field := Default_Width;
Base :
in Number_Base := Default_Base)
with Global =>
overriding in out File;
procedure Put(Item :
in Num;
Width :
in Field := Default_Width;
Base :
in Number_Base := Default_Base)
with Global =>
in out all;
procedure Get(From :
in String;
Item :
out Num;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Num;
Base :
in Number_Base := Default_Base)
with Nonblocking;
end Modular_IO;
-- Generic packages for Input-Output of Real Types
generic
type Num
is digits <>;
package Float_IO
is
Default_Fore : Field := 2;
Default_Aft : Field := Num'Digits-1;
Default_Exp : Field := 3;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Num;
Width :
in Field := 0)
with Global =>
overriding in out File;
procedure Get(Item :
out Num;
Width :
in Field := 0)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
overriding in out File;
procedure Put(Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
in out all;
{
AI12-0241-1}
procedure Get(From :
in String;
Item :
out Num;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Num;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Nonblocking;
end Float_IO;
generic
type Num
is delta <>;
package Fixed_IO
is
Default_Fore : Field := Num'Fore;
Default_Aft : Field := Num'Aft;
Default_Exp : Field := 0;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Num;
Width :
in Field := 0)
with Global =>
overriding in out File;
procedure Get(Item :
out Num;
Width :
in Field := 0)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
overriding in out File;
procedure Put(Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
in out all;
{
AI12-0241-1}
procedure Get(From :
in String;
Item :
out Num;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Num;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Nonblocking;
end Fixed_IO;
generic
type Num
is delta <>
digits <>;
package Decimal_IO
is
Default_Fore : Field := Num'Fore;
Default_Aft : Field := Num'Aft;
Default_Exp : Field := 0;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Num;
Width :
in Field := 0)
with Global =>
overriding in out File;
procedure Get(Item :
out Num;
Width :
in Field := 0)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
overriding in out File;
procedure Put(Item :
in Num;
Fore :
in Field := Default_Fore;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Global =>
in out all;
{
AI12-0241-1}
procedure Get(From :
in String;
Item :
out Num;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Num;
Aft :
in Field := Default_Aft;
Exp :
in Field := Default_Exp)
with Nonblocking;
end Decimal_IO;
-- Generic package for Input-Output of Enumeration Types
generic
type Enum
is (<>);
package Enumeration_IO
is
Default_Width : Field := 0;
Default_Setting : Type_Set := Upper_Case;
{
AI12-0302-1}
procedure Get(File :
in File_Type;
Item :
out Enum)
with Global =>
overriding in out File;
procedure Get(Item :
out Enum)
with Global =>
in out all;
{
AI12-0302-1}
procedure Put(File :
in File_Type;
Item :
in Enum;
Width :
in Field := Default_Width;
Set :
in Type_Set := Default_Setting)
with Global =>
overriding in out File;
procedure Put(Item :
in Enum;
Width :
in Field := Default_Width;
Set :
in Type_Set := Default_Setting)
with Global =>
in out all;
{
AI12-0241-1}
procedure Get(From :
in String;
Item :
out Enum;
Last :
out Positive)
with Nonblocking;
procedure Put(To :
out String;
Item :
in Enum;
Set :
in Type_Set := Default_Setting)
with Nonblocking;
end Enumeration_IO;
-- Exceptions
{
AI12-0021-1}
Status_Error :
exception renames IO_Exceptions.Status_Error;
Mode_Error :
exception renames IO_Exceptions.Mode_Error;
Name_Error :
exception renames IO_Exceptions.Name_Error;
Use_Error :
exception renames IO_Exceptions.Use_Error;
Device_Error :
exception renames IO_Exceptions.Device_Error;
End_Error :
exception renames IO_Exceptions.End_Error;
Data_Error :
exception renames IO_Exceptions.Data_Error;
Layout_Error :
exception renames IO_Exceptions.Layout_Error;
-- File management
procedure Create (File :
in out File_Type;
Mode :
in File_Mode := Out_File;
Name :
in Wide_String := "";
Form :
in Wide_String := "");
procedure Open (File :
in out File_Type;
Mode :
in File_Mode;
Name :
in Wide_String;
Form :
in Wide_String := "");
function Name (File :
in File_Type)
return Wide_String;
function Form (File :
in File_Type)
return Wide_String;
end Wide_File_Names;
-- File management
procedure Create (File :
in out File_Type;
Mode :
in File_Mode := Out_File;
Name :
in Wide_Wide_String := "";
Form :
in Wide_Wide_String := "");
procedure Open (File :
in out File_Type;
Mode :
in File_Mode;
Name :
in Wide_Wide_String;
Form :
in Wide_Wide_String := "");
function Name (File :
in File_Type)
return Wide_Wide_String;
function Form (File :
in File_Type)
return Wide_Wide_String;
end Wide_Wide_File_Names;
private
... -- not specified by the language
end Ada.Text_IO;
Incompatibilities With Ada 83
Append_File is a new element
of enumeration type File_Mode.
Extensions to Ada 83
Get_Immediate, Look_Ahead,
the subprograms for dealing with standard error, the type File_Access
and its associated subprograms, and the generic packages Modular_IO and
Decimal_IO are new in Ada 95.
Incompatibilities With Ada 95
{
AI95-00360-01}
Amendment Correction: Text_IO.File_Type is
defined to need finalization. If the restriction No_Nested_Finalization
(see
D.7) applies to the partition, and File_Type
does not have a controlled part, it will not be allowed in local objects
in Ada 2005 whereas it would be allowed in original Ada 95. Such code
is not portable, as another Ada compiler may have a controlled part in
File_Type, and thus would be illegal.
Wording Changes from Ada 95
{
8652/0051}
{
AI95-00057-01}
Corrigendum: Corrected the parameter mode of Flush; otherwise
it could not be used on Standard_Output.
Incompatibilities With Ada 2012
{
AI12-0021-1}
The Wide_File_Names and Wide_Wide_File_Names nested
packages are newly added to Ada.Text_IO. Therefore, a use clause conflict
is possible; see the introduction of
Annex A
for more on this topic.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe