19720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block/*
29720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Copyright (c) 1999
39720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Silicon Graphics Computer Systems, Inc.
49720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block *
59720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Copyright (c) 1999
69720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Boris Fomitchev
79720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block *
89720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * This material is provided "as is", with absolutely no warranty expressed
99720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * or implied. Any use is at your own risk.
109720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block *
119720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Permission to use or copy this software for any purpose is hereby granted
129720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * without fee, provided the above notices are retained on all copies.
139720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * Permission to modify the code and to distribute modified code is granted,
149720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * provided the above notices are retained, and a notice that the code was
159720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block * modified is included with the above copyright notice.
169720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block *
179720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block */
189720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
19e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#ifndef _STLP_INTERNAL_IOMANIP
20e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#define _STLP_INTERNAL_IOMANIP
219720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
22e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#ifndef _STLP_INTERNAL_ISTREAM
23e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#  include <stl/_istream.h>              // Includes <ostream> and <ios>
249720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block#endif
259720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
269720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block_STLP_BEGIN_NAMESPACE
279720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
28e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott_STLP_MOVE_TO_PRIV_NAMESPACE
29e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott
309720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block//----------------------------------------------------------------------
319720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block// Machinery for defining manipulators.
329720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
339720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block// Class that calls one of ios_base's single-argument member functions.
349720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _Arg>
359720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockstruct _Ios_Manip_1 {
369720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block   typedef _Arg (ios_base::*__f_ptr_type)(_Arg);
379720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
389720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg)
399720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block    : _M_f(__f), _M_arg(__arg) {}
409720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
419720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  void operator()(ios_base& __ios) const
429720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  { (__ios.*_M_f)(_M_arg); }
439720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
449720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __f_ptr_type _M_f;
459720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _Arg _M_arg;
469720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block};
479720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
489720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block// Class that calls one of ios_base's two-argument member functions.
499720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockstruct _Ios_Setf_Manip {
509720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  ios_base::fmtflags _M_flag;
519720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  ios_base::fmtflags _M_mask;
529720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  bool _M_two_args;
539720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
549720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _Ios_Setf_Manip(ios_base::fmtflags __f)
559720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block    : _M_flag(__f), _M_mask(0), _M_two_args(false) {}
569720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
579720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _Ios_Setf_Manip(ios_base::fmtflags __f, ios_base::fmtflags __m)
589720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block    : _M_flag(__f), _M_mask(__m), _M_two_args(true) {}
599720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
609720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  void operator()(ios_base& __ios) const {
619720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block    if (_M_two_args)
629720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block      __ios.setf(_M_flag, _M_mask);
639720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block    else
649720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block      __ios.setf(_M_flag);
659720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  }
669720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block};
679720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
68e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott_STLP_MOVE_TO_STD_NAMESPACE
699720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
709720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _Traits, class _Arg>
719720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_istream<_CharT, _Traits>& _STLP_CALL
729720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockoperator>>(basic_istream<_CharT, _Traits>& __istr,
73e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Ios_Manip_1<_Arg>& __f) {
749720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __f(__istr);
759720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __istr;
769720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
779720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
789720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _Traits, class _Arg>
799720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_ostream<_CharT, _Traits>& _STLP_CALL
809720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockoperator<<(basic_ostream<_CharT, _Traits>& __os,
81e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Ios_Manip_1<_Arg>& __f) {
829720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __f(__os);
839720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __os;
849720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
859720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
869720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _Traits>
879720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_istream<_CharT, _Traits>& _STLP_CALL
88e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottoperator>>(basic_istream<_CharT, _Traits>& __istr,
89e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Ios_Setf_Manip& __f) {
909720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __f(__istr);
919720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __istr;
929720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
939720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
949720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _Traits>
959720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_ostream<_CharT, _Traits>& _STLP_CALL
96e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottoperator<<(basic_ostream<_CharT, _Traits>& __os,
97e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Ios_Setf_Manip& __f) {
989720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __f(__os);
999720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __os;
1009720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1019720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
1029720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block//----------------------------------------------------------------------
1039720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block// The ios_base manipulators.
104e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL resetiosflags(ios_base::fmtflags __mask)
105e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ return _STLP_PRIV _Ios_Setf_Manip(0, __mask); }
1069720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
107e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag)
108e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ return _STLP_PRIV _Ios_Setf_Manip(__flag); }
1099720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
110e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL setbase(int __n) {
1119720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  ios_base::fmtflags __base = __n == 8  ? ios_base::oct :
1129720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block                              __n == 10 ? ios_base::dec :
1139720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block                              __n == 16 ? ios_base::hex :
1149720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block                              ios_base::fmtflags(0);
115e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott  return _STLP_PRIV _Ios_Setf_Manip(__base, ios_base::basefield);
1169720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1179720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
118e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Ios_Manip_1<streamsize> _STLP_CALL
1199720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocksetprecision(int __n) {
120e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott  _STLP_PRIV _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::precision;
121e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott  return _STLP_PRIV _Ios_Manip_1<streamsize>(__f, __n);
1229720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1239720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
124e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Ios_Manip_1<streamsize>  _STLP_CALL
1259720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocksetw(int __n) {
126e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott  _STLP_PRIV _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::width;
127e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott  return _STLP_PRIV _Ios_Manip_1<streamsize>(__f, __n);
1289720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1299720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
1309720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block//----------------------------------------------------------------------
1319720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block// setfill, a manipulator that operates on basic_ios<> instead of ios_base.
1329720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
133e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott_STLP_MOVE_TO_PRIV_NAMESPACE
134e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott
1359720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT>
1369720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockstruct _Setfill_Manip {
1379720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _Setfill_Manip(_CharT __c) : _M_c(__c) {}
1389720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  _CharT _M_c;
1399720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block};
1409720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
141e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott_STLP_MOVE_TO_STD_NAMESPACE
142e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott
1439720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _CharT2, class _Traits>
1449720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_ostream<_CharT, _Traits>& _STLP_CALL
1459720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockoperator<<(basic_ostream<_CharT, _Traits>& __os,
146e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Setfill_Manip<_CharT2>& __m) {
1479720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __os.fill(__m._M_c);
1489720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __os;
1499720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1509720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
1519720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT, class _CharT2, class _Traits>
1529720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockinline basic_istream<_CharT, _Traits>& _STLP_CALL
1539720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blockoperator>>(basic_istream<_CharT, _Traits>& __is,
154e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott           const _STLP_PRIV _Setfill_Manip<_CharT2>& __m) {
1559720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  __is.fill(__m._M_c);
1569720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block  return __is;
1579720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block}
1589720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
1599720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Blocktemplate <class _CharT>
160e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottinline _STLP_PRIV _Setfill_Manip<_CharT> _STLP_CALL setfill(_CharT __c)
161e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott{ return _STLP_PRIV _Setfill_Manip<_CharT>(__c); }
1629720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
1639720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block_STLP_END_NAMESPACE
1649720d5f59b9c1f5d1b9ecbc9173dbcb71bd557beSteve Block
165e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#endif /* _STLP_INTERNAL_IOMANIP */
166