MyGUI  3.2.0
MyGUI_LogLevel.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_LOG_LEVEL_H__
23 #define __MYGUI_LOG_LEVEL_H__
24 
25 #include "MyGUI_Prerequest.h"
26 
27 namespace MyGUI
28 {
29 
31  {
32  enum Enum
33  {
34  Info, // Информационное сообщение.
35  Warning, // Несущественная проблема.
36  Error, // Устранимая ошибка.
37  Critical, // Неустранимая ошибка или сбой в работе приложения.
38  MAX
39  };
40 
42  value(Info)
43  {
44  }
45 
46  LogLevel(Enum _value) :
47  value(_value)
48  {
49  }
50 
51  static LogLevel parse(const std::string& _value)
52  {
53  LogLevel type;
54  int value = 0;
55  while (true)
56  {
57  const char* name = type.getValueName(value);
58  if (strcmp(name, "") == 0 || name == _value)
59  break;
60  value++;
61  }
62  type.value = (Enum)value;
63  return type;
64  }
65 
66  friend bool operator < (LogLevel const& a, LogLevel const& b)
67  {
68  return a.value < b.value;
69  }
70 
71  friend bool operator >= (LogLevel const& a, LogLevel const& b)
72  {
73  return !(a < b);
74  }
75 
76  friend bool operator > (LogLevel const& a, LogLevel const& b)
77  {
78  return (b < a);
79  }
80 
81  friend bool operator <= (LogLevel const& a, LogLevel const& b)
82  {
83  return !(a > b);
84  }
85 
86  friend bool operator == (LogLevel const& a, LogLevel const& b)
87  {
88  return !(a < b) && !(a > b);
89  }
90 
91  friend bool operator != (LogLevel const& a, LogLevel const& b)
92  {
93  return !(a == b);
94  }
95 
96  friend std::ostream& operator << (std::ostream& _stream, const LogLevel& _value)
97  {
98  _stream << _value.getValueName(_value.value);
99  return _stream;
100  }
101 
102  friend std::istream& operator >> (std::istream& _stream, LogLevel& _value)
103  {
104  std::string value;
105  _stream >> value;
106  _value = parse(value);
107  return _stream;
108  }
109 
110  std::string print() const
111  {
112  return getValueName(value);
113  }
114 
115  private:
116  const char* getValueName(int _index) const
117  {
118  static const char* values[MAX + 1] = { "Info", "Warning", "Error", "Critical", "" };
119  return values[(_index < MAX && _index >= 0) ? _index : MAX];
120  }
121 
122  private:
123  Enum value;
124  };
125 
126 } // namespace MyGUI
127 
128 #endif // __MYGUI_LOG_LEVEL_H__