complex_io.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include "stlport_prefix.h"
  19. #include <complex>
  20. #include <istream>
  21. _STLP_BEGIN_NAMESPACE
  22. // Specializations for narrow characters; lets us avoid the nuisance of
  23. // widening.
  24. _STLP_OPERATOR_SPEC
  25. basic_ostream<char, char_traits<char> >& _STLP_CALL
  26. operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
  27. { return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
  28. _STLP_OPERATOR_SPEC
  29. basic_ostream<char, char_traits<char> >& _STLP_CALL
  30. operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
  31. { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
  32. #ifndef _STLP_NO_LONG_DOUBLE
  33. _STLP_OPERATOR_SPEC
  34. basic_ostream<char, char_traits<char> >& _STLP_CALL
  35. operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
  36. { return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
  37. #endif
  38. // Specialization for narrow characters; lets us avoid widen.
  39. _STLP_OPERATOR_SPEC
  40. basic_istream<char, char_traits<char> >& _STLP_CALL
  41. operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
  42. float __re = 0;
  43. float __im = 0;
  44. char __c;
  45. __is >> __c;
  46. if (__c == '(') {
  47. __is >> __re >> __c;
  48. if (__c == ',')
  49. __is >> __im >> __c;
  50. if (__c != ')')
  51. __is.setstate(ios_base::failbit);
  52. }
  53. else {
  54. __is.putback(__c);
  55. __is >> __re;
  56. }
  57. if (__is)
  58. __z = complex<float>(__re, __im);
  59. return __is;
  60. }
  61. _STLP_OPERATOR_SPEC
  62. basic_istream<char, char_traits<char> >& _STLP_CALL
  63. operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
  64. double __re = 0;
  65. double __im = 0;
  66. char __c;
  67. __is >> __c;
  68. if (__c == '(') {
  69. __is >> __re >> __c;
  70. if (__c == ',')
  71. __is >> __im >> __c;
  72. if (__c != ')')
  73. __is.setstate(ios_base::failbit);
  74. }
  75. else {
  76. __is.putback(__c);
  77. __is >> __re;
  78. }
  79. if (__is)
  80. __z = complex<double>(__re, __im);
  81. return __is;
  82. }
  83. #ifndef _STLP_NO_LONG_DOUBLE
  84. _STLP_OPERATOR_SPEC
  85. basic_istream<char, char_traits<char> >& _STLP_CALL
  86. operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
  87. long double __re = 0;
  88. long double __im = 0;
  89. char __c;
  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. if (__is)
  103. __z = complex<long double>(__re, __im);
  104. return __is;
  105. }
  106. #endif
  107. // Force instantiation of complex I/O functions
  108. #if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
  109. _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  110. operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
  111. _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  112. operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
  113. #ifndef _STLP_NO_LONG_DOUBLE
  114. _STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  115. operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
  116. _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  117. operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
  118. #endif
  119. _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  120. operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
  121. _STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL
  122. operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
  123. #endif /* _STLP_NO_WCHAR_T */
  124. _STLP_END_NAMESPACE
  125. // Local Variables:
  126. // mode:C++
  127. // End: