MongoDB C++ Driver  legacy-1.1.2
labeled_level.h
1 /* Copyright 2009 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <string>
19 
20 #include "mongo/logger/log_severity.h"
21 
22 namespace mongo {
23 namespace logger {
24 
28 class LabeledLevel {
29 public:
30  LabeledLevel(int level) : _level(level) {}
31  LabeledLevel(const char* label, int level) : _label(label), _level(level) {}
32  LabeledLevel(const std::string& label, int level) : _label(label), _level(level) {}
33 
34  LabeledLevel operator+(int i) const {
35  return LabeledLevel(_label, _level + i);
36  }
37 
38  LabeledLevel operator-(int i) const {
39  return LabeledLevel(_label, _level - i);
40  }
41 
42  const std::string& getLabel() const {
43  return _label;
44  }
45  int getLevel() const {
46  return _level;
47  }
48 
49  operator LogSeverity() const {
50  return logger::LogSeverity::cast(_level);
51  }
52 
53 private:
54  std::string _label;
55  int _level;
56 };
57 
58 inline bool operator<(const LabeledLevel& ll, const int i) {
59  return ll.getLevel() < i;
60 }
61 inline bool operator<(const int i, const LabeledLevel& ll) {
62  return i < ll.getLevel();
63 }
64 inline bool operator>(const LabeledLevel& ll, const int i) {
65  return ll.getLevel() > i;
66 }
67 inline bool operator>(const int i, const LabeledLevel& ll) {
68  return i > ll.getLevel();
69 }
70 inline bool operator<=(const LabeledLevel& ll, const int i) {
71  return ll.getLevel() <= i;
72 }
73 inline bool operator<=(const int i, const LabeledLevel& ll) {
74  return i <= ll.getLevel();
75 }
76 inline bool operator>=(const LabeledLevel& ll, const int i) {
77  return ll.getLevel() >= i;
78 }
79 inline bool operator>=(const int i, const LabeledLevel& ll) {
80  return i >= ll.getLevel();
81 }
82 inline bool operator==(const LabeledLevel& ll, const int i) {
83  return ll.getLevel() == i;
84 }
85 inline bool operator==(const int i, const LabeledLevel& ll) {
86  return i == ll.getLevel();
87 }
88 
89 } // namespace logger
90 } // namespace mongo
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
static LogSeverity cast(int)
Casts an integer to a severity.
Definition: log_severity-inl.h:40
Representation of the severity / priority of a log message.
Definition: log_severity.h:33
Deprecated utility for associating a string and log level together.
Definition: labeled_level.h:28