/*
 * 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.
 *
 */ 

#ifndef __SGI_STL_IOMANIP
#define __SGI_STL_IOMANIP

# ifndef __STL_OUTERMOST_HEADER_ID
#  define __STL_OUTERMOST_HEADER_ID 0x1030
#  include <stl/_prolog.h>
# endif

# if defined ( __SGI_STL_OWN_IOSTREAMS )

#  if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
#   error This header file requires the -LANG:std option
#  endif

#  include <istream>              // Includes <ostream> and <ios>

__STL_BEGIN_NAMESPACE

//----------------------------------------------------------------------
// Machinery for defining manipulators.

// Class that calls one of ios_base's single-argument member functions.
template <class _Arg>
struct _Ios_Manip_1 {
   typedef _Arg (ios_base::*__f_ptr_type)(_Arg);
 
  _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg)  
    : _M_f(__f), _M_arg(__arg)
    {}
  
  void operator()(ios_base& __ios) const {
    (__ios.*_M_f)(_M_arg);
  }

  __f_ptr_type _M_f;
  _Arg _M_arg;
};

// Class that calls one of ios_base's two-argument member functions.
struct _Ios_Setf_Manip {
  ios_base::fmtflags _M_flag;
  ios_base::fmtflags _M_mask;
  bool _M_two_args;

  _Ios_Setf_Manip(ios_base::fmtflags __f)
    : _M_flag(__f), _M_mask(0), _M_two_args(false)
    {}

  _Ios_Setf_Manip(ios_base::fmtflags __f, ios_base::fmtflags __m)
    : _M_flag(__f), _M_mask(__m), _M_two_args(true)
    {}

  void operator()(ios_base& __ios) const {
    if (_M_two_args)
      __ios.setf(_M_flag, _M_mask);
    else
      __ios.setf(_M_flag);
  }
};


template <class _CharT, class _Traits, class _Arg>
inline basic_istream<_CharT, _Traits>& __STL_CALL
operator>>(basic_istream<_CharT, _Traits>& __in,
           const _Ios_Manip_1<_Arg>& __f)
{
  __f(__in);
  return __in;
}

template <class _CharT, class _Traits, class _Arg>
inline basic_ostream<_CharT, _Traits>& __STL_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os,
           const _Ios_Manip_1<_Arg>& __f)
{
  __f(__os);
  return __os;
}

template <class _CharT, class _Traits>
inline basic_istream<_CharT, _Traits>& __STL_CALL
operator>>(basic_istream<_CharT, _Traits>& __in, const _Ios_Setf_Manip& __f)
{
  __f(__in);
  return __in;
}

template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& __STL_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const _Ios_Setf_Manip& __f)

{
  __f(__os);
  return __os;
}

//----------------------------------------------------------------------
// The ios_base manipulators.

inline _Ios_Setf_Manip  __STL_CALL resetiosflags(ios_base::fmtflags __mask) {
  return _Ios_Setf_Manip(0, __mask);
}

inline _Ios_Setf_Manip __STL_CALL setiosflags(ios_base::fmtflags __flag) {
  return _Ios_Setf_Manip(__flag);
}

inline _Ios_Setf_Manip __STL_CALL setbase(int __n) {
  ios_base::fmtflags __base = __n == 8  ? ios_base::oct :
                              __n == 10 ? ios_base::dec :
                              __n == 16 ? ios_base::hex :
                              ios_base::fmtflags(0);
  return _Ios_Setf_Manip(__base, ios_base::basefield);
}

inline _Ios_Manip_1<streamsize> __STL_CALL 
setprecision(int __n) {
  //*TY 02/24/2000 - mpw compilers have difficulty resolving overloaded function when assigning a pointer to function
#if !(defined(__MRC__) || defined(__SC__))
  _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::precision;
#else
  _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::_PRECISION;
#endif
  return _Ios_Manip_1<streamsize>(__f, __n);
}

inline _Ios_Manip_1<streamsize>  __STL_CALL
setw(int __n) {
#if !(defined(__MRC__) || defined(__SC__))
  _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::width;
#else
  _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::_WIDTH;	
#endif
  return _Ios_Manip_1<streamsize>(__f, __n);
}

//----------------------------------------------------------------------
// setfill, a manipulator that operates on basic_ios<> instead of ios_base.

template <class _CharT>
struct _Setfill_Manip {
  _Setfill_Manip(_CharT __c) : _M_c(__c) {}
  _CharT _M_c;
};

template <class _CharT, class _CharT2, class _Traits>
inline basic_ostream<_CharT, _Traits>& __STL_CALL 
operator<<(basic_ostream<_CharT, _Traits>& __os, 
           const _Setfill_Manip<_CharT2>& __m)
{
  __os.fill(__m._M_c);
  return __os;
}

template <class _CharT>
inline _Setfill_Manip<_CharT> __STL_CALL 
setfill(_CharT __c) {
  return _Setfill_Manip<_CharT>(__c);
}

__STL_END_NAMESPACE

# elif !defined (__STL_USE_NO_IOSTREAMS)
#  include <wrap_std/iomanip>
# endif

# if (__STL_OUTERMOST_HEADER_ID == 0x1030)
#  include <stl/_epilog.h>
#  undef __STL_OUTERMOST_HEADER_ID
# endif

#endif /* __SGI_STL_IOMANIP */

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