Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:43

0001 #ifndef MessageLogger_ErrorObj_h
0002 #define MessageLogger_ErrorObj_h
0003 
0004 // ----------------------------------------------------------------------
0005 //
0006 // ErrorObj     is the representation of all information about an error
0007 //      message.  The system uses this heavily:  ErrorLog forms an
0008 //      ErrorObj to pass around to destinations.  A physicist is
0009 //      permitted to use ErrorObj to form a message for potential
0010 //      logging.
0011 //
0012 // 7/8/98  mf   Created file.
0013 // 6/15/99 mf,jvr  Inserted operator<<(void (*f)(ErrorLog&)
0014 // 7/16/99 jvr  Added setSeverity() and setID functions
0015 // 6/6/00 web   Adapt to consolidated ELcout/X
0016 // 6/14/00 web  Declare classes before granting friendship.
0017 // 5/7/01  mf   operator<< (const char[]) to avoid many instantiations of
0018 //              the template one for each length of potential error message
0019 // 6/5/01  mf   Made set() and clear() public.  Added setReactedTo.
0020 // 6/6/06  mf   verbatim.
0021 //
0022 // ----------------------------------------------------------------------
0023 
0024 #include "FWCore/MessageLogger/interface/ELlist.h"
0025 #include "FWCore/MessageLogger/interface/ELextendedID.h"
0026 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
0027 
0028 #include "fmt/format.h"
0029 
0030 #include <sstream>
0031 #include <string>
0032 
0033 namespace edm {
0034 
0035   // ----------------------------------------------------------------------
0036   // Prerequisite classes:
0037   // ----------------------------------------------------------------------
0038 
0039   class ELcout;
0040 
0041   // ----------------------------------------------------------------------
0042   // ErrorObj:
0043   // ----------------------------------------------------------------------
0044 
0045   class ErrorObj {
0046   public:
0047     // --- birth/death:
0048     //
0049     ErrorObj(const messagelogger::ELseverityLevel& sev, std::string_view id, bool verbatim = false);
0050     ErrorObj(const ErrorObj& orig);  // Same serial number and everything!
0051     virtual ~ErrorObj();
0052 
0053     ErrorObj& operator=(const ErrorObj& other);
0054     void swap(ErrorObj& other);
0055     // --- accessors:
0056     //
0057     int serial() const;
0058     const ELextendedID& xid() const;
0059     const std::string& idOverflow() const;
0060     time_t timestamp() const;
0061     const ELlist_string& items() const;
0062     bool reactedTo() const;
0063     std::string fullText() const;
0064     const std::string& context() const;
0065     bool is_verbatim() const;
0066 
0067     // mutators:
0068     //
0069     virtual void setSeverity(const messagelogger::ELseverityLevel& sev);
0070     virtual void setID(std::string_view ID);
0071     virtual void setModule(std::string_view module);
0072     virtual void setSubroutine(std::string_view subroutine);
0073     virtual void setContext(std::string_view context);
0074 
0075     // -----  Methods for ErrorLog or for physicists logging errors:
0076     //
0077     template <class T>
0078     inline ErrorObj& opltlt(const T& t);
0079     ErrorObj& opltlt(const char s[]);
0080     inline ErrorObj& operator<<(std::ostream& (*f)(std::ostream&));
0081     inline ErrorObj& operator<<(std::ios_base& (*f)(std::ios_base&));
0082     template <typename... Args>
0083     inline ErrorObj& format(fmt::format_string<Args...> format, Args&&... args);
0084     inline ErrorObj& vformat(std::string_view fmt, fmt::format_args args);
0085 
0086     virtual ErrorObj& emitToken(std::string_view txt);
0087 
0088     // ---  mutators for use by ELadministrator and ELtsErrorLog
0089     //
0090     virtual void set(const messagelogger::ELseverityLevel& sev, std::string_view id);
0091     virtual void clear();
0092     virtual void setReactedTo(bool r);
0093 
0094   private:
0095     // ---  data members:
0096     //
0097     int mySerial;
0098     ELextendedID myXid;
0099     std::string myIdOverflow;
0100     time_t myTimestamp;
0101     ELlist_string myItems;
0102     bool myReactedTo;
0103     std::string myContext;
0104     std::ostringstream myOs;
0105     std::string emptyString;
0106     bool verbatim;
0107 
0108   };  // ErrorObj
0109 
0110   // ----------------------------------------------------------------------
0111 
0112   // -----  Method for physicists logging errors:
0113   //
0114   template <class T>
0115   inline ErrorObj& operator<<(ErrorObj& e, const T& t);
0116 
0117   ErrorObj& operator<<(ErrorObj& e, const char s[]);
0118 
0119   // ----------------------------------------------------------------------
0120 
0121   // ----------------------------------------------------------------------
0122   // Global functions:
0123   // ----------------------------------------------------------------------
0124 
0125   inline void swap(ErrorObj& a, ErrorObj& b) { a.swap(b); }
0126 
0127 }  // end of namespace edm
0128 
0129 // ----------------------------------------------------------------------
0130 // .icc
0131 // ----------------------------------------------------------------------
0132 
0133 // The icc file contains the template for operator<< (ErrorObj&, T)
0134 
0135 #define ERROROBJ_ICC
0136 #include "FWCore/MessageLogger/interface/ErrorObj.icc"
0137 #undef ERROROBJ_ICC
0138 
0139 // ----------------------------------------------------------------------
0140 
0141 #endif  // MessageLogger_ErrorObj_h