$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_OSTREAM_PROXY_H 00021 #define LIBMESH_OSTREAM_PROXY_H 00022 00023 00024 00025 // C++ includes 00026 #include <iostream> 00027 00028 // Local Includes 00029 // We don't use anything libMesh-specific here (yet) 00030 // #include "libmesh/libmesh_common.h" 00031 00032 00033 namespace libMesh 00034 { 00035 00036 // Forward Declarations 00037 00038 00039 00040 // ------------------------------------------------------------ 00041 // OStreamProxy class definition 00042 // 00043 // This class is intended to be reseatable like a pointer-to-ostream 00044 // for flexibility, but to look like a reference when used to produce 00045 // less awkward user code. 00046 // 00047 // It is up to the user to ensure that the target ostream 00048 00049 template <typename charT=char, typename traits=std::char_traits<charT> > 00050 class BasicOStreamProxy 00051 { 00052 public: 00057 typedef std::basic_ostream<charT,traits> streamT; 00058 00063 typedef std::basic_streambuf<charT,traits> streambufT; 00064 00070 BasicOStreamProxy (streamT& target) : _target(&target) {} 00071 00078 BasicOStreamProxy (BasicOStreamProxy& old) : _target(old._target) {} 00079 00083 BasicOStreamProxy& operator= (streamT& target) 00084 { 00085 _target = ⌖ 00086 return *this; 00087 } 00088 00092 BasicOStreamProxy& operator= (const BasicOStreamProxy& old) 00093 { 00094 _target = old._target; 00095 return *this; 00096 } 00097 00101 ~BasicOStreamProxy () {} 00102 00103 // 00104 // Functions that get passed to the proxied target: 00105 // 00106 00111 operator streamT&() { return *_target; } 00112 00117 operator const streamT&() const { return *_target; } 00118 00122 template<typename T> 00123 BasicOStreamProxy& operator<< (const T& in) { 00124 (*_target) << in; return *this; 00125 } 00126 00130 BasicOStreamProxy& operator<< (streamT& (*in)(streamT&)) { 00131 (*_target) << in; return *this; 00132 } 00133 00137 BasicOStreamProxy& operator<< (std::basic_ios<charT,traits>& (*in)(std::basic_ios<charT,traits>&)) { 00138 (*_target) << in; return *this; 00139 } 00140 00144 BasicOStreamProxy& operator<< (std::ios_base& (*in)(std::ios_base&)) { 00145 (*_target) << in; return *this; 00146 } 00147 00151 streambufT* rdbuf () const { return _target->rdbuf(); } 00152 00156 streambufT* rdbuf ( streambufT* sb ) { return _target->rdbuf(sb); } 00157 00161 BasicOStreamProxy& flush () { _target->flush(); return *this; } 00162 00166 std::ios_base::fmtflags flags ( ) const 00167 { return _target->flags(); } 00168 00172 std::ios_base::fmtflags flags ( std::ios_base::fmtflags fmtfl ) 00173 { return _target->flags(fmtfl); } 00174 00178 std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl ) 00179 { return _target->setf(fmtfl); } 00180 00184 std::ios_base::fmtflags setf ( std::ios_base::fmtflags fmtfl, 00185 std::ios_base::fmtflags mask ) 00186 { return _target->setf(fmtfl, mask); } 00187 00191 void unsetf ( std::ios_base::fmtflags mask ) 00192 { _target->unsetf(mask); } 00193 00197 std::streamsize precision () const 00198 { return _target->precision(); } 00199 00203 std::streamsize precision ( std::streamsize prec ) 00204 { return _target->precision(prec); } 00205 00206 // 00207 // Functions that affect the Proxy class: 00208 // 00209 00214 void reset (streamT& target) { _target = ⌖ } 00215 00220 streamT* get() { 00221 return _target; 00222 } 00223 00228 const streamT* get() const { 00229 return _target; 00230 } 00231 00232 private: 00236 streamT* _target; 00237 }; 00238 00239 typedef BasicOStreamProxy<> OStreamProxy; 00240 00241 } // namespace libMesh 00242 00243 #endif // LIBMESH_OSTREAM_PROXY_H