ostream_proxy.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 
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 
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 
207  void reset (streamT & target) { _target = &target; }
208 
213  streamT * get() {
214  return _target;
215  }
216 
221  const streamT * get() const {
222  return _target;
223  }
224 
225 private:
230 };
231 
233 
234 } // namespace libMesh
235 
236 #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
std::streamsize precision() 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)
streambufT * rdbuf() const
BasicOStreamProxy(streamT &target)
Definition: ostream_proxy.h:62
BasicOStreamProxy & flush()
std::ios_base::fmtflags flags() const
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl)
BasicOStreamProxy(BasicOStreamProxy &old)
Definition: ostream_proxy.h:70
std::streamsize precision(std::streamsize prec)
BasicOStreamProxy & operator=(streamT &target)
Definition: ostream_proxy.h:75
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl, std::ios_base::fmtflags mask)