Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 <sstream>
0029 #include <string>
0030 
0031 namespace edm {
0032 
0033   // ----------------------------------------------------------------------
0034   // Prerequisite classes:
0035   // ----------------------------------------------------------------------
0036 
0037   class ELcout;
0038 
0039   // ----------------------------------------------------------------------
0040   // ErrorObj:
0041   // ----------------------------------------------------------------------
0042 
0043   class ErrorObj {
0044   public:
0045     // --- birth/death:
0046     //
0047     ErrorObj(const messagelogger::ELseverityLevel& sev, std::string_view id, bool verbatim = false);
0048     ErrorObj(const ErrorObj& orig);  // Same serial number and everything!
0049     virtual ~ErrorObj();
0050 
0051     ErrorObj& operator=(const ErrorObj& other);
0052     void swap(ErrorObj& other);
0053     // --- accessors:
0054     //
0055     int serial() const;
0056     const ELextendedID& xid() const;
0057     const std::string& idOverflow() const;
0058     time_t timestamp() const;
0059     const ELlist_string& items() const;
0060     bool reactedTo() const;
0061     std::string fullText() const;
0062     const std::string& context() const;
0063     bool is_verbatim() const;
0064 
0065     // mutators:
0066     //
0067     virtual void setSeverity(const messagelogger::ELseverityLevel& sev);
0068     virtual void setID(std::string_view ID);
0069     virtual void setModule(std::string_view module);
0070     virtual void setSubroutine(std::string_view subroutine);
0071     virtual void setContext(std::string_view context);
0072 
0073     // -----  Methods for ErrorLog or for physicists logging errors:
0074     //
0075     template <class T>
0076     inline ErrorObj& opltlt(const T& t);
0077     ErrorObj& opltlt(const char s[]);
0078     inline ErrorObj& operator<<(std::ostream& (*f)(std::ostream&));
0079     inline ErrorObj& operator<<(std::ios_base& (*f)(std::ios_base&));
0080     template <typename... Args>
0081     inline ErrorObj& format(std::string_view fmt, Args const&... args);
0082 
0083     virtual ErrorObj& emitToken(std::string_view txt);
0084 
0085     // ---  mutators for use by ELadministrator and ELtsErrorLog
0086     //
0087     virtual void set(const messagelogger::ELseverityLevel& sev, std::string_view id);
0088     virtual void clear();
0089     virtual void setReactedTo(bool r);
0090 
0091   private:
0092     // ---  data members:
0093     //
0094     int mySerial;
0095     ELextendedID myXid;
0096     std::string myIdOverflow;
0097     time_t myTimestamp;
0098     ELlist_string myItems;
0099     bool myReactedTo;
0100     std::string myContext;
0101     std::ostringstream myOs;
0102     std::string emptyString;
0103     bool verbatim;
0104 
0105   };  // ErrorObj
0106 
0107   // ----------------------------------------------------------------------
0108 
0109   // -----  Method for physicists logging errors:
0110   //
0111   template <class T>
0112   inline ErrorObj& operator<<(ErrorObj& e, const T& t);
0113 
0114   ErrorObj& operator<<(ErrorObj& e, const char s[]);
0115 
0116   // ----------------------------------------------------------------------
0117 
0118   // ----------------------------------------------------------------------
0119   // Global functions:
0120   // ----------------------------------------------------------------------
0121 
0122   inline void swap(ErrorObj& a, ErrorObj& b) { a.swap(b); }
0123 
0124 }  // end of namespace edm
0125 
0126 // ----------------------------------------------------------------------
0127 // .icc
0128 // ----------------------------------------------------------------------
0129 
0130 // The icc file contains the template for operator<< (ErrorObj&, T)
0131 
0132 #define ERROROBJ_ICC
0133 #include "FWCore/MessageLogger/interface/ErrorObj.icc"
0134 #undef ERROROBJ_ICC
0135 
0136 // ----------------------------------------------------------------------
0137 
0138 #endif  // MessageLogger_ErrorObj_h