OSDN Git Service

New Language: Ada
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-tideio.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUNTIME COMPONENTS                          --
4 --                                                                          --
5 --               A D A . T E X T _ I O . D E C I M A L _ I O                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.7 $
10 --                                                                          --
11 --          Copyright (C) 1992-1999 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNAT was originally developed  by the GNAT team at  New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 with Ada.Text_IO.Decimal_Aux;
37
38 package body Ada.Text_IO.Decimal_IO is
39
40    package Aux renames Ada.Text_IO.Decimal_Aux;
41
42    Scale : constant Integer := Num'Scale;
43
44    ---------
45    -- Get --
46    ---------
47
48    procedure Get
49      (File  : in File_Type;
50       Item  : out Num;
51       Width : in Field := 0)
52    is
53       pragma Unsuppress (Range_Check);
54
55    begin
56       if Num'Size > Integer'Size then
57          Item := Num'Fixed_Value (Aux.Get_LLD (File, Width, Scale));
58
59       else
60          Item := Num'Fixed_Value (Aux.Get_Dec (File, Width, Scale));
61       end if;
62
63    exception
64       when Constraint_Error => raise Data_Error;
65    end Get;
66
67    procedure Get
68      (Item  : out Num;
69       Width : in Field := 0)
70    is
71    begin
72       Get (Current_In, Item, Width);
73    end Get;
74
75    procedure Get
76      (From : in String;
77       Item : out Num;
78       Last : out Positive)
79    is
80       pragma Unsuppress (Range_Check);
81
82    begin
83       if Num'Size > Integer'Size then
84          Item := Num'Fixed_Value
85                    (Aux.Gets_LLD (From, Last'Unrestricted_Access, Scale));
86       else
87          Item := Num'Fixed_Value
88                    (Aux.Gets_Dec (From, Last'Unrestricted_Access, Scale));
89       end if;
90
91    exception
92       when Constraint_Error => raise Data_Error;
93    end Get;
94
95    ---------
96    -- Put --
97    ---------
98
99    procedure Put
100      (File : in File_Type;
101       Item : in Num;
102       Fore : in Field := Default_Fore;
103       Aft  : in Field := Default_Aft;
104       Exp  : in Field := Default_Exp)
105    is
106    begin
107       if Num'Size > Integer'Size then
108          Aux.Put_LLD
109            (File, Long_Long_Integer'Integer_Value (Item),
110             Fore, Aft, Exp, Scale);
111       else
112          Aux.Put_Dec
113            (File, Integer'Integer_Value (Item), Fore, Aft, Exp, Scale);
114       end if;
115    end Put;
116
117    procedure Put
118      (Item : in Num;
119       Fore : in Field := Default_Fore;
120       Aft  : in Field := Default_Aft;
121       Exp  : in Field := Default_Exp)
122    is
123    begin
124       Put (Current_Out, Item, Fore, Aft, Exp);
125    end Put;
126
127    procedure Put
128      (To   : out String;
129       Item : in Num;
130       Aft  : in Field := Default_Aft;
131       Exp  : in Field := Default_Exp)
132    is
133    begin
134       if Num'Size > Integer'Size then
135          Aux.Puts_LLD
136            (To, Long_Long_Integer'Integer_Value (Item), Aft, Exp, Scale);
137       else
138          Aux.Puts_Dec (To, Integer'Integer_Value (Item), Aft, Exp, Scale);
139       end if;
140    end Put;
141
142 end Ada.Text_IO.Decimal_IO;