Writer.cpp

00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #include <cstdlib>
00010 #include <cstring>
00011 #include <string>
00012 #include <iomanip>
00013 #include <list>
00014 
00015 #include <stk_util/util/IndentStreambuf.hpp>
00016 #include <stk_util/diag/Writer.hpp>
00017 
00018 namespace stk {
00019 namespace diag {
00020 
00021 WriterThrowSafe::WriterThrowSafe(
00022   Writer &              writer)
00023   : m_writer(writer),
00024     m_depth(writer.getDepth())
00025 {}
00026 
00027 
00028 WriterThrowSafe::~WriterThrowSafe()
00029 {
00030   m_writer.restoreDepth(m_depth);
00031 }
00032 
00033 
00034 Writer::Writer(
00035   std::streambuf *      writer_streambuf,
00036   PrintMask   print_mask,
00037   Flags     flags)
00038   : m_flags(flags),
00039     m_printMask(print_mask),
00040     m_lineMaskStack(),
00041     m_traceDepth(0),
00042     m_writerStream(writer_streambuf)
00043 {}
00044 
00045 
00046 Writer::~Writer()
00047 {}
00048 
00049 
00055 Writer &
00056 Writer::dflush() {
00057   getStream() << std::flush;
00058   return *this;
00059 }
00060 
00069 Writer &
00070 Writer::dendl() {
00071   if (shouldPrint())
00072     getStream() << std::endl;
00073 
00074   m_lineMaskStack.resetDepth();
00075 
00076   return *this;
00077 }
00078 
00085 Writer &
00086 Writer::push() {
00087   if (shouldPrint()) {
00088     m_lineMaskStack.pushDepth();
00089     getStream() << stk::push;
00090   }
00091 
00092   return *this;
00093 }
00094 
00101 Writer &
00102 Writer::pop() {
00103   if (shouldPrint()) {
00104     getStream() << stk::pop;
00105     m_lineMaskStack.resetDepth().pop();
00106   }
00107 
00108   return *this;
00109 }
00110 
00117 Writer &
00118 Writer::resetLineMask() {
00119   m_lineMaskStack.popLineMask();
00120 
00121   return *this;
00122 }
00123 
00130 Writer &
00131 Writer::operator<<(Writer& (*f)(Writer&)) {
00132   f(*this);
00133   return *this;
00134 }
00135 
00136 Writer &
00137 Writer::operator<<(
00138   std::ios_base &       (*f)(std::ios_base&))
00139 {
00140   if (shouldPrint())
00141     f(getStream());
00142   return *this;
00143 }
00144 
00145 
00146 Writer &
00147 Writer::operator<<(
00148   std::ostream &        (*f)(std::ostream&))
00149 {
00150   if (shouldPrint())
00151     f(getStream());
00152 
00153   return *this;
00154 }
00155 
00156 
00157 Writer &
00158 operator<<(
00159   Writer &  dout,
00160   const void *  ptr)
00161 {
00162   if (dout.shouldPrint())
00163     dout.getStream() << ptr;
00164 
00165   return dout;
00166 }
00167 
00168 
00169 Writer &
00170 operator<<(
00171   Writer &  dout,
00172   const char *  c_str)
00173 {
00174   if (dout.shouldPrint())
00175     dout.getStream() << c_str;
00176 
00177   return dout;
00178 }
00179 
00180 
00181 Writer &
00182 operator<<(
00183   Writer &              dout,
00184   const std::string &   s)
00185 {
00186   dout << s.c_str();
00187   return dout;
00188 }
00189 
00190 
00191 Writer &
00192 operator<<(
00193   Writer &  dout,
00194   const float & x)
00195 {
00196   if (dout.shouldPrint())
00197     dout.getStream() << x;
00198 
00199   return dout;
00200 }
00201 
00202 
00203 Writer &
00204 operator<<(
00205   Writer &          dout,
00206   const double &        x)
00207 {
00208   if (dout.shouldPrint())
00209     dout.getStream() << x;
00210 
00211   return dout;
00212 }
00213 
00214 
00215 Writer &
00216 operator<<(
00217   Writer &          dout,
00218   const long double &   x)
00219 {
00220   if (dout.shouldPrint())
00221     dout.getStream() << x;
00222 
00223   return dout;
00224 }
00225 
00226 
00227 Writer &
00228 operator<<(
00229   Writer &  dout,
00230   const int &   x)
00231 {
00232   if (dout.shouldPrint())
00233     dout.getStream() << x;
00234 
00235   return dout;
00236 }
00237 
00238 
00239 Writer &
00240 operator<<(
00241   Writer &          dout,
00242   const unsigned int &  x)
00243 {
00244   if (dout.shouldPrint())
00245     dout.getStream() << x;
00246 
00247   return dout;
00248 }
00249 
00250 
00251 Writer &
00252 operator<<(
00253   Writer &  dout,
00254   const long &  x)
00255 {
00256   if (dout.shouldPrint())
00257     dout.getStream() << x;
00258 
00259   return dout;
00260 }
00261 
00262 
00263 Writer &
00264 operator<<(
00265   Writer &          dout,
00266   const unsigned long & x)
00267 {
00268   if (dout.shouldPrint())
00269     dout.getStream() << x;
00270 
00271   return dout;
00272 }
00273 
00274 Writer &
00275 operator<<(
00276   Writer &            dout,
00277   const long long &     x)
00278 {
00279   if (dout.shouldPrint())
00280     dout.getStream() << x;
00281 
00282   return dout;
00283 }
00284 
00285 Writer &
00286 operator<<(
00287   Writer &            dout,
00288   const unsigned long long &  x)
00289 {
00290   if (dout.shouldPrint())
00291     dout.getStream() << x;
00292 
00293   return dout;
00294 }
00295 
00296 Writer &
00297 operator<<(
00298   Writer &  dout,
00299   const short & x)
00300 {
00301   if (dout.shouldPrint())
00302     dout.getStream() << x;
00303 
00304   return dout;
00305 }
00306 
00307 
00308 Writer &
00309 operator<<(
00310   Writer &            dout,
00311   const unsigned short &  x)
00312 {
00313   if (dout.shouldPrint())
00314     dout.getStream() << x;
00315 
00316   return dout;
00317 }
00318 
00319 
00320 } // namespace diag
00321 } // namespace stk

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7