| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 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 -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 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. -- |
| 17 |
-- -- |
| 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. -- |
| 21 |
-- -- |
| 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/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 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; |
| 42 |
|
| 43 |
package body Ada.Wide_Wide_Text_IO.Complex_IO is |
| 44 |
|
| 45 |
use Complex_Types; |
| 46 |
|
| 47 |
package Scalar_Float is new |
| 48 |
Ada.Wide_Wide_Text_IO.Float_Aux (Float, Scan_Float, Set_Image_Float); |
| 49 |
|
| 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); |
| 53 |
|
| 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); |
| 57 |
|
| 58 |
package Aux_Float is new |
| 59 |
Ada.Wide_Wide_Text_IO.Complex_Aux (Float, Scalar_Float); |
| 60 |
|
| 61 |
package Aux_Long_Float is new |
| 62 |
Ada.Wide_Wide_Text_IO.Complex_Aux (Long_Float, Scalar_Long_Float); |
| 63 |
|
| 64 |
package Aux_Long_Long_Float is new |
| 65 |
Ada.Wide_Wide_Text_IO.Complex_Aux |
| 66 |
(Long_Long_Float, Scalar_Long_Long_Float); |
| 67 |
|
| 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. |
| 72 |
|
| 73 |
OK_Float : constant Boolean := Real'Base'Digits <= Float'Digits; |
| 74 |
|
| 75 |
OK_Long_Float : constant Boolean := Real'Base'Digits <= Long_Float'Digits; |
| 76 |
|
| 77 |
--------- |
| 78 |
-- Get -- |
| 79 |
--------- |
| 80 |
|
| 81 |
procedure Get |
| 82 |
(File : File_Type; |
| 83 |
Item : out Complex; |
| 84 |
Width : Field := 0) |
| 85 |
is |
| 86 |
Real_Item : Real'Base; |
| 87 |
Imag_Item : Real'Base; |
| 88 |
|
| 89 |
begin |
| 90 |
if OK_Float then |
| 91 |
Aux_Float.Get (File, Float (Real_Item), Float (Imag_Item), Width); |
| 92 |
elsif OK_Long_Float then |
| 93 |
Aux_Long_Float.Get |
| 94 |
(File, Long_Float (Real_Item), Long_Float (Imag_Item), Width); |
| 95 |
else |
| 96 |
Aux_Long_Long_Float.Get |
| 97 |
(File, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item), |
| 98 |
Width); |
| 99 |
end if; |
| 100 |
|
| 101 |
Item := (Real_Item, Imag_Item); |
| 102 |
|
| 103 |
exception |
| 104 |
when Constraint_Error => raise Data_Error; |
| 105 |
end Get; |
| 106 |
|
| 107 |
--------- |
| 108 |
-- Get -- |
| 109 |
--------- |
| 110 |
|
| 111 |
procedure Get |
| 112 |
(Item : out Complex; |
| 113 |
Width : Field := 0) |
| 114 |
is |
| 115 |
begin |
| 116 |
Get (Current_In, Item, Width); |
| 117 |
end Get; |
| 118 |
|
| 119 |
--------- |
| 120 |
-- Get -- |
| 121 |
--------- |
| 122 |
|
| 123 |
procedure Get |
| 124 |
(From : Wide_Wide_String; |
| 125 |
Item : out Complex; |
| 126 |
Last : out Positive) |
| 127 |
is |
| 128 |
Real_Item : Real'Base; |
| 129 |
Imag_Item : Real'Base; |
| 130 |
|
| 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. |
| 136 |
|
| 137 |
begin |
| 138 |
if OK_Float then |
| 139 |
Aux_Float.Gets (S, Float (Real_Item), Float (Imag_Item), Last); |
| 140 |
elsif OK_Long_Float then |
| 141 |
Aux_Long_Float.Gets |
| 142 |
(S, Long_Float (Real_Item), Long_Float (Imag_Item), Last); |
| 143 |
else |
| 144 |
Aux_Long_Long_Float.Gets |
| 145 |
(S, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item), |
| 146 |
Last); |
| 147 |
end if; |
| 148 |
|
| 149 |
Item := (Real_Item, Imag_Item); |
| 150 |
|
| 151 |
exception |
| 152 |
when Data_Error => raise Constraint_Error; |
| 153 |
end Get; |
| 154 |
|
| 155 |
--------- |
| 156 |
-- Put -- |
| 157 |
--------- |
| 158 |
|
| 159 |
procedure Put |
| 160 |
(File : File_Type; |
| 161 |
Item : Complex; |
| 162 |
Fore : Field := Default_Fore; |
| 163 |
Aft : Field := Default_Aft; |
| 164 |
Exp : Field := Default_Exp) |
| 165 |
is |
| 166 |
begin |
| 167 |
if OK_Float then |
| 168 |
Aux_Float.Put |
| 169 |
(File, Float (Re (Item)), Float (Im (Item)), Fore, Aft, Exp); |
| 170 |
elsif OK_Long_Float then |
| 171 |
Aux_Long_Float.Put |
| 172 |
(File, Long_Float (Re (Item)), Long_Float (Im (Item)), Fore, Aft, |
| 173 |
Exp); |
| 174 |
else |
| 175 |
Aux_Long_Long_Float.Put |
| 176 |
(File, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)), |
| 177 |
Fore, Aft, Exp); |
| 178 |
end if; |
| 179 |
end Put; |
| 180 |
|
| 181 |
--------- |
| 182 |
-- Put -- |
| 183 |
--------- |
| 184 |
|
| 185 |
procedure Put |
| 186 |
(Item : Complex; |
| 187 |
Fore : Field := Default_Fore; |
| 188 |
Aft : Field := Default_Aft; |
| 189 |
Exp : Field := Default_Exp) |
| 190 |
is |
| 191 |
begin |
| 192 |
Put (Current_Out, Item, Fore, Aft, Exp); |
| 193 |
end Put; |
| 194 |
|
| 195 |
--------- |
| 196 |
-- Put -- |
| 197 |
--------- |
| 198 |
|
| 199 |
procedure Put |
| 200 |
(To : out Wide_Wide_String; |
| 201 |
Item : Complex; |
| 202 |
Aft : Field := Default_Aft; |
| 203 |
Exp : Field := Default_Exp) |
| 204 |
is |
| 205 |
S : String (To'First .. To'Last); |
| 206 |
|
| 207 |
begin |
| 208 |
if OK_Float then |
| 209 |
Aux_Float.Puts (S, Float (Re (Item)), Float (Im (Item)), Aft, Exp); |
| 210 |
elsif OK_Long_Float then |
| 211 |
Aux_Long_Float.Puts |
| 212 |
(S, Long_Float (Re (Item)), Long_Float (Im (Item)), Aft, Exp); |
| 213 |
else |
| 214 |
Aux_Long_Long_Float.Puts |
| 215 |
(S, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)), |
| 216 |
Aft, Exp); |
| 217 |
end if; |
| 218 |
|
| 219 |
for J in S'Range loop |
| 220 |
To (J) := Wide_Wide_Character'Val (Character'Pos (S (J))); |
| 221 |
end loop; |
| 222 |
end Put; |
| 223 |
|
| 224 |
end Ada.Wide_Wide_Text_IO.Complex_IO; |