home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl453up.zip / stl453fx / src / complex_io.cpp < prev    next >
C/C++ Source or Header  |  2002-04-29  |  3KB  |  145 lines

  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. // #include <iterator>
  21. #include "complex_impl.h"
  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. {
  34.   return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')';
  35. }
  36.  
  37. _STLP_OPERATOR_SPEC
  38. basic_ostream<char, char_traits<char> >& _STLP_CALL
  39. operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
  40. {
  41.   return __os << '(' << __z.real() << ',' << __z.imag() << ')';
  42. }
  43.  
  44. #ifndef _STLP_NO_LONG_DOUBLE
  45. _STLP_OPERATOR_SPEC
  46. basic_ostream<char, char_traits<char> >& _STLP_CALL
  47. operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
  48. {
  49.   return __os << '(' << __z.real() << ',' << __z.imag() << ')';
  50. }
  51. #endif
  52.  
  53. // Specialization for narrow characters; lets us avoid widen.
  54. _STLP_OPERATOR_SPEC
  55. basic_istream<char, char_traits<char> >& _STLP_CALL
  56. operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z)
  57. {
  58.   float  __re = 0;
  59.   float  __im = 0;
  60.  
  61.   char __c;
  62.  
  63.   __is >> __c;
  64.   if (__c == '(') {
  65.     __is >> __re >> __c;
  66.     if (__c == ',')
  67.       __is >> __im >> __c;
  68.     if (__c != ')')
  69.       __is.setstate(ios_base::failbit);
  70.   }
  71.   else {
  72.     __is.putback(__c);
  73.     __is >> __re;
  74.   }
  75.  
  76.   if (__is)
  77.     __z = complex<float>(__re, __im);
  78.   return __is;
  79. }
  80.  
  81. _STLP_OPERATOR_SPEC
  82. basic_istream<char, char_traits<char> >& _STLP_CALL
  83. operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z)
  84. {
  85.   double  __re = 0;
  86.   double  __im = 0;
  87.  
  88.   char __c;
  89.  
  90.   __is >> __c;
  91.   if (__c == '(') {
  92.     __is >> __re >> __c;
  93.     if (__c == ',')
  94.       __is >> __im >> __c;
  95.     if (__c != ')')
  96.       __is.setstate(ios_base::failbit);
  97.   }
  98.   else {
  99.     __is.putback(__c);
  100.     __is >> __re;
  101.   }
  102.  
  103.   if (__is)
  104.     __z = complex<double>(__re, __im);
  105.   return __is;
  106. }
  107.  
  108. #  ifndef _STLP_NO_LONG_DOUBLE
  109. _STLP_OPERATOR_SPEC
  110. basic_istream<char, char_traits<char> >& _STLP_CALL
  111. operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
  112.   long double  __re = 0;
  113.   long double  __im = 0;
  114.  
  115.   char __c;
  116.  
  117.   __is >> __c;
  118.   if (__c == '(') {
  119.     __is >> __re >> __c;
  120.     if (__c == ',')
  121.       __is >> __im >> __c;
  122.     if (__c != ')')
  123.       __is.setstate(ios_base::failbit);
  124.   }
  125.   else {
  126.     __is.putback(__c);
  127.     __is >> __re;
  128.   }
  129.  
  130.   if (__is)
  131.     __z = complex<long double>(__re, __im);
  132.   return __is;
  133. }
  134. #  endif
  135.  
  136. # endif /* MSVC */
  137.  
  138. _STLP_END_NAMESPACE
  139.  
  140.  
  141. // Local Variables:
  142. // mode:C++
  143. // End:
  144.  
  145.