1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
34 //-----------------------------------------------------------------------------
35 // Parametrized Manipulators as specified by ANSI draft
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 // Stream Manipulators
40 //-----------------------------------------------------------------------------
42 template<class TP
> class smanip
; // TP = Type Param
44 template<class TP
> class sapp
{
47 sapp(ios
& (*f
)(ios
&, TP
)) : _f(f
) {}
49 smanip
<TP
> operator()(TP a
)
50 { return smanip
<TP
>(_f
, a
); }
54 inline istream
& operator>>(istream
& i
, const smanip
<TP
>& m
);
56 inline ostream
& operator<<(ostream
& o
, const smanip
<TP
>& m
);
58 template <class TP
> class smanip
{
62 smanip(ios
& (*f
)(ios
&, TP
), TP a
) : _f(f
), _a(a
) {}
65 istream
& operator>> <>(istream
& i
, const smanip
<TP
>& m
);
67 ostream
& operator<< <>(ostream
& o
, const smanip
<TP
>& m
);
71 __extension__
extern template class smanip
<int>;
72 __extension__
extern template class smanip
<ios::fmtflags
>;
76 inline istream
& operator>>(istream
& i
, const smanip
<TP
>& m
)
77 { (*m
._f
)(i
, m
._a
); return i
; }
80 inline ostream
& operator<<(ostream
& o
, const smanip
<TP
>& m
)
81 { (*m
._f
)(o
, m
._a
); return o
;}
85 template istream
& operator>>(istream
&, const smanip
<int>&);
87 template istream
& operator>>(istream
&, const smanip
<ios::fmtflags
>&);
89 template ostream
& operator<<(ostream
&, const smanip
<int>&);
91 template ostream
& operator<<(ostream
&, const smanip
<ios::fmtflags
>&);
94 //-----------------------------------------------------------------------------
95 // Input-Stream Manipulators
96 //-----------------------------------------------------------------------------
98 template<class TP
> class imanip
;
100 template<class TP
> class iapp
{
101 istream
& (*_f
)(istream
&, TP
);
103 iapp(istream
& (*f
)(istream
&,TP
)) : _f(f
) {}
105 imanip
<TP
> operator()(TP a
)
106 { return imanip
<TP
>(_f
, a
); }
110 inline istream
& operator>>(istream
&, const imanip
<TP
>&);
112 template <class TP
> class imanip
{
113 istream
& (*_f
)(istream
&, TP
);
116 imanip(istream
& (*f
)(istream
&, TP
), TP a
) : _f(f
), _a(a
) {}
119 istream
& operator>> <>(istream
& i
, const imanip
<TP
>& m
);
123 inline istream
& operator>>(istream
& i
, const imanip
<TP
>& m
)
124 { return (*m
._f
)( i
, m
._a
); }
126 //-----------------------------------------------------------------------------
127 // Output-Stream Manipulators
128 //-----------------------------------------------------------------------------
130 template<class TP
> class omanip
;
132 template<class TP
> class oapp
{
133 ostream
& (*_f
)(ostream
&, TP
);
135 oapp(ostream
& (*f
)(ostream
&,TP
)) : _f(f
) {}
137 omanip
<TP
> operator()(TP a
)
138 { return omanip
<TP
>(_f
, a
); }
142 inline ostream
& operator<<(ostream
&, const omanip
<TP
>&);
144 template <class TP
> class omanip
{
145 ostream
& (*_f
)(ostream
&, TP
);
148 omanip(ostream
& (*f
)(ostream
&, TP
), TP a
) : _f(f
), _a(a
) {}
151 ostream
& operator<< <>(ostream
& o
, const omanip
<TP
>& m
);
155 inline ostream
& operator<<(ostream
& o
, const omanip
<TP
>& m
)
156 { return (*m
._f
)(o
, m
._a
); }
158 //-----------------------------------------------------------------------------
159 // Available Manipulators
160 //-----------------------------------------------------------------------------
163 // Macro to define an iomanip function, with one argument
164 // The underlying function is `__iomanip_<name>'
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); }
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
)
176 __DEFINE_IOMANIP_FN1( smanip
, ios::fmtflags
, resetiosflags
)
177 __DEFINE_IOMANIP_FN1( smanip
, ios::fmtflags
, setiosflags
)
180 #endif /*!_IOMANIP_H*/