This appendix, adapted from the Ada 95 Reference
Manual, Section A.10.1, gives
the specification for Ada.Text_IO
. Note that the numeric
sub-packages Integer_IO
and Float_IO
are given here
as generic. The standard also provides for the preinstantiated packages
Ada.Integer_Text_IO
and Ada.Float_Text_IO
as we have
used in this book. These last two packages are part of the standard libraries
and do not need to be created or compiled by the user.
Explanations of the most common input/output exceptions are given in Appendix H, along with the other exceptions likely to be encountered by a student.
WITH Ada.IO_Exceptions; PACKAGE Ada.Text_IO 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 := ; -- 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; --Buffer control PROCEDURE Flush ( File : IN OUT File_Type); PROCEDURE Flush; -- Specification of line and page lengths PROCEDURE Set_Line_Length( File : IN File_Type; To : IN Count); PROCEDURE Set_Line_Length( To : IN Count); PROCEDURE Set_Page_Length( File : IN File_Type; To : IN Count); PROCEDURE Set_Page_Length( To : IN Count); FUNCTION Line_Length( File : IN File_Type) RETURN Count; FUNCTION Line_Length RETURN Count; FUNCTION Page_Length( File : IN File_Type) RETURN Count; FUNCTION Page_Length RETURN Count; -- Column, Line, and Page Control PROCEDURE New_Line ( File : IN File_Type; Spacing : IN Positive_Count := ); PROCEDURE New_Line ( Spacing : IN Positive_Count := ); PROCEDURE Skip_Line ( File : IN File_Type; Spacing : IN Positive_Count := ); PROCEDURE Skip_Line ( Spacing : IN Positive_Count := ); FUNCTION End_Of_Line( File : IN File_Type) RETURN Boolean; FUNCTION End_Of_Line RETURN Boolean; PROCEDURE New_Page ( File : IN File_Type); PROCEDURE New_Page; PROCEDURE Skip_Page ( File : IN File_Type); PROCEDURE Skip_Page; FUNCTION End_Of_Page( File : IN File_Type) RETURN Boolean; FUNCTION End_Of_Page RETURN Boolean; FUNCTION End_Of_File( File : IN File_Type) RETURN Boolean; FUNCTION End_Of_File RETURN Boolean; PROCEDURE Set_Col ( File : IN File_Type; To : IN Positive_Count); PROCEDURE Set_Col ( To : IN Positive_Count); PROCEDURE Set_Line( File : IN File_Type; To : IN Positive_Count); PROCEDURE Set_Line( To : IN Positive_Count); FUNCTION Col ( File : IN File_Type) RETURN Positive_Count; FUNCTION Col RETURN Positive_Count; FUNCTION Line( File : IN File_Type) RETURN Positive_Count; FUNCTION Line RETURN Positive_Count; FUNCTION Page( File : IN File_Type) RETURN Positive_Count; FUNCTION Page RETURN Positive_Count; -- Character Input-Output PROCEDURE Get( File : IN File_Type; Item : OUT Character); PROCEDURE Get( Item : OUT Character); PROCEDURE Put( File : IN File_Type; Item : IN Character); PROCEDURE Put( Item : IN Character); PROCEDURE Look_Ahead ( File : IN File_Type; Item : OUTCharacter; End_Of_Line : OUT Boolean); PROCEDURE Look_Ahead ( Item : OUT Character; End_Of_Line : OUT Boolean); PROCEDURE Get_Immediate( File : IN File_Type; Item : OUT Character); PROCEDURE Get_Immediate( Item : OUT Character); PROCEDURE Get_Immediate( File : IN File_Type; Item : OUT Character; Available : OUT Boolean); PROCEDURE Get_Immediate( Item : OUT Character; Available : OUT Boolean); -- String Input-Output PROCEDURE Get( File : IN File_Type; Item : OUT String); PROCEDURE Get( Item : OUT String); PROCEDURE Put( File : IN File_Type; Item : IN String); PROCEDURE Put( Item : IN String); PROCEDURE Get_Line( File : IN File_Type; Item : OUT String; Last : OUT Natural); PROCEDURE Get_Line( Item : OUT String; Last : OUT Natural); PROCEDURE Put_Line( File : IN File_Type; Item : IN String); PROCEDURE Put_Line( Item : IN String); -- 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; PROCEDURE Get( File : IN File_Type; Item : OUT Num; Width : IN Field := 0); PROCEDURE Get( Item : OUT Num; Width : IN Field := 0); PROCEDURE Put( File : IN File_Type; Item : IN Num; Width : IN Field := Default_Width; Base : IN Number_Base := Default_Base); PROCEDURE Put( Item : IN Num; Width : IN Field := Default_Width; Base : IN Number_Base := Default_Base); PROCEDURE Get( From : IN String; Item : OUT Num; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Num; Base : IN Number_Base := Default_Base); END Integer_IO; GENERIC TYPE Num IS mod <>; PACKAGE Modular_IO IS Default_Width : Field := Num'Width; Default_Base : Number_Base := ; PROCEDURE Get( File : IN File_Type; Item : OUT Num; Width : IN Field := 0); PROCEDURE Get( Item : OUT Num; Width : IN Field := 0); PROCEDURE Put( File : IN File_Type; Item : IN Num; Width : IN Field := Default_Width; Base : IN Number_Base := Default_Base); PROCEDURE Put( Item : IN Num; Width : IN Field := Default_Width; Base : IN Number_Base := Default_Base); PROCEDURE Get( From : IN String; Item : OUT Num; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Num; Base : IN Number_Base := Default_Base); 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; PROCEDURE Get( File : IN File_Type; Item : OUT Num; Width : IN Field := 0); PROCEDURE Get( Item : OUT Num; Width : IN Field := 0); PROCEDURE Put( File : IN File_Type; Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Put( Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Get( From : IN String; Item : OUT Num; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Num; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); 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; PROCEDURE Get( File : IN File_Type; Item : OUT Num; Width : IN Field := 0); PROCEDURE Get( Item : OUT Num; Width : IN Field := 0); PROCEDURE Put( File : IN File_Type; Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Put( Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Get( From : IN String; Item : OUT Num; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Num; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); 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; PROCEDURE Get( File : IN File_Type; Item : OUT Num; Width : IN Field := 0); PROCEDURE Get( Item : OUT Num; Width : IN Field := 0); PROCEDURE Put( File : IN File_Type; Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Put( Item : IN Num; Fore : IN Field := Default_Fore; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); PROCEDURE Get( From : IN String; Item : OUT Num; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Num; Aft : IN Field := Default_Aft; Exp : IN Field := Default_Exp); 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; PROCEDURE Get( File : IN File_Type; Item : OUT Enum); PROCEDURE Get( Item : OUT Enum); PROCEDURE Put( File : IN File_Type; Item : IN Enum; Width : IN Field := Default_Width; Set : IN Type_Set := Default_Setting); PROCEDURE Put( Item : IN Enum; Width : IN Field := Default_Width; Set : IN Type_Set := Default_Setting); PROCEDURE Get( From : IN String; Item : OUT Enum; Last : OUT Positive); PROCEDURE Put( To : OUT String; Item : IN Enum; Set : IN Type_Set := Default_Setting); END Enumeration_IO; -- Exceptions 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; PRIVATE ... -- not specified by the language END Ada.Text_IO;
Copyright © 1996 by Addison-Wesley Publishing Company, Inc.