00001
00002 #ifndef TRIGCONFBASE_MSGSTREAM_H
00003 #define TRIGCONFBASE_MSGSTREAM_H 1
00004
00012 #include <sstream>
00013
00014 class IMessageSvc;
00015
00016 namespace TrigConf {
00017
00019 namespace MSGTC {
00020 enum Level {
00021 NIL = 0,
00022 VERBOSE,
00023 DEBUG,
00024 INFO,
00025 WARNING,
00026 ERROR,
00027 FATAL,
00028 ALWAYS,
00029 NUM_LEVELS
00030 };
00031 }
00032
00048 class MsgStreamTC : public std::ostringstream {
00049 public:
00050 MsgStreamTC(const std::string& name);
00051
00053 MSGTC::Level level() {return m_level;}
00054
00056 void setLevel(MSGTC::Level lvl);
00057
00058
00059 void setWidth(unsigned int width) {
00060 m_width = width;
00061 }
00062
00064 MsgStreamTC& operator<< (MSGTC::Level lvl) {
00065 lvl = (lvl >= MSGTC::NUM_LEVELS) ? MSGTC::ALWAYS : (lvl<MSGTC::NIL) ? MSGTC::NIL : lvl;
00066 m_active = ((m_msgLevel=lvl) >= m_level);
00067 return *this;
00068 }
00069
00071 template<typename T>
00072 MsgStreamTC& operator<< (const T& t) {
00073 if (m_active) *static_cast<std::ostringstream*>(this) << t;
00074 return *this;
00075 }
00076
00078 MsgStreamTC& operator<< (std::ios& (*_f)(std::ios&)) {
00079 if (m_active) _f(*this);
00080 return *this;
00081 }
00082
00084 MsgStreamTC& operator<< ( std::ostream& (*_f)(std::ostream&)) {
00085 if (m_active) _f(*this);
00086 return *this;
00087 }
00088
00090 MsgStreamTC& operator<< ( MsgStreamTC& (*_f)(MsgStreamTC&)) {
00091 if (m_active) _f(*this);
00092 return *this;
00093 }
00094
00096 void doOutput();
00097
00099 bool isActive() { return m_active; }
00100
00102 void setName(const std::string & name) { m_name = name; }
00103
00104 private:
00105 bool m_active;
00106 MSGTC::Level m_level;
00107 MSGTC::Level m_msgLevel;
00108 std::string m_name;
00109 unsigned int m_width { 30 };
00110 };
00111
00113 inline MsgStreamTC& endmsgtc(MsgStreamTC& s) {
00114 if (s.isActive()) s.doOutput();
00115 return s;
00116 }
00117
00118 }
00119
00120 #endif