michael@0: /* michael@0: * Copyright (c) 1999 michael@0: * Silicon Graphics Computer Systems, Inc. michael@0: * michael@0: * Copyright (c) 1999 michael@0: * Boris Fomitchev michael@0: * michael@0: * This material is provided "as is", with absolutely no warranty expressed michael@0: * or implied. Any use is at your own risk. michael@0: * michael@0: * Permission to use or copy this software for any purpose is hereby granted michael@0: * without fee, provided the above notices are retained on all copies. michael@0: * Permission to modify the code and to distribute modified code is granted, michael@0: * provided the above notices are retained, and a notice that the code was michael@0: * modified is included with the above copyright notice. michael@0: * michael@0: */ michael@0: michael@0: #include "stlport_prefix.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: _STLP_BEGIN_NAMESPACE michael@0: michael@0: // Specializations for narrow characters; lets us avoid the nuisance of michael@0: // widening. michael@0: _STLP_OPERATOR_SPEC michael@0: basic_ostream >& _STLP_CALL michael@0: operator<< (basic_ostream >& __os, const complex& __z) michael@0: { return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; } michael@0: michael@0: _STLP_OPERATOR_SPEC michael@0: basic_ostream >& _STLP_CALL michael@0: operator<< (basic_ostream >& __os, const complex& __z) michael@0: { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; } michael@0: michael@0: #ifndef _STLP_NO_LONG_DOUBLE michael@0: _STLP_OPERATOR_SPEC michael@0: basic_ostream >& _STLP_CALL michael@0: operator<< (basic_ostream >& __os, const complex& __z) michael@0: { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; } michael@0: #endif michael@0: michael@0: // Specialization for narrow characters; lets us avoid widen. michael@0: _STLP_OPERATOR_SPEC michael@0: basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >& __is, complex& __z) { michael@0: float __re = 0; michael@0: float __im = 0; michael@0: michael@0: char __c; michael@0: michael@0: __is >> __c; michael@0: if (__c == '(') { michael@0: __is >> __re >> __c; michael@0: if (__c == ',') michael@0: __is >> __im >> __c; michael@0: if (__c != ')') michael@0: __is.setstate(ios_base::failbit); michael@0: } michael@0: else { michael@0: __is.putback(__c); michael@0: __is >> __re; michael@0: } michael@0: michael@0: if (__is) michael@0: __z = complex(__re, __im); michael@0: return __is; michael@0: } michael@0: michael@0: _STLP_OPERATOR_SPEC michael@0: basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >& __is, complex& __z) { michael@0: double __re = 0; michael@0: double __im = 0; michael@0: michael@0: char __c; michael@0: michael@0: __is >> __c; michael@0: if (__c == '(') { michael@0: __is >> __re >> __c; michael@0: if (__c == ',') michael@0: __is >> __im >> __c; michael@0: if (__c != ')') michael@0: __is.setstate(ios_base::failbit); michael@0: } michael@0: else { michael@0: __is.putback(__c); michael@0: __is >> __re; michael@0: } michael@0: michael@0: if (__is) michael@0: __z = complex(__re, __im); michael@0: return __is; michael@0: } michael@0: michael@0: #ifndef _STLP_NO_LONG_DOUBLE michael@0: _STLP_OPERATOR_SPEC michael@0: basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >& __is, complex& __z) { michael@0: long double __re = 0; michael@0: long double __im = 0; michael@0: michael@0: char __c; michael@0: michael@0: __is >> __c; michael@0: if (__c == '(') { michael@0: __is >> __re >> __c; michael@0: if (__c == ',') michael@0: __is >> __im >> __c; michael@0: if (__c != ')') michael@0: __is.setstate(ios_base::failbit); michael@0: } michael@0: else { michael@0: __is.putback(__c); michael@0: __is >> __re; michael@0: } michael@0: michael@0: if (__is) michael@0: __z = complex(__re, __im); michael@0: return __is; michael@0: } michael@0: #endif michael@0: michael@0: // Force instantiation of complex I/O functions michael@0: #if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T)) michael@0: michael@0: _STLP_OPERATOR_SPEC basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >&, complex&); michael@0: michael@0: _STLP_OPERATOR_SPEC basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >&, complex&); michael@0: michael@0: #ifndef _STLP_NO_LONG_DOUBLE michael@0: _STLP_OPERATOR_SPEC basic_istream >& _STLP_CALL michael@0: operator>>(basic_istream >&, complex&); michael@0: michael@0: _STLP_OPERATOR_SPEC basic_ostream >& _STLP_CALL michael@0: operator<<(basic_ostream >&, const complex&); michael@0: #endif michael@0: michael@0: _STLP_OPERATOR_SPEC basic_ostream >& _STLP_CALL michael@0: operator<<(basic_ostream >&, const complex&); michael@0: michael@0: _STLP_OPERATOR_SPEC basic_ostream >& _STLP_CALL michael@0: operator<<(basic_ostream >&, const complex&); michael@0: michael@0: #endif /* _STLP_NO_WCHAR_T */ michael@0: michael@0: _STLP_END_NAMESPACE michael@0: michael@0: michael@0: // Local Variables: michael@0: // mode:C++ michael@0: // End: michael@0: