MultiMessageDebugStream.h

00001 
00002 #ifndef SCT_MULTIMESSAGEDEBUGSTREAM_H
00003 #define SCT_MULTIMESSAGEDEBUGSTREAM_H
00004 
00005 #include <sstream>
00006 #include <iostream>
00007 
00008 namespace Sct {
00009 
00010   class MultiMessageDebugStream {
00011   private:
00012     const bool m_out;
00013     const bool m_err;
00014     const bool m_mrs;
00015     unsigned int m_severity;
00016     std::ostringstream * m_oss;
00018     bool renew();
00019     void announce(const std::string & s);
00020   public:
00021     MultiMessageDebugStream(const bool out=true,
00022                             const bool err=true,
00023                             const bool mrs=true);
00024     ~MultiMessageDebugStream();
00025     void flush();
00026     void severity(unsigned int i);
00027     template <class T> MultiMessageDebugStream & operator<<(const T & t) {
00028       if (m_oss) {
00029         // use m_oss
00030         (*m_oss) << t;
00031       } else {
00032         // try to renew:
00033         if (this->renew()) {
00034           // renew worked
00035           (*m_oss) << t;
00036         } else {
00037           // renew failed -- may be nearly out of memory
00038           // -- can only write to stdout and err, 
00039           // and must flush in case we lose the output!
00040           if (m_out) {
00041             std::cout << "MultiMessageDubugStreamEmergencyChunk[" << t << "]"
00042                       << std::flush; 
00043           };
00044           if (m_err) {
00045             std::cerr << "MultiMessageDubugStreamEmergencyChunk[" << t << "]"
00046                       << std::flush; 
00047           };
00048         };
00049       };
00050 
00051       return *this;
00052     };
00053   };
00054 
00055 };
00056 
00057 #endif

Generated on Mon Feb 6 14:01:23 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6