1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . W I D E _ W I D E _ T E X T _ IO . C O M P L E X _ I O --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with Ada
.Wide_Wide_Text_IO
.Complex_Aux
;
33 with Ada
.Wide_Wide_Text_IO
.Float_Aux
;
34 with System
.Img_Flt
; use System
.Img_Flt
;
35 with System
.Img_LFlt
; use System
.Img_LFlt
;
36 with System
.Img_LLF
; use System
.Img_LLF
;
37 with System
.Val_Flt
; use System
.Val_Flt
;
38 with System
.Val_LFlt
; use System
.Val_LFlt
;
39 with System
.Val_LLF
; use System
.Val_LLF
;
40 with System
.WCh_Con
; use System
.WCh_Con
;
41 with System
.WCh_WtS
; use System
.WCh_WtS
;
43 package body Ada
.Wide_Wide_Text_IO
.Complex_IO
is
47 package Scalar_Float
is new
48 Ada
.Wide_Wide_Text_IO
.Float_Aux
(Float, Scan_Float
, Set_Image_Float
);
50 package Scalar_Long_Float
is new
51 Ada
.Wide_Wide_Text_IO
.Float_Aux
52 (Long_Float, Scan_Long_Float
, Set_Image_Long_Float
);
54 package Scalar_Long_Long_Float
is new
55 Ada
.Wide_Wide_Text_IO
.Float_Aux
56 (Long_Long_Float, Scan_Long_Long_Float
, Set_Image_Long_Long_Float
);
58 package Aux_Float
is new
59 Ada
.Wide_Wide_Text_IO
.Complex_Aux
(Float, Scalar_Float
);
61 package Aux_Long_Float
is new
62 Ada
.Wide_Wide_Text_IO
.Complex_Aux
(Long_Float, Scalar_Long_Float
);
64 package Aux_Long_Long_Float
is new
65 Ada
.Wide_Wide_Text_IO
.Complex_Aux
66 (Long_Long_Float, Scalar_Long_Long_Float
);
68 -- Throughout this generic body, we distinguish between the case where type
69 -- Float is OK, where type Long_Float is OK and where type Long_Long_Float
70 -- is needed. These boolean constants are used to test for this, such that
71 -- only code for the relevant case is included in the instance.
73 OK_Float
: constant Boolean := Real
'Base'Digits <= Float'Digits;
75 OK_Long_Float : constant Boolean := Real'Base'Digits <= Long_Float'Digits;
86 Real_Item
: Real
'Base;
87 Imag_Item
: Real
'Base;
91 Aux_Float
.Get
(File
, Float (Real_Item
), Float (Imag_Item
), Width
);
92 elsif OK_Long_Float
then
94 (File
, Long_Float (Real_Item
), Long_Float (Imag_Item
), Width
);
96 Aux_Long_Long_Float
.Get
97 (File
, Long_Long_Float (Real_Item
), Long_Long_Float (Imag_Item
),
101 Item
:= (Real_Item
, Imag_Item
);
104 when Constraint_Error
=> raise Data_Error
;
116 Get
(Current_In
, Item
, Width
);
124 (From
: Wide_Wide_String
;
128 Real_Item
: Real
'Base;
129 Imag_Item
: Real
'Base;
131 S
: constant String := Wide_Wide_String_To_String
(From
, WCEM_Upper
);
132 -- String on which we do the actual conversion. Note that the method
133 -- used for wide character encoding is irrelevant, since if there is
134 -- a character outside the Standard.Character range then the call to
135 -- Aux.Gets will raise Data_Error in any case.
139 Aux_Float
.Gets
(S
, Float (Real_Item
), Float (Imag_Item
), Last
);
140 elsif OK_Long_Float
then
142 (S
, Long_Float (Real_Item
), Long_Float (Imag_Item
), Last
);
144 Aux_Long_Long_Float
.Gets
145 (S
, Long_Long_Float (Real_Item
), Long_Long_Float (Imag_Item
),
149 Item
:= (Real_Item
, Imag_Item
);
152 when Data_Error
=> raise Constraint_Error
;
162 Fore
: Field
:= Default_Fore
;
163 Aft
: Field
:= Default_Aft
;
164 Exp
: Field
:= Default_Exp
)
169 (File
, Float (Re
(Item
)), Float (Im
(Item
)), Fore
, Aft
, Exp
);
170 elsif OK_Long_Float
then
172 (File
, Long_Float (Re
(Item
)), Long_Float (Im
(Item
)), Fore
, Aft
,
175 Aux_Long_Long_Float
.Put
176 (File
, Long_Long_Float (Re
(Item
)), Long_Long_Float (Im
(Item
)),
187 Fore
: Field
:= Default_Fore
;
188 Aft
: Field
:= Default_Aft
;
189 Exp
: Field
:= Default_Exp
)
192 Put
(Current_Out
, Item
, Fore
, Aft
, Exp
);
200 (To
: out Wide_Wide_String
;
202 Aft
: Field
:= Default_Aft
;
203 Exp
: Field
:= Default_Exp
)
205 S
: String (To
'First .. To
'Last);
209 Aux_Float
.Puts
(S
, Float (Re
(Item
)), Float (Im
(Item
)), Aft
, Exp
);
210 elsif OK_Long_Float
then
212 (S
, Long_Float (Re
(Item
)), Long_Float (Im
(Item
)), Aft
, Exp
);
214 Aux_Long_Long_Float
.Puts
215 (S
, Long_Long_Float (Re
(Item
)), Long_Long_Float (Im
(Item
)),
219 for J
in S
'Range loop
220 To
(J
) := Wide_Wide_Character
'Val (Character'Pos (S
(J
)));
224 end Ada
.Wide_Wide_Text_IO
.Complex_IO
;