Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

complex_io.cc

Go to the documentation of this file.
00001 // The template and inlines for the -*- C++ -*- complex number classes.
00002 
00003 // Copyright (C) 2000 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 #include <bits/std_complex.h>
00031 #include <bits/std_istream.h>
00032 #include <bits/std_ostream.h>
00033 #include <bits/std_sstream.h>
00034 
00035 namespace std
00036 {
00037     
00038   template<typename _Tp, typename _CharT, class _Traits>
00039     basic_istream <_CharT, _Traits> &
00040     operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
00041     {
00042 #if !defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) && !defined(_GLIBCPP_BUGGY_COMPLEX)
00043       _Tp __re_x, __im_x;
00044       _CharT __ch;
00045       __is >> __ch;
00046       if (__ch == '(') 
00047     {
00048       __is >> __re_x >> __ch;
00049       if (__ch == ',') 
00050         {
00051           __is >> __im_x >> __ch;
00052           if (__ch == ')') 
00053         {
00054           __x = complex<_Tp>(__re_x, __im_x);
00055           return __is;
00056         }
00057         }
00058       else if (__ch == ')') 
00059         {
00060           __x = complex<_Tp>(__re_x, _Tp(0));
00061           return __is;
00062         }
00063     }
00064       else 
00065     {
00066       __is.putback(__ch);
00067       __is >> __re_x;
00068       __x = complex<_Tp>(__re_x, _Tp(0));
00069       return __is;
00070     }
00071       __is.setstate(ios_base::failbit);
00072 #else
00073       __x = complex<_Tp>(_Tp(0), _Tp(0));
00074 #endif
00075       return __is;
00076     }
00077 
00078   template<typename _Tp, typename _CharT, class _Traits>
00079     basic_ostream<_CharT, _Traits>&
00080     operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
00081     {
00082       basic_ostringstream<_CharT, _Traits> __s;
00083       __s.flags(__os.flags());
00084       __s.imbue(__os.getloc());
00085       __s.precision (__os.precision());
00086       __s << '(' << __x.real() << "," << __x.imag() << ')' << ends;
00087       return __os << __s.str();
00088     }
00089 
00090 
00091   template
00092     basic_istream<char, char_traits<char> >&
00093     operator>>(basic_istream<char, char_traits<char> >&, complex<float>&);
00094 
00095   template
00096     basic_ostream<char, char_traits<char> >&
00097     operator<<(basic_ostream<char, char_traits<char> >&, 
00098            const complex<float>&);
00099 
00100   template
00101     basic_istream<char, char_traits<char> >&
00102     operator>>(basic_istream<char, char_traits<char> >&, complex<double>&);
00103 
00104   template
00105     basic_ostream<char, char_traits<char> >&
00106     operator<<(basic_ostream<char, char_traits<char> >&, 
00107            const complex<double>&);
00108 
00109   template
00110     basic_istream<char, char_traits<char> >&
00111     operator>>(basic_istream<char, char_traits<char> >&, 
00112            complex<long double>&);
00113 
00114   template
00115     basic_ostream<char, char_traits<char> >&
00116     operator<<(basic_ostream<char, char_traits<char> >&,
00117                const complex<long double>&);
00118 
00119 #ifdef _GLIBCPP_USE_WCHAR_T
00120   template
00121     basic_istream<wchar_t, char_traits<wchar_t> >&
00122     operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&,
00123                complex<float>&);
00124 
00125   template
00126     basic_ostream<wchar_t, char_traits<wchar_t> >&
00127     operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&,
00128                const complex<float>&);
00129 
00130   template
00131     basic_istream<wchar_t, char_traits<wchar_t> >&
00132     operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&,
00133                complex<double>&);
00134 
00135   template
00136     basic_ostream<wchar_t, char_traits<wchar_t> >&
00137     operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&,
00138                const complex<double>&);
00139 
00140   template
00141     basic_istream<wchar_t, char_traits<wchar_t> >&
00142     operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&,
00143                complex<long double>&);
00144 
00145   template
00146     basic_ostream<wchar_t, char_traits<wchar_t> >&
00147     operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&,
00148                const complex<long double>&);
00149 #endif //_GLIBCPP_USE_WCHAR_T
00150 } // namespace std
00151 

Generated at Tue May 1 16:28:37 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001