OSDN Git Service

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