Home | History | Annotate | Download | only in src
      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 // Specializations for narrow characters; lets us avoid the nuisance of
     27 // widening.
     28 _STLP_OPERATOR_SPEC
     29 basic_ostream<char, char_traits<char> >& _STLP_CALL
     30 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
     31 { return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
     32 
     33 _STLP_OPERATOR_SPEC
     34 basic_ostream<char, char_traits<char> >& _STLP_CALL
     35 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
     36 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
     37 
     38 #ifndef _STLP_NO_LONG_DOUBLE
     39 _STLP_OPERATOR_SPEC
     40 basic_ostream<char, char_traits<char> >& _STLP_CALL
     41 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
     42 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
     43 #endif
     44 
     45 // Specialization for narrow characters; lets us avoid widen.
     46 _STLP_OPERATOR_SPEC
     47 basic_istream<char, char_traits<char> >& _STLP_CALL
     48 operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
     49   float  __re = 0;
     50   float  __im = 0;
     51 
     52   char __c;
     53 
     54   __is >> __c;
     55   if (__c == '(') {
     56     __is >> __re >> __c;
     57     if (__c == ',')
     58       __is >> __im >> __c;
     59     if (__c != ')')
     60       __is.setstate(ios_base::failbit);
     61   }
     62   else {
     63     __is.putback(__c);
     64     __is >> __re;
     65   }
     66 
     67   if (__is)
     68     __z = complex<float>(__re, __im);
     69   return __is;
     70 }
     71 
     72 _STLP_OPERATOR_SPEC
     73 basic_istream<char, char_traits<char> >& _STLP_CALL
     74 operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
     75   double  __re = 0;
     76   double  __im = 0;
     77 
     78   char __c;
     79 
     80   __is >> __c;
     81   if (__c == '(') {
     82     __is >> __re >> __c;
     83     if (__c == ',')
     84       __is >> __im >> __c;
     85     if (__c != ')')
     86       __is.setstate(ios_base::failbit);
     87   }
     88   else {
     89     __is.putback(__c);
     90     __is >> __re;
     91   }
     92 
     93   if (__is)
     94     __z = complex<double>(__re, __im);
     95   return __is;
     96 }
     97 
     98 #ifndef _STLP_NO_LONG_DOUBLE
     99 _STLP_OPERATOR_SPEC
    100 basic_istream<char, char_traits<char> >& _STLP_CALL
    101 operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
    102   long double  __re = 0;
    103   long double  __im = 0;
    104 
    105   char __c;
    106 
    107   __is >> __c;
    108   if (__c == '(') {
    109     __is >> __re >> __c;
    110     if (__c == ',')
    111       __is >> __im >> __c;
    112     if (__c != ')')
    113       __is.setstate(ios_base::failbit);
    114   }
    115   else {
    116     __is.putback(__c);
    117     __is >> __re;
    118   }
    119 
    120   if (__is)
    121     __z = complex<long double>(__re, __im);
    122   return __is;
    123 }
    124 #endif
    125 
    126 // Force instantiation of complex I/O functions
    127 #if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
    128 
    129 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
    130 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
    131 
    132 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
    133 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
    134 
    135 #ifndef _STLP_NO_LONG_DOUBLE
    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<long double>&);
    138 
    139 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
    140 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
    141 #endif
    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<float>&);
    145 
    146 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
    147 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
    148 
    149 #endif /* _STLP_NO_WCHAR_T */
    150 
    151 _STLP_END_NAMESPACE
    152 
    153 
    154 // Local Variables:
    155 // mode:C++
    156 // End:
    157 
    158