]> git.buserror.net Git - polintos/scott/priv.git/blob - lib/c++/stlport/complex_io.cpp
Add STLport 5.1.4
[polintos/scott/priv.git] / lib / c++ / stlport / complex_io.cpp
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18
19 #include "stlport_prefix.h"
20
21 #include <complex>
22 #include <istream>
23
24 _STLP_BEGIN_NAMESPACE
25
26 #if !(defined (_STLP_MSVC) && _STLP_MSVC < 1200)
27
28 // Specializations for narrow characters; lets us avoid the nuisance of
29 // widening.
30 _STLP_OPERATOR_SPEC
31 basic_ostream<char, char_traits<char> >& _STLP_CALL
32 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
33 { return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
34
35 _STLP_OPERATOR_SPEC
36 basic_ostream<char, char_traits<char> >& _STLP_CALL
37 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
38 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
39
40 #  ifndef _STLP_NO_LONG_DOUBLE
41 _STLP_OPERATOR_SPEC
42 basic_ostream<char, char_traits<char> >& _STLP_CALL
43 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
44 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
45 #  endif
46
47 // Specialization for narrow characters; lets us avoid widen.
48 _STLP_OPERATOR_SPEC
49 basic_istream<char, char_traits<char> >& _STLP_CALL
50 operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
51   float  __re = 0;
52   float  __im = 0;
53
54   char __c;
55
56   __is >> __c;
57   if (__c == '(') {
58     __is >> __re >> __c;
59     if (__c == ',')
60       __is >> __im >> __c;
61     if (__c != ')')
62       __is.setstate(ios_base::failbit);
63   }
64   else {
65     __is.putback(__c);
66     __is >> __re;
67   }
68
69   if (__is)
70     __z = complex<float>(__re, __im);
71   return __is;
72 }
73
74 _STLP_OPERATOR_SPEC
75 basic_istream<char, char_traits<char> >& _STLP_CALL
76 operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
77   double  __re = 0;
78   double  __im = 0;
79
80   char __c;
81
82   __is >> __c;
83   if (__c == '(') {
84     __is >> __re >> __c;
85     if (__c == ',')
86       __is >> __im >> __c;
87     if (__c != ')')
88       __is.setstate(ios_base::failbit);
89   }
90   else {
91     __is.putback(__c);
92     __is >> __re;
93   }
94
95   if (__is)
96     __z = complex<double>(__re, __im);
97   return __is;
98 }
99
100 #  ifndef _STLP_NO_LONG_DOUBLE
101 _STLP_OPERATOR_SPEC
102 basic_istream<char, char_traits<char> >& _STLP_CALL
103 operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
104   long double  __re = 0;
105   long double  __im = 0;
106
107   char __c;
108
109   __is >> __c;
110   if (__c == '(') {
111     __is >> __re >> __c;
112     if (__c == ',')
113       __is >> __im >> __c;
114     if (__c != ')')
115       __is.setstate(ios_base::failbit);
116   }
117   else {
118     __is.putback(__c);
119     __is >> __re;
120   }
121
122   if (__is)
123     __z = complex<long double>(__re, __im);
124   return __is;
125 }
126 #  endif
127
128 #endif /* MSVC */
129
130 // Force instantiation of complex I/O functions
131 #if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
132
133 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
134 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
135
136 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
137 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
138
139 #ifndef _STLP_NO_LONG_DOUBLE
140 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
141 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
142
143 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
144 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
145 #endif
146
147 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
148 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
149
150 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
151 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
152
153 #endif /* _STLP_NO_WCHAR_T */
154
155 _STLP_END_NAMESPACE
156
157
158 // Local Variables:
159 // mode:C++
160 // End:
161