ostream_proxy.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_OSTREAM_PROXY_H
21 #define LIBMESH_OSTREAM_PROXY_H
22 
23 
24 
25 // C++ includes
26 #include <iostream>
27 
28 namespace libMesh
29 {
30 
41 template <typename charT=char, typename traits=std::char_traits<charT> >
43 {
44 public:
49  typedef std::basic_ostream<charT,traits> streamT;
50 
55  typedef std::basic_streambuf<charT,traits> streambufT;
56 
62  BasicOStreamProxy (streamT & target) : _target(&target) {}
63 
71 
75  BasicOStreamProxy & operator= (streamT & target)
76  {
77  _target = &target;
78  return *this;
79  }
80 
85  {
86  _target = old._target;
87  return *this;
88  }
89 
94 
95  //
96  // Functions that get passed to the proxied target:
97  //
98 
103  operator streamT & () { return *_target; }
104 
109  operator const streamT &() const { return *_target; }
110 
114  template<typename T>
115  BasicOStreamProxy & operator<< (const T & in) {
116  (*_target) << in; return *this;
117  }
118 
122  BasicOStreamProxy & operator<< (streamT & (*in)(streamT &)) {
123  (*_target) << in; return *this;
124  }
125 
129  BasicOStreamProxy & operator<< (std::basic_ios<charT,traits> & (*in)(std::basic_ios<charT,traits> &)) {
130  (*_target) << in; return *this;
131  }
132 
136  BasicOStreamProxy & operator<< (std::ios_base & (*in)(std::ios_base &)) {
137  (*_target) << in; return *this;
138  }
139 
143  streambufT * rdbuf () const { return _target->rdbuf(); }
144 
148  streambufT * rdbuf ( streambufT * sb ) { return _target->rdbuf(sb); }
149 
153  BasicOStreamProxy & flush () { _target->flush(); return *this; }
154 
158  std::ios_base::fmtflags flags ( ) const
159  { return _target->flags(); }
160 
164  std::ios_base::fmtflags flags ( std::ios_base::fmtflags fmtfl )
165  { return _target->flags(fmtfl); }
166 
170  std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl )
171  { return _target->setf(fmtfl); }
172 
176  std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl,
177  std::ios_base::fmtflags mask )
178  { return _target->setf(fmtfl, mask); }
179 
183  void unsetf ( std::ios_base::fmtflags mask )
184  { _target->unsetf(mask); }
185 
189  std::streamsize precision () const
190  { return _target->precision(); }
191 
195  std::streamsize precision ( std::streamsize prec )
196  { return _target->precision(prec); }
197 
198  //
199  // Functions that affect the Proxy class:
200  //
201 
206  void reset (streamT & target) { _target = &target; }
207 
212  streamT * get() {
213  return _target;
214  }
215 
220  const streamT * get() const {
221  return _target;
222  }
223 
224 private:
228  streamT * _target;
229 };
230 
232 
233 } // namespace libMesh
234 
235 #endif // LIBMESH_OSTREAM_PROXY_H
std::ios_base::fmtflags flags(std::ios_base::fmtflags fmtfl)
BasicOStreamProxy & operator<<(const T &in)
std::basic_ostream< charT, traits > streamT
Definition: ostream_proxy.h:49
streambufT * rdbuf() const
void reset(streamT &target)
streambufT * rdbuf(streambufT *sb)
std::basic_streambuf< charT, traits > streambufT
Definition: ostream_proxy.h:55
BasicOStreamProxy OStreamProxy
void unsetf(std::ios_base::fmtflags mask)
BasicOStreamProxy(streamT &target)
Definition: ostream_proxy.h:62
BasicOStreamProxy & flush()
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl)
std::ios_base::fmtflags flags() const
BasicOStreamProxy(BasicOStreamProxy &old)
Definition: ostream_proxy.h:70
std::streamsize precision(std::streamsize prec)
std::streamsize precision() const
BasicOStreamProxy & operator=(streamT &target)
Definition: ostream_proxy.h:75
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl, std::ios_base::fmtflags mask)