os/ossrv/genericopenlibs/cppstdlib/stl/src/complex_io.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * Copyright (c) 1999
sl@0
     3
 * Silicon Graphics Computer Systems, Inc.
sl@0
     4
 *
sl@0
     5
 * Copyright (c) 1999
sl@0
     6
 * Boris Fomitchev
sl@0
     7
 *
sl@0
     8
 * This material is provided "as is", with absolutely no warranty expressed
sl@0
     9
 * or implied. Any use is at your own risk.
sl@0
    10
 *
sl@0
    11
 * Permission to use or copy this software for any purpose is hereby granted
sl@0
    12
 * without fee, provided the above notices are retained on all copies.
sl@0
    13
 * Permission to modify the code and to distribute modified code is granted,
sl@0
    14
 * provided the above notices are retained, and a notice that the code was
sl@0
    15
 * modified is included with the above copyright notice.
sl@0
    16
 *
sl@0
    17
 */
sl@0
    18
sl@0
    19
#include "stlport_prefix.h"
sl@0
    20
sl@0
    21
#include <complex>
sl@0
    22
#include <istream>
sl@0
    23
sl@0
    24
_STLP_BEGIN_NAMESPACE
sl@0
    25
sl@0
    26
#if !(defined (_STLP_MSVC) && _STLP_MSVC < 1200)
sl@0
    27
sl@0
    28
// Specializations for narrow characters; lets us avoid the nuisance of
sl@0
    29
// widening.
sl@0
    30
_STLP_OPERATOR_SPEC
sl@0
    31
basic_ostream<char, char_traits<char> >& _STLP_CALL
sl@0
    32
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<float>& __z)
sl@0
    33
{ return __os << '(' << (double)__z.real() << ',' << (double)__z.imag() << ')'; }
sl@0
    34
sl@0
    35
_STLP_OPERATOR_SPEC
sl@0
    36
basic_ostream<char, char_traits<char> >& _STLP_CALL
sl@0
    37
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<double>& __z)
sl@0
    38
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
sl@0
    39
sl@0
    40
#  ifndef _STLP_NO_LONG_DOUBLE
sl@0
    41
_STLP_OPERATOR_SPEC
sl@0
    42
basic_ostream<char, char_traits<char> >& _STLP_CALL
sl@0
    43
operator<< (basic_ostream<char, char_traits<char> >& __os, const complex<long double>& __z)
sl@0
    44
{ return __os << '(' << __z.real() << ',' << __z.imag() << ')'; }
sl@0
    45
#  endif
sl@0
    46
sl@0
    47
// Specialization for narrow characters; lets us avoid widen.
sl@0
    48
_STLP_OPERATOR_SPEC
sl@0
    49
basic_istream<char, char_traits<char> >& _STLP_CALL
sl@0
    50
operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z) {
sl@0
    51
  float  __re = 0;
sl@0
    52
  float  __im = 0;
sl@0
    53
sl@0
    54
  char __c;
sl@0
    55
sl@0
    56
  __is >> __c;
sl@0
    57
  if (__c == '(') {
sl@0
    58
    __is >> __re >> __c;
sl@0
    59
    if (__c == ',')
sl@0
    60
      __is >> __im >> __c;
sl@0
    61
    if (__c != ')')
sl@0
    62
      __is.setstate(ios_base::failbit);
sl@0
    63
  }
sl@0
    64
  else {
sl@0
    65
    __is.putback(__c);
sl@0
    66
    __is >> __re;
sl@0
    67
  }
sl@0
    68
sl@0
    69
  if (__is)
sl@0
    70
    __z = complex<float>(__re, __im);
sl@0
    71
  return __is;
sl@0
    72
}
sl@0
    73
sl@0
    74
_STLP_OPERATOR_SPEC
sl@0
    75
basic_istream<char, char_traits<char> >& _STLP_CALL
sl@0
    76
operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z) {
sl@0
    77
  double  __re = 0;
sl@0
    78
  double  __im = 0;
sl@0
    79
sl@0
    80
  char __c;
sl@0
    81
sl@0
    82
  __is >> __c;
sl@0
    83
  if (__c == '(') {
sl@0
    84
    __is >> __re >> __c;
sl@0
    85
    if (__c == ',')
sl@0
    86
      __is >> __im >> __c;
sl@0
    87
    if (__c != ')')
sl@0
    88
      __is.setstate(ios_base::failbit);
sl@0
    89
  }
sl@0
    90
  else {
sl@0
    91
    __is.putback(__c);
sl@0
    92
    __is >> __re;
sl@0
    93
  }
sl@0
    94
sl@0
    95
  if (__is)
sl@0
    96
    __z = complex<double>(__re, __im);
sl@0
    97
  return __is;
sl@0
    98
}
sl@0
    99
sl@0
   100
#  ifndef _STLP_NO_LONG_DOUBLE
sl@0
   101
_STLP_OPERATOR_SPEC
sl@0
   102
basic_istream<char, char_traits<char> >& _STLP_CALL
sl@0
   103
operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z) {
sl@0
   104
  long double  __re = 0;
sl@0
   105
  long double  __im = 0;
sl@0
   106
sl@0
   107
  char __c;
sl@0
   108
sl@0
   109
  __is >> __c;
sl@0
   110
  if (__c == '(') {
sl@0
   111
    __is >> __re >> __c;
sl@0
   112
    if (__c == ',')
sl@0
   113
      __is >> __im >> __c;
sl@0
   114
    if (__c != ')')
sl@0
   115
      __is.setstate(ios_base::failbit);
sl@0
   116
  }
sl@0
   117
  else {
sl@0
   118
    __is.putback(__c);
sl@0
   119
    __is >> __re;
sl@0
   120
  }
sl@0
   121
sl@0
   122
  if (__is)
sl@0
   123
    __z = complex<long double>(__re, __im);
sl@0
   124
  return __is;
sl@0
   125
}
sl@0
   126
#  endif
sl@0
   127
sl@0
   128
#endif /* MSVC */
sl@0
   129
sl@0
   130
// Force instantiation of complex I/O functions
sl@0
   131
#if !(defined (_STLP_NO_FORCE_INSTANTIATE) || defined (_STLP_NO_WCHAR_T))
sl@0
   132
sl@0
   133
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   134
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
sl@0
   135
sl@0
   136
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   137
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
sl@0
   138
sl@0
   139
#ifndef _STLP_NO_LONG_DOUBLE
sl@0
   140
_STLP_OPERATOR_SPEC basic_istream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   141
operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
sl@0
   142
sl@0
   143
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   144
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
sl@0
   145
#endif
sl@0
   146
sl@0
   147
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   148
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
sl@0
   149
sl@0
   150
_STLP_OPERATOR_SPEC basic_ostream<wchar_t, char_traits<wchar_t> >&  _STLP_CALL
sl@0
   151
operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
sl@0
   152
sl@0
   153
#endif /* _STLP_NO_WCHAR_T */
sl@0
   154
sl@0
   155
_STLP_END_NAMESPACE
sl@0
   156
sl@0
   157
sl@0
   158
// Local Variables:
sl@0
   159
// mode:C++
sl@0
   160
// End:
sl@0
   161