OSDN Git Service

* configure.in: For *-*-cygwin32*, add a -I for winsup to both
[pf3gnuchains/gcc-fork.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>
54 inline istream& operator>>(istream& i, const smanip<TP>& m);
55 template<class TP>
56 inline ostream& operator<<(ostream& o, const smanip<TP>& m);
57
58 template <class TP> class smanip {
59     ios& (*_f)(ios&, TP);
60     TP _a;
61 public:
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 extern template class smanip<int>;
72 extern template class smanip<ios::fmtflags>;
73 #endif
74
75 template<class TP>
76 inline istream& operator>>(istream& i, const smanip<TP>& m)
77 { (*m._f)(i, m._a); return i; }
78
79 template<class TP>
80 inline ostream& operator<<(ostream& o, const smanip<TP>& m)
81 { (*m._f)(o, m._a); return o;}
82
83 #ifdef __GNUG__
84 extern template istream& operator>>(istream&, const smanip<int>&);
85 extern template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
86 extern template ostream& operator<<(ostream&, const smanip<int>&);
87 extern template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
88 #endif
89
90 //-----------------------------------------------------------------------------
91 //      Input-Stream Manipulators
92 //-----------------------------------------------------------------------------
93 //
94 template<class TP> class imanip; 
95
96 template<class TP> class iapp {
97     istream& (*_f)(istream&, TP);
98 public: 
99     iapp(istream& (*f)(istream&,TP)) : _f(f) {}
100     //
101     imanip<TP> operator()(TP a)
102        { return imanip<TP>(_f, a); }
103 };
104
105 template <class TP>
106 inline istream& operator>>(istream&, const imanip<TP>&);
107
108 template <class TP> class imanip {
109     istream& (*_f)(istream&, TP);
110     TP _a;
111 public:
112     imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
113     //
114     friend
115       istream& operator>> <>(istream& i, const imanip<TP>& m);
116 };
117
118 template <class TP>
119 inline istream& operator>>(istream& i, const imanip<TP>& m)
120 { return (*m._f)( i, m._a); }
121
122 //-----------------------------------------------------------------------------
123 //      Output-Stream Manipulators
124 //-----------------------------------------------------------------------------
125 //
126 template<class TP> class omanip; 
127
128 template<class TP> class oapp {
129     ostream& (*_f)(ostream&, TP);
130 public: 
131     oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
132     //
133     omanip<TP> operator()(TP a)
134       { return omanip<TP>(_f, a); }
135 };
136
137 template <class TP>
138 inline ostream& operator<<(ostream&, const omanip<TP>&);
139
140 template <class TP> class omanip {
141     ostream& (*_f)(ostream&, TP);
142     TP _a;
143 public:
144     omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
145     //
146     friend
147       ostream& operator<< <>(ostream& o, const omanip<TP>& m);
148 };
149
150 template <class TP>
151 inline ostream& operator<<(ostream& o, const omanip<TP>& m)
152 { return (*m._f)(o, m._a); }
153
154 //-----------------------------------------------------------------------------
155 //      Available Manipulators
156 //-----------------------------------------------------------------------------
157
158 //
159 // Macro to define an iomanip function, with one argument
160 // The underlying function is `__iomanip_<name>' 
161 //
162 #define __DEFINE_IOMANIP_FN1(type,param,function)         \
163         extern ios& __iomanip_##function (ios&, param); \
164         inline type<param> function (param n)           \
165                         { return type<param> (__iomanip_##function, n); }
166
167 __DEFINE_IOMANIP_FN1( smanip, int, setbase)
168 __DEFINE_IOMANIP_FN1( smanip, int, setfill)
169 __DEFINE_IOMANIP_FN1( smanip, int, setprecision)
170 __DEFINE_IOMANIP_FN1( smanip, int, setw)
171
172 __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
173 __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
174 } // extern "C++"
175
176 #endif /*!_IOMANIP_H*/