Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:40

0001 #ifndef FWCore_MessageLogger_MessageSender_h
0002 #define FWCore_MessageLogger_MessageSender_h
0003 
0004 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
0005 #include "FWCore/MessageLogger/interface/ErrorObj.h"
0006 
0007 #include <memory>
0008 
0009 #include <map>
0010 
0011 namespace edm {
0012 
0013   class MessageSender {
0014     struct ErrorObjDeleter {
0015       ErrorObjDeleter() {}
0016       void operator()(ErrorObj* errorObjPtr);
0017     };
0018 
0019   public:
0020     // ---  birth/death:
0021     MessageSender() = default;
0022     MessageSender(messagelogger::ELseverityLevel const& sev,
0023                   std::string_view id,
0024                   bool verbatim = false,
0025                   bool suppressed = false);
0026     MessageSender(MessageSender&&) = default;
0027     MessageSender(MessageSender const&) = default;
0028     MessageSender& operator=(MessageSender&&) = default;
0029     MessageSender& operator=(MessageSender const&) = default;
0030     ~MessageSender();
0031 
0032     // ---  stream out the next part of a message:
0033     template <class T>
0034     MessageSender& operator<<(T const& t) {
0035       if (valid())
0036         (*errorobj_p) << t;
0037       return *this;
0038     }
0039 
0040     template <typename... Args>
0041     MessageSender& format(std::string_view fmt, Args const&... args) {
0042       if (valid())
0043         errorobj_p->format(fmt, args...);
0044       return *this;
0045     }
0046 
0047     bool valid() const noexcept { return errorobj_p != nullptr; }
0048 
0049   private:
0050     // data:
0051     std::shared_ptr<ErrorObj> errorobj_p;
0052 
0053   };  // MessageSender
0054 
0055 }  // namespace edm
0056 
0057 #endif  // FWCore_MessageLogger_MessageSender_h