/home/ntakagi/work/STLport-5.1.5/src/complex_io.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #include "stlport_prefix.h"
00020 
00021 #include <complex>
00022 #include <istream>
00023 
00024 _STLP_BEGIN_NAMESPACE
00025 
00026 #if !(defined (_STLP_MSVC) && _STLP_MSVC < 1200)
00027 
00028 // Specializations for narrow characters; lets us avoid the nuisance of
00029 // widening.
00030 _STLP_OPERATOR_SPEC
00031 basic_ostream<char, char_traits<char> >& _STLP_CALL
00032 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
00033 { return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
00034 
00035 _STLP_OPERATOR_SPEC
00036 basic_ostream<char, char_traits<char> >& _STLP_CALL
00037 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
00038 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
00039 
00040 #  ifndef _STLP_NO_LONG_DOUBLE
00041 _STLP_OPERATOR_SPEC
00042 basic_ostream<char, char_traits<char> >& _STLP_CALL
00043 operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
00044 { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
00045 #  endif
00046 
00047 // Specialization for narrow characters; lets us avoid widen.
00048 _STLP_OPERATOR_SPEC
00049 basic_istream<char, char_traits<char> >& _STLP_CALL
00050 operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
00051   float  __re = 0;
00052   float  __im = 0;
00053 
00054   char __c;
00055 
00056   __is >> __c;
00057   if (__c == '(') {
00058     __is >> __re >> __c;
00059     if (__c == ',')
00060       __is >> __im >> __c;
00061     if (__c != ')')
00062       __is.setstate(ios_base::failbit);
00063   }
00064   else {
00065     __is.putback(__c);
00066     __is >> __re;
00067   }
00068 
00069   if (__is)
00070     __z = complex<float>(__re, __im);
00071   return __is;
00072 }
00073 
00074 _STLP_OPERATOR_SPEC
00075 basic_istream<char, char_traits<char> >& _STLP_CALL
00076 operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
00077   double  __re = 0;
00078   double  __im = 0;
00079 
00080   char __c;
00081 
00082   __is >> __c;
00083   if (__c == '(') {
00084     __is >> __re >> __c;
00085     if (__c == ',')
00086       __is >> __im >> __c;
00087     if (__c != ')')
00088       __is.setstate(ios_base::failbit);
00089   }
00090   else {
00091     __is.putback(__c);
00092     __is >> __re;
00093   }
00094 
00095   if (__is)
00096     __z = complex<double>(__re, __im);
00097   return __is;
00098 }
00099 
00100 #  ifndef _STLP_NO_LONG_DOUBLE
00101 _STLP_OPERATOR_SPEC
00102 basic_istream<char, char_traits<char> >& _STLP_CALL
00103 operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
00104   long double  __re = 0;
00105   long double  __im = 0;
00106 
00107   char __c;
00108 
00109   __is >> __c;
00110   if (__c == '(') {
00111     __is >> __re >> __c;
00112     if (__c == ',')
00113       __is >> __im >> __c;
00114     if (__c != ')')
00115       __is.setstate(ios_base::failbit);
00116   }
00117   else {
00118     __is.putback(__c);
00119     __is >> __re;
00120   }
00121 
00122   if (__is)
00123     __z = complex<long double>(__re, __im);
00124   return __is;
00125 }
00126 #  endif
00127 
00128 #endif /* MSVC */
00129 
00130 // Force instantiation of complex I/O functions
00131 #if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
00132 
00133 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00134 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
00135 
00136 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00137 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
00138 
00139 #ifndef _STLP_NO_LONG_DOUBLE
00140 _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00141 operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
00142 
00143 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00144 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
00145 #endif
00146 
00147 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00148 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
00149 
00150 _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
00151 operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
00152 
00153 #endif /* _STLP_NO_WCHAR_T */
00154 
00155 _STLP_END_NAMESPACE
00156 
00157 
00158 // Local Variables:
00159 // mode:C++
00160 // End:
00161 



Generated on Mon Mar 10 15:32:16 2008 by  doxygen 1.5.1