libMesh
ostream_proxy.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
228  std::streampos tellp() { return _target->tellp(); }
229 
230 private:
235 };
236 
238 
239 } // namespace libMesh
240 
241 #endif // LIBMESH_OSTREAM_PROXY_H
libMesh::BasicOStreamProxy::setf
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl)
Set the associated flags.
Definition: ostream_proxy.h:170
libMesh::BasicOStreamProxy::BasicOStreamProxy
BasicOStreamProxy(streamT &target)
Default constructor.
Definition: ostream_proxy.h:62
libMesh::BasicOStreamProxy::unsetf
void unsetf(std::ios_base::fmtflags mask)
Clear the associated flags.
Definition: ostream_proxy.h:183
libMesh::BasicOStreamProxy::rdbuf
streambufT * rdbuf() const
Get the associated stream buffer.
Definition: ostream_proxy.h:143
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::BasicOStreamProxy::~BasicOStreamProxy
~BasicOStreamProxy()
Default destructor.
Definition: ostream_proxy.h:93
libMesh::BasicOStreamProxy::setf
std::ios_base::fmtflags setf(std::ios_base::fmtflags fmtfl, std::ios_base::fmtflags mask)
Set the associated flags.
Definition: ostream_proxy.h:176
libMesh::BasicOStreamProxy::BasicOStreamProxy
BasicOStreamProxy(BasicOStreamProxy &old)
Shallow copy constructor.
Definition: ostream_proxy.h:70
libMesh::BasicOStreamProxy::precision
std::streamsize precision(std::streamsize prec)
Set the associated write precision.
Definition: ostream_proxy.h:195
libMesh::BasicOStreamProxy::operator=
BasicOStreamProxy & operator=(streamT &target)
Reset the internal target to a new target output stream.
Definition: ostream_proxy.h:75
libMesh::BasicOStreamProxy::flush
BasicOStreamProxy & flush()
Flush the associated stream buffer.
Definition: ostream_proxy.h:153
libMesh::BasicOStreamProxy::flags
std::ios_base::fmtflags flags() const
Get the associated format flags.
Definition: ostream_proxy.h:158
libMesh::OStreamProxy
BasicOStreamProxy OStreamProxy
Definition: ostream_proxy.h:237
libMesh::BasicOStreamProxy::_target
streamT * _target
The pointer to the "real" ostream we send everything to.
Definition: ostream_proxy.h:234
libMesh::BasicOStreamProxy::get
streamT * get()
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
Definition: ostream_proxy.h:213
libMesh::BasicOStreamProxy::operator<<
BasicOStreamProxy & operator<<(const T &in)
Redirect any output to the target.
Definition: ostream_proxy.h:115
libMesh::BasicOStreamProxy::flags
std::ios_base::fmtflags flags(std::ios_base::fmtflags fmtfl)
Set/get the associated format flags.
Definition: ostream_proxy.h:164
libMesh::BasicOStreamProxy::tellp
std::streampos tellp()
Returns the position of the character in the current stream.
Definition: ostream_proxy.h:228
libMesh::BasicOStreamProxy
This class is intended to be reseatable like a pointer-to-ostream for flexibility,...
Definition: ostream_proxy.h:42
libMesh::BasicOStreamProxy::get
const streamT * get() const
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
Definition: ostream_proxy.h:221
libMesh::BasicOStreamProxy::streamT
std::basic_ostream< charT, traits > streamT
This class is going to be used to proxy for ostream, but other character and traits types are possibl...
Definition: ostream_proxy.h:49
libMesh::BasicOStreamProxy::reset
void reset(streamT &target)
Reset the proxy to point to a different target.
Definition: ostream_proxy.h:207
libMesh::BasicOStreamProxy::rdbuf
streambufT * rdbuf(streambufT *sb)
Set the associated stream buffer.
Definition: ostream_proxy.h:148
libMesh::BasicOStreamProxy::precision
std::streamsize precision() const
Get the associated write precision.
Definition: ostream_proxy.h:189
libMesh::BasicOStreamProxy::streambufT
std::basic_streambuf< charT, traits > streambufT
This class is going to be used to proxy for ostream, but other character and traits types are possibl...
Definition: ostream_proxy.h:55