Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

CommonMessaging.h

Go to the documentation of this file.
00001 /*
00002  * CommonMessaging.h
00003  *
00004  *  Created on: Feb 20, 2009
00005  *      Author: Marco Clemencic
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       // Get default implementation of the message service.
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 
00071   inline MsgStream& msgStream() const {
00072     if (UNLIKELY((!m_msgStream.get()) || (!m_streamWithService))) {
00073       SmartIF<IMessageSvc>& ms = msgSvc();
00074       m_msgStream.reset(new MsgStream(ms, this->name()));
00075       m_streamWithService = ms.get() != 0;
00076     }
00077     return *m_msgStream;
00078   }
00079 
00090   inline MsgStream& msgStream(const MSG::Level level) const {
00091     return msgStream() << level;
00092   }
00093 
00095   inline MsgStream&  always() const { return msgStream(MSG::ALWAYS); }
00096 
00098   inline MsgStream&   fatal() const { return msgStream(MSG::FATAL); }
00099 
00101   inline MsgStream&     err() const { return msgStream(MSG::ERROR); }
00102 
00104   inline MsgStream&   error() const { return msgStream(MSG::ERROR); }
00105 
00107   inline MsgStream& warning() const { return msgStream(MSG::WARNING); }
00108 
00110   inline MsgStream&    info() const { return msgStream(MSG::INFO); }
00111 
00113   inline MsgStream&   debug() const { return msgStream(MSG::DEBUG); }
00114 
00116   inline MsgStream& verbose() const { return msgStream(MSG::VERBOSE); }
00117 
00119   inline MsgStream&     msg() const { return msgStream(MSG::INFO); }
00120 
00122   inline MSG::Level msgLevel() const {
00123     return msgStream().level();
00124   }
00125 
00127   inline bool msgLevel(MSG::Level lvl) const {
00128     return UNLIKELY(msgLevel() <= lvl);
00129   }
00130 
00131 protected:
00133   mutable SmartIF<IMessageSvc> m_msgsvc;
00134 
00136   mutable std::auto_ptr<MsgStream> m_msgStream;
00137 
00139   mutable bool m_streamWithService;
00140 
00143   void updateMsgStreamOutputLevel(int level) {
00144     if (m_msgStream.get()) m_msgStream->setLevel(level);
00145   }
00146 
00147 };
00148 
00149 
00150 #endif /* COMMONMESSAGING_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:29 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004