Sierra Toolkit Version of the Day
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     std::ostream &os = dout.getStream();
00176     if (!c_str)
00177       os << "(null)";
00178     else
00179       os << c_str;
00180   }
00181 
00182   return dout;
00183 }
00184 
00185 
00186 Writer &
00187 operator<<(
00188   Writer &              dout,
00189   const std::string &   s)
00190 {
00191   dout << s.c_str();
00192   return dout;
00193 }
00194 
00195 
00196 Writer &
00197 operator<<(
00198   Writer &  dout,
00199   const float & x)
00200 {
00201   if (dout.shouldPrint())
00202     dout.getStream() << x;
00203 
00204   return dout;
00205 }
00206 
00207 
00208 Writer &
00209 operator<<(
00210   Writer &          dout,
00211   const double &        x)
00212 {
00213   if (dout.shouldPrint())
00214     dout.getStream() << x;
00215 
00216   return dout;
00217 }
00218 
00219 
00220 Writer &
00221 operator<<(
00222   Writer &          dout,
00223   const long double &   x)
00224 {
00225   if (dout.shouldPrint())
00226     dout.getStream() << x;
00227 
00228   return dout;
00229 }
00230 
00231 
00232 Writer &
00233 operator<<(
00234   Writer &  dout,
00235   const int &   x)
00236 {
00237   if (dout.shouldPrint())
00238     dout.getStream() << x;
00239 
00240   return dout;
00241 }
00242 
00243 
00244 Writer &
00245 operator<<(
00246   Writer &          dout,
00247   const unsigned int &  x)
00248 {
00249   if (dout.shouldPrint())
00250     dout.getStream() << x;
00251 
00252   return dout;
00253 }
00254 
00255 
00256 Writer &
00257 operator<<(
00258   Writer &  dout,
00259   const long &  x)
00260 {
00261   if (dout.shouldPrint())
00262     dout.getStream() << x;
00263 
00264   return dout;
00265 }
00266 
00267 
00268 Writer &
00269 operator<<(
00270   Writer &          dout,
00271   const unsigned long & x)
00272 {
00273   if (dout.shouldPrint())
00274     dout.getStream() << x;
00275 
00276   return dout;
00277 }
00278 
00279 Writer &
00280 operator<<(
00281   Writer &            dout,
00282   const long long &     x)
00283 {
00284   if (dout.shouldPrint())
00285     dout.getStream() << x;
00286 
00287   return dout;
00288 }
00289 
00290 Writer &
00291 operator<<(
00292   Writer &            dout,
00293   const unsigned long long &  x)
00294 {
00295   if (dout.shouldPrint())
00296     dout.getStream() << x;
00297 
00298   return dout;
00299 }
00300 
00301 Writer &
00302 operator<<(
00303   Writer &  dout,
00304   const short & x)
00305 {
00306   if (dout.shouldPrint())
00307     dout.getStream() << x;
00308 
00309   return dout;
00310 }
00311 
00312 
00313 Writer &
00314 operator<<(
00315   Writer &            dout,
00316   const unsigned short &  x)
00317 {
00318   if (dout.shouldPrint())
00319     dout.getStream() << x;
00320 
00321   return dout;
00322 }
00323 
00324 
00325 } // namespace diag
00326 } // namespace stk
00327 
00328 namespace sierra {
00329 namespace Diag {
00330 
00331 Writer &
00332 operator<<(
00333   Writer &          dout,
00334   const String &        str)
00335 {
00336   if (dout.shouldPrint())
00337     dout.getStream() << str;
00338 
00339   return dout;
00340 }
00341 
00342 
00343 Writer &
00344 operator<<(
00345   Writer &                      dout,
00346   const sierra::Identifier &    s)
00347 {
00348   if (dout.shouldPrint())
00349     dout.getStream() << '\'' << s << '\'';
00350 
00351   return dout;
00352 }
00353 
00354 } // namespace Diag
00355 } // namespace sierra
00356 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines