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