ostream_proxy.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 // Local Includes
29 // We don't use anything libMesh-specific here (yet)
30 // #include "libmesh/libmesh_common.h"
31 
32 
33 namespace libMesh
34 {
35 
36 // Forward Declarations
37 
38 
39 
40  // ------------------------------------------------------------
41  // OStreamProxy class definition
42  //
43  // This class is intended to be reseatable like a pointer-to-ostream
44  // for flexibility, but to look like a reference when used to produce
45  // less awkward user code.
46  //
47  // It is up to the user to ensure that the target ostream
48 
49  template <typename charT=char, typename traits=std::char_traits<charT> >
51  {
52  public:
57  typedef std::basic_ostream<charT,traits> streamT;
58 
63  typedef std::basic_streambuf<charT,traits> streambufT;
64 
70  BasicOStreamProxy (streamT& target) : _target(&target) {}
71 
79 
84  {
85  _target = &target;
86  return *this;
87  }
88 
93  {
94  _target = old._target;
95  return *this;
96  }
97 
102 
103  //
104  // Functions that get passed to the proxied target:
105  //
106 
111  operator streamT&() { return *_target; }
112 
117  operator const streamT&() const { return *_target; }
118 
122  template<typename T>
124  (*_target) << in; return *this;
125  }
126 
131  (*_target) << in; return *this;
132  }
133 
137  BasicOStreamProxy& operator<< (std::basic_ios<charT,traits>& (*in)(std::basic_ios<charT,traits>&)) {
138  (*_target) << in; return *this;
139  }
140 
144  BasicOStreamProxy& operator<< (std::ios_base& (*in)(std::ios_base&)) {
145  (*_target) << in; return *this;
146  }
147 
151  streambufT* rdbuf () const { return _target->rdbuf(); }
152 
156  streambufT* rdbuf ( streambufT* sb ) { return _target->rdbuf(sb); }
157 
161  BasicOStreamProxy& flush () { _target->flush(); return *this; }
162 
166  std::ios_base::fmtflags flags ( ) const
167  { return _target->flags(); }
168 
172  std::ios_base::fmtflags flags ( std::ios_base::fmtflags fmtfl )
173  { return _target->flags(fmtfl); }
174 
178  std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl )
179  { return _target->setf(fmtfl); }
180 
184  std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl,
185  std::ios_base::fmtflags mask )
186  { return _target->setf(fmtfl, mask); }
187 
191  void unsetf ( std::ios_base::fmtflags mask )
192  { _target->unsetf(mask); }
193 
197  std::streamsize precision () const
198  { return _target->precision(); }
199 
203  std::streamsize precision ( std::streamsize prec )
204  { return _target->precision(prec); }
205 
206  //
207  // Functions that affect the Proxy class:
208  //
209 
214  void reset (streamT& target) { _target = &target; }
215 
220  streamT* get() {
221  return _target;
222  }
223 
228  const streamT* get() const {
229  return _target;
230  }
231 
232  private:
237  };
238 
240 
241 } // namespace libMesh
242 
243 #endif // LIBMESH_OSTREAM_PROXY_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo