aboutsummaryrefslogtreecommitdiff
path: root/src/complex_io.cpp
blob: 4cb6636f634d7187cf2e03faf9dadc6e928f0cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (c) 1999
 * Silicon Graphics Computer Systems, Inc.
 *
 * Copyright (c) 1999
 * Boris Fomitchev
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

#include "stlport_prefix.h"

#include <complex>
#include <istream>

_STLP_BEGIN_NAMESPACE

// Specializations for narrow characters; lets us avoid the nuisance of
// widening.
_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
{ return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }

_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }

#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC
basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
#endif

// Specialization for narrow characters; lets us avoid widen.
_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
  float  __re = 0;
  float  __im = 0;

  char __c;

  __is >> __c;
  if (__c == '(') {
    __is >> __re >> __c;
    if (__c == ',')
      __is >> __im >> __c;
    if (__c != ')')
      __is.setstate(ios_base::failbit);
  }
  else {
    __is.putback(__c);
    __is >> __re;
  }

  if (__is)
    __z = complex<float>(__re, __im);
  return __is;
}

_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
  double  __re = 0;
  double  __im = 0;

  char __c;

  __is >> __c;
  if (__c == '(') {
    __is >> __re >> __c;
    if (__c == ',')
      __is >> __im >> __c;
    if (__c != ')')
      __is.setstate(ios_base::failbit);
  }
  else {
    __is.putback(__c);
    __is >> __re;
  }

  if (__is)
    __z = complex<double>(__re, __im);
  return __is;
}

#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC
basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
  long double  __re = 0;
  long double  __im = 0;

  char __c;

  __is >> __c;
  if (__c == '(') {
    __is >> __re >> __c;
    if (__c == ',')
      __is >> __im >> __c;
    if (__c != ')')
      __is.setstate(ios_base::failbit);
  }
  else {
    __is.putback(__c);
    __is >> __re;
  }

  if (__is)
    __z = complex<long double>(__re, __im);
  return __is;
}
#endif

// Force instantiation of complex I/O functions
#if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))

_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);

_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);

#ifndef _STLP_NO_LONG_DOUBLE
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);

_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
#endif

_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);

_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);

#endif /* _STLP_NO_WCHAR_T */

_STLP_END_NAMESPACE


// Local Variables:
// mode:C++
// End: