Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef MessageLogger_ELseverityLevel_h
0002 #define MessageLogger_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>
0018 #include <string_view>
0019 
0020 namespace edm {
0021   namespace messagelogger {
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       ELseverityLevel(std::string_view str);
0050       // str may match getSymbol, getName, getInputStr,
0051       // or getVarName -- see accessors
0052       ~ELseverityLevel() noexcept = default;
0053 
0054       // -----  Comparator:
0055       //
0056       [[nodiscard]] constexpr int cmp(ELseverityLevel const& e) const noexcept { return myLevel - e.myLevel; }
0057 
0058       // -----  Accessors:
0059       //
0060       constexpr int getLevel() const noexcept { return myLevel; }
0061       const std::string& getSymbol() const;    // example: "-e"
0062       const std::string& getName() const;      // example: "Error"
0063       const std::string& getInputStr() const;  // example: "ERROR"
0064       const std::string& getVarName() const;   // example: "ELerror"
0065 
0066       // -----  Emitter:
0067       //
0068       friend std::ostream& operator<<(std::ostream& os, const ELseverityLevel& sev);
0069 
0070     private:
0071       // Data per ELseverityLevel object:
0072       //
0073       int myLevel;
0074 
0075     };  // ELseverityLevel
0076 
0077     // ----------------------------------------------------------------------
0078     // Declare the globally available severity objects,
0079     // one generator function and one proxy per non-default ELsev_:
0080     // ----------------------------------------------------------------------
0081 
0082     constexpr const ELseverityLevel ELzeroSeverity{ELseverityLevel::ELsev_zeroSeverity};
0083 
0084     constexpr const ELseverityLevel ELdebug{ELseverityLevel::ELsev_success};
0085 
0086     constexpr const ELseverityLevel ELinfo{ELseverityLevel::ELsev_info};
0087 
0088     constexpr const ELseverityLevel ELfwkInfo{ELseverityLevel::ELsev_fwkInfo};
0089 
0090     constexpr const ELseverityLevel ELwarning{ELseverityLevel::ELsev_warning};
0091 
0092     constexpr const ELseverityLevel ELerror{ELseverityLevel::ELsev_error};
0093 
0094     constexpr const ELseverityLevel ELunspecified{ELseverityLevel::ELsev_unspecified};
0095 
0096     constexpr const ELseverityLevel ELsevere{ELseverityLevel::ELsev_severe};
0097 
0098     constexpr const ELseverityLevel ELhighestSeverity{ELseverityLevel::ELsev_highestSeverity};
0099 
0100     // ----------------------------------------------------------------------
0101     // Comparators:
0102     // ----------------------------------------------------------------------
0103 
0104     constexpr inline bool operator==(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0105       return e1.cmp(e2) == 0;
0106     }
0107     constexpr inline bool operator!=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0108       return e1.cmp(e2) != 0;
0109     }
0110     constexpr inline bool operator<(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0111       return e1.cmp(e2) < 0;
0112     }
0113     constexpr inline bool operator<=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0114       return e1.cmp(e2) <= 0;
0115     }
0116     constexpr inline bool operator>(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0117       return e1.cmp(e2) > 0;
0118     }
0119     constexpr inline bool operator>=(ELseverityLevel const& e1, ELseverityLevel const& e2) noexcept {
0120       return e1.cmp(e2) >= 0;
0121     }
0122 
0123     // ----------------------------------------------------------------------
0124   }  // namespace messagelogger
0125 }  // end of namespace edm
0126 
0127 #endif  // MessageLogger_ELseverityLevel_h