]>
Commit | Line | Data |
---|---|---|
4c2d6a70 AC |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3084fecd | 3 | -- GNAT RUN-TIME COMPONENTS -- |
4c2d6a70 AC |
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 | -- -- | |
4b490c1e | 9 | -- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- |
4c2d6a70 AC |
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- -- | |
748086b7 | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
4c2d6a70 AC |
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 -- | |
748086b7 JJ |
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/>. -- | |
4c2d6a70 AC |
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; | |
338e5133 EB |
33 | with Ada.Wide_Wide_Text_IO.Float_Aux; |
34 | with System.Val_Flt; use System.Val_Flt; | |
35 | with System.Val_LFlt; use System.Val_LFlt; | |
36 | with System.Val_LLF; use System.Val_LLF; | |
37 | with System.WCh_Con; use System.WCh_Con; | |
38 | with System.WCh_WtS; use System.WCh_WtS; | |
4c2d6a70 AC |
39 | |
40 | with Ada.Unchecked_Conversion; | |
41 | ||
42 | package body Ada.Wide_Wide_Text_IO.Complex_IO is | |
43 | ||
338e5133 EB |
44 | use Complex_Types; |
45 | ||
46 | package Scalar_Float is new | |
47 | Ada.Wide_Wide_Text_IO.Float_Aux (Float, Scan_Float); | |
48 | ||
49 | package Scalar_Long_Float is new | |
50 | Ada.Wide_Wide_Text_IO.Float_Aux (Long_Float, Scan_Long_Float); | |
51 | ||
52 | package Scalar_Long_Long_Float is new | |
53 | Ada.Wide_Wide_Text_IO.Float_Aux (Long_Long_Float, Scan_Long_Long_Float); | |
54 | ||
55 | package Aux_Float is new | |
56 | Ada.Wide_Wide_Text_IO.Complex_Aux (Float, Scalar_Float); | |
4c2d6a70 | 57 | |
338e5133 EB |
58 | package Aux_Long_Float is new |
59 | Ada.Wide_Wide_Text_IO.Complex_Aux (Long_Float, Scalar_Long_Float); | |
4c2d6a70 | 60 | |
338e5133 EB |
61 | package Aux_Long_Long_Float is new |
62 | Ada.Wide_Wide_Text_IO.Complex_Aux | |
63 | (Long_Long_Float, Scalar_Long_Long_Float); | |
64 | ||
65 | -- Throughout this generic body, we distinguish between the case where type | |
66 | -- Float is OK, where type Long_Float is OK and where type Long_Long_Float | |
67 | -- is needed. These boolean constants are used to test for this, such that | |
68 | -- only code for the relevant case is included in the instance. | |
69 | ||
70 | OK_Float : constant Boolean := Real'Base'Digits <= Float'Digits; | |
71 | ||
72 | OK_Long_Float : constant Boolean := Real'Base'Digits <= Long_Float'Digits; | |
4c2d6a70 AC |
73 | |
74 | --------- | |
75 | -- Get -- | |
76 | --------- | |
77 | ||
78 | procedure Get | |
0ae9f22f | 79 | (File : File_Type; |
4c2d6a70 | 80 | Item : out Complex; |
0ae9f22f | 81 | Width : Field := 0) |
4c2d6a70 AC |
82 | is |
83 | Real_Item : Real'Base; | |
84 | Imag_Item : Real'Base; | |
85 | ||
86 | begin | |
338e5133 EB |
87 | if OK_Float then |
88 | Aux_Float.Get (File, Float (Real_Item), Float (Imag_Item), Width); | |
89 | elsif OK_Long_Float then | |
90 | Aux_Long_Float.Get | |
91 | (File, Long_Float (Real_Item), Long_Float (Imag_Item), Width); | |
92 | else | |
93 | Aux_Long_Long_Float.Get | |
94 | (File, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item), | |
95 | Width); | |
96 | end if; | |
97 | ||
4c2d6a70 AC |
98 | Item := (Real_Item, Imag_Item); |
99 | ||
100 | exception | |
101 | when Constraint_Error => raise Data_Error; | |
102 | end Get; | |
103 | ||
104 | --------- | |
105 | -- Get -- | |
106 | --------- | |
107 | ||
108 | procedure Get | |
109 | (Item : out Complex; | |
110 | Width : Field := 0) | |
111 | is | |
112 | begin | |
430dd877 | 113 | Get (Current_In, Item, Width); |
4c2d6a70 AC |
114 | end Get; |
115 | ||
116 | --------- | |
117 | -- Get -- | |
118 | --------- | |
119 | ||
120 | procedure Get | |
121 | (From : Wide_Wide_String; | |
122 | Item : out Complex; | |
123 | Last : out Positive) | |
124 | is | |
125 | Real_Item : Real'Base; | |
126 | Imag_Item : Real'Base; | |
127 | ||
128 | S : constant String := Wide_Wide_String_To_String (From, WCEM_Upper); | |
129 | -- String on which we do the actual conversion. Note that the method | |
130 | -- used for wide character encoding is irrelevant, since if there is | |
131 | -- a character outside the Standard.Character range then the call to | |
132 | -- Aux.Gets will raise Data_Error in any case. | |
133 | ||
134 | begin | |
338e5133 EB |
135 | if OK_Float then |
136 | Aux_Float.Gets (S, Float (Real_Item), Float (Imag_Item), Last); | |
137 | elsif OK_Long_Float then | |
138 | Aux_Long_Float.Gets | |
139 | (S, Long_Float (Real_Item), Long_Float (Imag_Item), Last); | |
140 | else | |
141 | Aux_Long_Long_Float.Gets | |
142 | (S, Long_Long_Float (Real_Item), Long_Long_Float (Imag_Item), | |
143 | Last); | |
144 | end if; | |
145 | ||
4c2d6a70 AC |
146 | Item := (Real_Item, Imag_Item); |
147 | ||
148 | exception | |
149 | when Data_Error => raise Constraint_Error; | |
150 | end Get; | |
151 | ||
152 | --------- | |
153 | -- Put -- | |
154 | --------- | |
155 | ||
156 | procedure Put | |
157 | (File : File_Type; | |
158 | Item : Complex; | |
159 | Fore : Field := Default_Fore; | |
160 | Aft : Field := Default_Aft; | |
161 | Exp : Field := Default_Exp) | |
162 | is | |
163 | begin | |
338e5133 EB |
164 | if OK_Float then |
165 | Aux_Float.Put | |
166 | (File, Float (Re (Item)), Float (Im (Item)), Fore, Aft, Exp); | |
167 | elsif OK_Long_Float then | |
168 | Aux_Long_Float.Put | |
169 | (File, Long_Float (Re (Item)), Long_Float (Im (Item)), Fore, Aft, | |
170 | Exp); | |
171 | else | |
172 | Aux_Long_Long_Float.Put | |
173 | (File, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)), | |
174 | Fore, Aft, Exp); | |
175 | end if; | |
4c2d6a70 AC |
176 | end Put; |
177 | ||
178 | --------- | |
179 | -- Put -- | |
180 | --------- | |
181 | ||
182 | procedure Put | |
183 | (Item : Complex; | |
184 | Fore : Field := Default_Fore; | |
185 | Aft : Field := Default_Aft; | |
186 | Exp : Field := Default_Exp) | |
187 | is | |
188 | begin | |
430dd877 | 189 | Put (Current_Out, Item, Fore, Aft, Exp); |
4c2d6a70 AC |
190 | end Put; |
191 | ||
192 | --------- | |
193 | -- Put -- | |
194 | --------- | |
195 | ||
196 | procedure Put | |
197 | (To : out Wide_Wide_String; | |
198 | Item : Complex; | |
199 | Aft : Field := Default_Aft; | |
200 | Exp : Field := Default_Exp) | |
201 | is | |
202 | S : String (To'First .. To'Last); | |
203 | ||
204 | begin | |
338e5133 EB |
205 | if OK_Float then |
206 | Aux_Float.Puts (S, Float (Re (Item)), Float (Im (Item)), Aft, Exp); | |
207 | elsif OK_Long_Float then | |
208 | Aux_Long_Float.Puts | |
209 | (S, Long_Float (Re (Item)), Long_Float (Im (Item)), Aft, Exp); | |
210 | else | |
211 | Aux_Long_Long_Float.Puts | |
212 | (S, Long_Long_Float (Re (Item)), Long_Long_Float (Im (Item)), | |
213 | Aft, Exp); | |
214 | end if; | |
4c2d6a70 AC |
215 | |
216 | for J in S'Range loop | |
217 | To (J) := Wide_Wide_Character'Val (Character'Pos (S (J))); | |
218 | end loop; | |
219 | end Put; | |
220 | ||
221 | end Ada.Wide_Wide_Text_IO.Complex_IO; |