Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:58

0001 #ifndef DataFormats_Common_ELseverityLevel_h
0002 #define DataFormats_Common_ELseverityLevel_h
0003 
0004 // ----------------------------------------------------------------------
0005 //
0006 // ELseverityLevel.h - declare objects that encode a message's urgency
0007 //
0008 //  Both frameworker and user will often pass one of the
0009 //  instantiated severity levels to logger methods.
0010 //
0011 //  The only other methods of ELseverityLevel a frameworker
0012 //  might use is to check the relative level of two severities
0013 //  using operator< or the like.
0014 //
0015 // ----------------------------------------------------------------------
0016 
0017 #include <string_view>
0018 #include <cassert>
0019 
0020 namespace edm {
0021 
0022   // ----------------------------------------------------------------------
0023   // ELseverityLevel:
0024   // ----------------------------------------------------------------------
0025 
0026   class ELseverityLevel {
0027   public:
0028     // ---  One ELseverityLevel is globally instantiated (see below)
0029     // ---  for each of the following levels:
0030     //
0031     enum ELsev_ {
0032       ELsev_noValueAssigned = 0,  // default returned by map when not found
0033       ELsev_zeroSeverity,         // threshold use only
0034       ELsev_success,              // report reaching a milestone
0035       ELsev_info,                 // information
0036       ELsev_fwkInfo,              // framework
0037       ELsev_warning,              // warning
0038       ELsev_error,                // error detected
0039       ELsev_unspecified,          // severity was not specified
0040       ELsev_severe,               // future results are suspect
0041       ELsev_highestSeverity,      // threshold use only
0042       // -----
0043       nLevels  // how many levels?
0044     };         // ELsev_
0045 
0046     // -----  Birth/death:
0047     //
0048     constexpr ELseverityLevel(ELsev_ lev = ELsev_unspecified) noexcept : myLevel(lev) {}
0049     constexpr ELseverityLevel(int lev) noexcept : myLevel(lev) {
0050       assert(lev >= ELsev_noValueAssigned);
0051       assert(lev < nLevels);
0052     }
0053     ~ELseverityLevel() noexcept = default;
0054     constexpr ELseverityLevel(const ELseverityLevel&) noexcept = default;
0055     constexpr ELseverityLevel(ELseverityLevel&&) noexcept = default;
0056     constexpr ELseverityLevel& operator=(const ELseverityLevel&) noexcept = default;
0057     constexpr ELseverityLevel& operator=(ELseverityLevel&&) noexcept = default;
0058 
0059     // -----  Comparator:
0060     //
0061     [[nodiscard]] constexpr int cmp(ELseverityLevel const& e) const noexcept { return myLevel - e.myLevel; }
0062 
0063     // -----  Accessors:
0064     //
0065     constexpr int getLevel() const noexcept { return myLevel; }
0066     std::string_view getName() const noexcept;
0067 
0068   private:
0069     // Data per ELseverityLevel object:
0070     //
0071     int myLevel;
0072 
0073   };  // ELseverityLevel
0074 
0075   // ----------------------------------------------------------------------
0076   // Declare the globally available severity objects,
0077   // one generator function and one proxy per non-default ELsev_:
0078   // ----------------------------------------------------------------------
0079 
0080   constexpr const ELseverityLevel ELzeroSeverity{ELseverityLevel::ELsev_zeroSeverity};
0081 
0082   constexpr const ELseverityLevel ELdebug{ELseverityLevel::ELsev_success};
0083 
0084   constexpr const ELseverityLevel ELinfo{ELseverityLevel::ELsev_info};
0085 
0086   constexpr const ELseverityLevel ELfwkInfo{ELseverityLevel::ELsev_fwkInfo};
0087 
0088   constexpr const ELseverityLevel ELwarning{ELseverityLevel::ELsev_warning};
0089 
0090   constexpr const ELseverityLevel ELerror{ELseverityLevel::ELsev_error};
0091 
0092   constexpr const ELseverityLevel ELunspecified{ELseverityLevel::ELsev_unspecified};
0093 
0094   constexpr const ELseverityLevel ELsevere{ELseverityLevel::ELsev_severe};
0095 
0096   constexpr const ELseverityLevel ELhighestSeverity{ELseverityLevel::ELsev_highestSeverity};
0097 
0098   // ----------------------------------------------------------------------
0099   // Comparators:
0100   // ----------------------------------------------------------------------
0101 
0102   constexpr inline bool operator==(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0103     return e1.cmp(e2) == 0;
0104   }
0105   constexpr inline bool operator!=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0106     return e1.cmp(e2) != 0;
0107   }
0108   constexpr inline bool operator<(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0109     return e1.cmp(e2) < 0;
0110   }
0111   constexpr inline bool operator<=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0112     return e1.cmp(e2) <= 0;
0113   }
0114   constexpr inline bool operator>(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0115     return e1.cmp(e2) > 0;
0116   }
0117   constexpr inline bool operator>=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0118     return e1.cmp(e2) >= 0;
0119   }
0120 
0121   // ----------------------------------------------------------------------
0122 
0123 }  // end of namespace edm
0124 
0125 #endif  // DataFormats_Common_ELseverityLevel_h