CommonMessaging.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef COMMONMESSAGING_H_
00009 #define COMMONMESSAGING_H_
00010 #include "GaudiKernel/IService.h"
00011 #include "GaudiKernel/ISvcLocator.h"
00012 #include "GaudiKernel/IMessageSvc.h"
00013 #include "GaudiKernel/MsgStream.h"
00014 #include "GaudiKernel/SmartIF.h"
00015 #include "GaudiKernel/GaudiException.h"
00016
00017 #include <memory>
00018
00022 template <class BASE>
00023 class GAUDI_API CommonMessaging: public BASE {
00024 public:
00025 typedef CommonMessaging base_class;
00026
00028 template <typename A1, typename A2, typename A3> CommonMessaging(const A1& a1, const A2& a2, const A3& a3):
00029 BASE(a1,a2,a3), m_streamWithService(false) {}
00031 template <typename A1, typename A2> CommonMessaging(const A1& a1, const A2& a2):
00032 BASE(a1, a2), m_streamWithService(false) {}
00034 template <typename A1> CommonMessaging(const A1& a1):
00035 BASE(a1), m_streamWithService(false) {}
00037 CommonMessaging():
00038 BASE(), m_streamWithService(false) {}
00039
00041 virtual ~CommonMessaging() {}
00042
00044 virtual SmartIF<ISvcLocator>& serviceLocator() const = 0;
00045
00047 virtual const std::string& name() const = 0;
00048
00052 inline SmartIF<IMessageSvc>& msgSvc() const {
00053 if (!m_msgsvc.get()) {
00054
00055 m_msgsvc = this->serviceLocator();
00056 }
00057 return m_msgsvc;
00058 }
00059
00060 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NO_DEPRECATED)
00061
00065 inline SmartIF<IMessageSvc>& messageService() const {
00066 return msgSvc();
00067 }
00068 #endif
00069
00080 inline MsgStream& msgStream(const MSG::Level level = MSG::INFO) const {
00081 if ((!m_msgStream.get()) || (!m_streamWithService)) {
00082 SmartIF<IMessageSvc>& ms = msgSvc();
00083 m_msgStream.reset(new MsgStream(ms, this->name()));
00084 m_streamWithService = ms.get() != 0;
00085 }
00086 return *m_msgStream << level;
00087 }
00088
00090 inline MsgStream& always() const { return msgStream(MSG::ALWAYS); }
00091
00093 inline MsgStream& fatal() const { return msgStream(MSG::FATAL); }
00094
00096 inline MsgStream& err() const { return msgStream(MSG::ERROR); }
00097
00099 inline MsgStream& error() const { return msgStream(MSG::ERROR); }
00100
00102 inline MsgStream& warning() const { return msgStream(MSG::WARNING); }
00103
00105 inline MsgStream& info() const { return msgStream(MSG::INFO); }
00106
00108 inline MsgStream& debug() const { return msgStream(MSG::DEBUG); }
00109
00111 inline MsgStream& verbose() const { return msgStream(MSG::VERBOSE); }
00112
00114 inline MsgStream& msg() const { return msgStream(); }
00115
00116 protected:
00118 mutable SmartIF<IMessageSvc> m_msgsvc;
00119
00121 mutable std::auto_ptr<MsgStream> m_msgStream;
00122
00124 mutable bool m_streamWithService;
00125
00126 };
00127
00128
00129 #endif