]> git.ipfire.org Git - thirdparty/gcc.git/blob - libio/iomanip.h
Initial revision
[thirdparty/gcc.git] / libio / iomanip.h
1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
3
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)
8 any later version.
9
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.
14
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.
18
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. */
24
25 #ifndef _IOMANIP_H
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29 #define _IOMANIP_H
30
31 #include <iostream.h>
32
33 extern "C++" {
34 //-----------------------------------------------------------------------------
35 // Parametrized Manipulators as specified by ANSI draft
36 //-----------------------------------------------------------------------------
37
38 //-----------------------------------------------------------------------------
39 // Stream Manipulators
40 //-----------------------------------------------------------------------------
41 //
42 template<class TP> class smanip; // TP = Type Param
43
44 template<class TP> class sapp {
45 ios& (*_f)(ios&, TP);
46 public:
47 sapp(ios& (*f)(ios&, TP)) : _f(f) {}
48 //
49 smanip<TP> operator()(TP a)
50 { return smanip<TP>(_f, a); }
51 };
52
53 template <class TP> class smanip {
54 ios& (*_f)(ios&, TP);
55 TP _a;
56 public:
57 smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
58 //
59 friend
60 istream& operator>>(istream& i, const smanip<TP>& m);
61 friend
62 ostream& operator<<(ostream& o, const smanip<TP>& m);
63 };
64
65 #ifdef __GNUG__
66 extern template class smanip<int>;
67 extern template class smanip<ios::fmtflags>;
68 #endif
69
70 template<class TP>
71 inline istream& operator>>(istream& i, const smanip<TP>& m)
72 { (*m._f)(i, m._a); return i; }
73
74 template<class TP>
75 inline ostream& operator<<(ostream& o, const smanip<TP>& m)
76 { (*m._f)(o, m._a); return o;}
77
78 #ifdef __GNUG__
79 extern template istream& operator>>(istream&, const smanip<int>&);
80 extern template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
81 extern template ostream& operator<<(ostream&, const smanip<int>&);
82 extern template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
83 #endif
84
85 //-----------------------------------------------------------------------------
86 // Input-Stream Manipulators
87 //-----------------------------------------------------------------------------
88 //
89 template<class TP> class imanip;
90
91 template<class TP> class iapp {
92 istream& (*_f)(istream&, TP);
93 public:
94 iapp(istream& (*f)(istream&,TP)) : _f(f) {}
95 //
96 imanip<TP> operator()(TP a)
97 { return imanip<TP>(_f, a); }
98 };
99
100 template <class TP> class imanip {
101 istream& (*_f)(istream&, TP);
102 TP _a;
103 public:
104 imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
105 //
106 friend
107 istream& operator>>(istream& i, const imanip<TP>& m);
108 };
109
110 template <class TP>
111 inline istream& operator>>(istream& i, const imanip<TP>& m)
112 { return (*m._f)( i, m._a); }
113
114 //-----------------------------------------------------------------------------
115 // Output-Stream Manipulators
116 //-----------------------------------------------------------------------------
117 //
118 template<class TP> class omanip;
119
120 template<class TP> class oapp {
121 ostream& (*_f)(ostream&, TP);
122 public:
123 oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
124 //
125 omanip<TP> operator()(TP a)
126 { return omanip<TP>(_f, a); }
127 };
128
129 template <class TP> class omanip {
130 ostream& (*_f)(ostream&, TP);
131 TP _a;
132 public:
133 omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
134 //
135 friend
136 ostream& operator<<(ostream& o, const omanip<TP>& m);
137 };
138
139 template <class TP>
140 inline ostream& operator<<(ostream& o, const omanip<TP>& m)
141 { return (*m._f)(o, m._a); }
142
143 //-----------------------------------------------------------------------------
144 // Available Manipulators
145 //-----------------------------------------------------------------------------
146
147 //
148 // Macro to define an iomanip function, with one argument
149 // The underlying function is `__iomanip_<name>'
150 //
151 #define __DEFINE_IOMANIP_FN1(type,param,function) \
152 extern ios& __iomanip_##function (ios&, param); \
153 inline type<param> function (param n) \
154 { return type<param> (__iomanip_##function, n); }
155
156 __DEFINE_IOMANIP_FN1( smanip, int, setbase)
157 __DEFINE_IOMANIP_FN1( smanip, int, setfill)
158 __DEFINE_IOMANIP_FN1( smanip, int, setprecision)
159 __DEFINE_IOMANIP_FN1( smanip, int, setw)
160
161 __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
162 __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
163 } // extern "C++"
164
165 #endif /*!_IOMANIP_H*/