Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

MultiMessageDebugStream.h

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

Generated on Thu Feb 3 17:37:37 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5