1/* This is part of libio/iostream, providing -*- C++ -*- input/output. 2Copyright (C) 1993 Free Software Foundation 3 4This file is part of the GNU IO Library. This library is free 5software; you can redistribute it and/or modify it under the 6terms of the GNU General Public License as published by the 7Free Software Foundation; either version 2, or (at your option) 8any later version. 9 10This library is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this library; see the file COPYING. If not, write to the Free 17Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19As a special exception, if you link this library with files 20compiled with a GNU compiler to produce an executable, this does not cause 21the resulting executable to be covered by the GNU General Public License. 22This exception does not however invalidate any other reasons why 23the executable file might be covered by the GNU General Public License. */ 24 25#ifndef _IOMANIP_H 26#ifdef __GNUG__ 27#pragma interface 28#endif 29#define _IOMANIP_H 30 31#include <iostream.h> 32 33extern "C++" { 34//----------------------------------------------------------------------------- 35// Parametrized Manipulators as specified by ANSI draft 36//----------------------------------------------------------------------------- 37 38//----------------------------------------------------------------------------- 39// Stream Manipulators 40//----------------------------------------------------------------------------- 41// 42template<class TP> class smanip; // TP = Type Param 43 44template<class TP> class sapp { 45 ios& (*_f)(ios&, TP); 46public: 47 sapp(ios& (*f)(ios&, TP)) : _f(f) {} 48 // 49 smanip<TP> operator()(TP a) 50 { return smanip<TP>(_f, a); } 51}; 52 53template<class TP> 54inline istream& operator>>(istream& i, const smanip<TP>& m); 55template<class TP> 56inline ostream& operator<<(ostream& o, const smanip<TP>& m); 57 58template <class TP> class smanip { 59 ios& (*_f)(ios&, TP); 60 TP _a; 61public: 62 smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {} 63 // 64 friend 65 istream& operator>> <>(istream& i, const smanip<TP>& m); 66 friend 67 ostream& operator<< <>(ostream& o, const smanip<TP>& m); 68}; 69 70#ifdef __GNUG__ 71__extension__ extern template class smanip<int>; 72__extension__ extern template class smanip<ios::fmtflags>; 73#endif 74 75template<class TP> 76inline istream& operator>>(istream& i, const smanip<TP>& m) 77{ (*m._f)(i, m._a); return i; } 78 79template<class TP> 80inline ostream& operator<<(ostream& o, const smanip<TP>& m) 81{ (*m._f)(o, m._a); return o;} 82 83#ifdef __GNUG__ 84__extension__ extern 85template istream& operator>>(istream&, const smanip<int>&); 86__extension__ extern 87template istream& operator>>(istream&, const smanip<ios::fmtflags>&); 88__extension__ extern 89template ostream& operator<<(ostream&, const smanip<int>&); 90__extension__ extern 91template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&); 92#endif 93 94//----------------------------------------------------------------------------- 95// Input-Stream Manipulators 96//----------------------------------------------------------------------------- 97// 98template<class TP> class imanip; 99 100template<class TP> class iapp { 101 istream& (*_f)(istream&, TP); 102public: 103 iapp(istream& (*f)(istream&,TP)) : _f(f) {} 104 // 105 imanip<TP> operator()(TP a) 106 { return imanip<TP>(_f, a); } 107}; 108 109template <class TP> 110inline istream& operator>>(istream&, const imanip<TP>&); 111 112template <class TP> class imanip { 113 istream& (*_f)(istream&, TP); 114 TP _a; 115public: 116 imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {} 117 // 118 friend 119 istream& operator>> <>(istream& i, const imanip<TP>& m); 120}; 121 122template <class TP> 123inline istream& operator>>(istream& i, const imanip<TP>& m) 124{ return (*m._f)( i, m._a); } 125 126//----------------------------------------------------------------------------- 127// Output-Stream Manipulators 128//----------------------------------------------------------------------------- 129// 130template<class TP> class omanip; 131 132template<class TP> class oapp { 133 ostream& (*_f)(ostream&, TP); 134public: 135 oapp(ostream& (*f)(ostream&,TP)) : _f(f) {} 136 // 137 omanip<TP> operator()(TP a) 138 { return omanip<TP>(_f, a); } 139}; 140 141template <class TP> 142inline ostream& operator<<(ostream&, const omanip<TP>&); 143 144template <class TP> class omanip { 145 ostream& (*_f)(ostream&, TP); 146 TP _a; 147public: 148 omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {} 149 // 150 friend 151 ostream& operator<< <>(ostream& o, const omanip<TP>& m); 152}; 153 154template <class TP> 155inline ostream& operator<<(ostream& o, const omanip<TP>& m) 156{ return (*m._f)(o, m._a); } 157 158//----------------------------------------------------------------------------- 159// Available Manipulators 160//----------------------------------------------------------------------------- 161 162// 163// Macro to define an iomanip function, with one argument 164// The underlying function is `__iomanip_<name>' 165// 166#define __DEFINE_IOMANIP_FN1(type,param,function) \ 167 extern ios& __iomanip_##function (ios&, param); \ 168 inline type<param> function (param n) \ 169 { return type<param> (__iomanip_##function, n); } 170 171__DEFINE_IOMANIP_FN1( smanip, int, setbase) 172__DEFINE_IOMANIP_FN1( smanip, int, setfill) 173__DEFINE_IOMANIP_FN1( smanip, int, setprecision) 174__DEFINE_IOMANIP_FN1( smanip, int, setw) 175 176__DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags) 177__DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags) 178} // extern "C++" 179 180#endif /*!_IOMANIP_H*/ 181