Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

MsgStream.h

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiKernel/GaudiKernel/MsgStream.h,v 1.1.1.1 2001/04/18 18:14:18 tlindner Exp $
00002 #ifndef GAUDIKERNEL_MSGSTREAM_H
00003 #define GAUDIKERNEL_MSGSTREAM_H
00004 
00005 // Include files
00006 #include <string>
00007 #include <iomanip>
00008 #include <strstream>
00009 #include "GaudiKernel/IMessageSvc.h"
00010 
00019 class MsgStream     {
00020 public:
00022   enum Error   {
00023         MSGSTREAM_ERROR = -1
00024   };
00025 protected:
00027   IMessageSvc*    m_service;
00029   std::string     m_buffer;
00031   std::string     m_source;
00033   std::ostrstream m_stream;
00035   bool            m_active;
00037   MSG::Level      m_level;
00039   MSG::Level      m_currLevel;
00040 public:
00042   MsgStream(IMessageSvc* svc, int buffer_length=128);
00044   MsgStream(IMessageSvc* svc, const std::string& source, int buffer_length=128);
00046   MsgStream(const MsgStream& msg)
00047   : m_service(msg.m_service),
00048     m_source(msg.m_source),
00049     m_active(msg.m_active),
00050     m_level(msg.m_level)
00051   {
00052   }
00054   virtual ~MsgStream();
00056   MsgStream& report(int lvl)   {
00057     lvl = (lvl >= MSG::NUM_LEVELS) ? MSG::FATAL : (lvl<MSG::NIL) ? MSG::NIL : lvl;
00058     ((m_currLevel=MSG::Level(lvl)) >= level()) ? activate() : deactivate();
00059     return *this;
00060   }
00062   virtual MsgStream& doOutput();
00064   const std::string& buffer() const {
00065     return m_buffer;
00066   }
00068   std::ostrstream& stream()   {
00069     return m_stream;
00070   }
00072   void setLevel(int level)    {
00073     level = (level >= MSG::NUM_LEVELS) ? MSG::FATAL : (level<MSG::NIL) ? MSG::NIL : level;
00074     m_level = MSG::Level(level);
00075   }
00077   MSG::Level level()   {
00078     return m_level;
00079   }
00081   void activate()     {
00082     m_active = true;
00083   }
00085   void deactivate()     {
00086     m_active = false;
00087   }
00089   bool isActive()  const   {
00090     return m_active;
00091   }
00092   // oMsgStream flush emulation
00093   MsgStream& flush()    {
00094     if ( isActive() ) m_stream.flush();
00095     return *this;
00096   }
00097   // oMsgStream write emulation
00098   MsgStream& write(const char* buff,int len)  {
00099     if ( isActive() ) m_stream.write(buff, len);
00100     return *this;
00101   }
00103   MsgStream& operator<<(MsgStream& (*_f)(MsgStream&))    {
00104     if ( isActive() ) _f(*this);
00105     return *this;
00106   }
00108   MsgStream& operator<<(std::ostream& (*_f)(std::ostream&))    {
00109     if ( isActive() ) _f(m_stream);
00110     return *this;
00111   }
00113   MsgStream& operator<<(std::ios& (*_f)(std::ios&))    {
00114     if ( isActive() ) _f(m_stream);
00115     return *this;
00116   }
00118   MsgStream& operator<< (MSG::Level level)  {   
00119     return report(level);
00120   }
00121   MsgStream& operator<<(const char* arg)          {if(isActive())m_stream << arg; return *this;}
00122   MsgStream& operator<<(const unsigned char arg)  {if(isActive())m_stream << arg; return *this;}
00123   MsgStream& operator<<(const signed char arg)    {if(isActive())m_stream << arg; return *this;}
00124   MsgStream& operator<<(char arg)                 {if(isActive())m_stream << arg; return *this;}
00125   MsgStream& operator<<(short arg)                {if(isActive())m_stream << arg; return *this;}
00126   MsgStream& operator<<(unsigned short arg)       {if(isActive())m_stream << arg; return *this;}
00127   MsgStream& operator<<(int arg)                  {if(isActive())m_stream << arg; return *this;}
00128   MsgStream& operator<<(unsigned int arg)         {if(isActive())m_stream << arg; return *this;}
00129   MsgStream& operator<<(long arg)                 {if(isActive())m_stream << arg; return *this;}
00130   MsgStream& operator<<(unsigned long arg)        {if(isActive())m_stream << arg; return *this;}
00131   MsgStream& operator<<(longlong arg)             {if(isActive())m_stream << "0x" << std::hex 
00132                                                    << (long)(arg>>32) << (long)((arg<<32)>>32) 
00133                                                    << std::dec; return *this;}
00134   MsgStream& operator<<(float arg)                {if(isActive())m_stream << arg; return *this;}
00135   MsgStream& operator<<(double arg)               {if(isActive())m_stream << arg; return *this;}
00136   MsgStream& operator<<(long double arg)          {if(isActive())m_stream << arg; return *this;}
00137   MsgStream& operator<<(bool arg)                 {if(isActive())m_stream << arg; return *this;}
00138   MsgStream& operator<<(const void* arg)          {if(isActive())m_stream << arg; return *this;}
00139   MsgStream& operator<<(const std::string& arg)   {if(isActive())m_stream << arg; return *this;}
00140   // IOS emulation
00141   long flags()                             const  {return isActive() ? m_stream.flags()    : MSGSTREAM_ERROR;}
00142   long flags(long v)                              {return isActive() ? m_stream.flags(v)  :  MSGSTREAM_ERROR;}
00143   long setf(long v)                               {return isActive() ? m_stream.setf(v)  :  MSGSTREAM_ERROR;}
00144   int width()                              const  {return isActive() ? m_stream.width()    : MSGSTREAM_ERROR;}
00145   int width(int v)                                {return isActive() ? m_stream.width(v)    : MSGSTREAM_ERROR;}
00146   char fill()                              const  {return isActive() ? m_stream.fill()     : MSGSTREAM_ERROR;}
00147   char fill(char v)                               {return isActive() ? m_stream.fill(v)     : MSGSTREAM_ERROR;}
00148   int precision()                          const  {return isActive() ? m_stream.precision(): MSGSTREAM_ERROR;}
00149   int precision(int v)                            {return isActive() ? m_stream.precision(v): MSGSTREAM_ERROR;}
00150   int rdstate()                            const  {return isActive() ? m_stream.rdstate () : MSGSTREAM_ERROR;}
00151   int good()                               const  {return isActive() ? m_stream.good ()    : MSGSTREAM_ERROR;}
00152   int eof()                                const  {return isActive() ? m_stream.eof ()     : MSGSTREAM_ERROR;}
00153   int bad()                                const  {return isActive() ? m_stream.bad()      : MSGSTREAM_ERROR;}
00154   long setf(long _f,long _m)  {
00155     return isActive() ? m_stream.setf(_f, _m)   : MSGSTREAM_ERROR;
00156   }
00157   void unsetf(long _l)    {
00158     if ( isActive() ) m_stream.unsetf(_l);
00159   }
00160   void clear(int _i = 0)  {
00161     if ( isActive() ) m_stream.clear(_i);
00162   }
00163 };
00164 
00166 inline MsgStream& endreq(MsgStream& s)   {
00167   return s.doOutput();
00168 }
00169 
00171 #ifdef WIN32
00172   template<class _E> inline 
00173   MsgStream& operator<<( MsgStream& s, const std::_Fillobj<_E>& obj)    {
00174     if ( s.isActive() ) s.stream().fill(obj._Ch);
00175     return s;
00176   }
00177   template<class _Tm> inline
00178   MsgStream& operator << (MsgStream& s, const std::_Smanip<_Tm>& manip) {
00179     if ( s.isActive() ) (*manip._Pf)(s.stream(), manip._Manarg);
00180           return s; 
00181   }
00182 #else
00183   template<class _Tm> inline
00184   MsgStream& operator << (MsgStream& s, const std::smanip<_Tm>& manip)  {
00185     if ( s.isActive() ) s.stream() << manip;
00186           return s; 
00187   }
00188 #endif
00189 #endif    // GAUDIKERNEL_MSGSTREAM_H
00190 

Generated at Wed Nov 21 12:22:04 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000