Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


A.10.8 Input-Output for Integer Types

Static Semantics
(1)
The following procedures are defined in the generic packages Integer_IO and Modular_IO, which have to be instantiated for the appropriate signed integer or modular type respectively (indicated by Num in the specifications).
(2)
Values are output as decimal or based literals, without low line characters or exponent, and, for Integer_IO, preceded by a minus sign if negative. The format (which includes any leading spaces and minus sign) can be specified by an optional field width parameter. Values of widths of fields in output formats are of the nonnegative integer subtype Field. Values of bases are of the integer subtype Number_Base.
(3)
       subtype Number_Base is Integer range 2 .. 16;
(4)
The default field width and base to be used by output procedures are defined by the following variables that are declared in the generic packages Integer_IO and Modular_IO:
(5)
       Default_Width : Field := Num'Width;
       Default_Base  : Number_Base := 10;
(6)
The following procedures are provided:
(7)
       procedure Get(File : in File_Type; Item : out Num; Width : in Field := 0);
       procedure Get(Item : out Num; Width : in Field := 0);
(8)
(9)
(10)
(11)
       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);
(12)
(13)
(14)
(15)
       procedure Get(From : in String; Item : out Num; Last : out Positive);
(16)
(17)
(18)
       procedure Put(To   : out String;
                     Item : in Num;
                     Base : in Number_Base := Default_Base);
(19)
(20)
Integer_Text_IO is a library package that is a nongeneric equivalent to Text_IO.Integer_IO for the predefined type Integer:
(21)
       with Ada.Text_IO;
       package Ada.Integer_Text_IO is new Ada.Text_IO.Integer_IO(Integer);
(22)
For each predefined signed integer type, a nongeneric equivalent to Text_IO.Integer_IO is provided, with names such as Ada.Long_Integer_Text_IO.
Implementation Permissions
(23)
The nongeneric equivalent packages may, but need not, be actual instantiations of the generic package for the appropriate predefined type.

(24)
Examples
(25)
       -- (blank)
(26)
       package Int_IO is new Integer_IO(Small_Int); use Int_IO;
       -- default format used at instantiation,
       -- Default_Width = 4, Default_Base = 10
(27)
       Put(126);                            -- "b126"
       Put(-126, 7);                        -- "bbb-126"
       Put(126, Width => 13, Base => 2);    -- "bbb2#1111110#"

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12