MyGUI 3.4.1
MyGUI_LogLevel.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_LOG_LEVEL_H_
8#define MYGUI_LOG_LEVEL_H_
9
10#include "MyGUI_Prerequest.h"
11#include <string>
12#include <cstring>
13#include <iostream>
14
15namespace MyGUI
16{
17
19 {
20 enum Enum
21 {
22 Info, // Информационное сообщение.
23 Warning, // Несущественная проблема.
24 Error, // Устранимая ошибка.
25 Critical, // Неустранимая ошибка или сбой в работе приложения.
26 MAX
27 };
28
30 mValue(Info)
31 {
32 }
33
34 LogLevel(Enum _value) :
35 mValue(_value)
36 {
37 }
38
39 static LogLevel parse(const std::string& _value)
40 {
41 LogLevel type;
42 int value = 0;
43 while (true)
44 {
45 const char* name = type.getValueName(value);
46 if (strcmp(name, "") == 0 || name == _value)
47 break;
48 value++;
49 }
50 type.mValue = (Enum)value;
51 return type;
52 }
53
54 friend bool operator < (LogLevel const& a, LogLevel const& b)
55 {
56 return a.mValue < b.mValue;
57 }
58
59 friend bool operator >= (LogLevel const& a, LogLevel const& b)
60 {
61 return !(a < b);
62 }
63
64 friend bool operator > (LogLevel const& a, LogLevel const& b)
65 {
66 return (b < a);
67 }
68
69 friend bool operator <= (LogLevel const& a, LogLevel const& b)
70 {
71 return !(a > b);
72 }
73
74 friend bool operator == (LogLevel const& a, LogLevel const& b)
75 {
76 return !(a < b) && !(a > b);
77 }
78
79 friend bool operator != (LogLevel const& a, LogLevel const& b)
80 {
81 return !(a == b);
82 }
83
84 friend std::ostream& operator << (std::ostream& _stream, const LogLevel& _value)
85 {
86 _stream << _value.getValueName(_value.mValue);
87 return _stream;
88 }
89
90 friend std::istream& operator >> (std::istream& _stream, LogLevel& _value)
91 {
92 std::string value;
93 _stream >> value;
94 _value = parse(value);
95 return _stream;
96 }
97
98 std::string print() const
99 {
100 return getValueName(mValue);
101 }
102
103 int getValue() const
104 {
105 return mValue;
106 }
107
108 private:
109 const char* getValueName(int _index) const
110 {
111 static const char* values[MAX + 1] = { "Info", "Warning", "Error", "Critical", "" };
112 return values[(_index < MAX && _index >= 0) ? _index : MAX];
113 }
114
115 private:
116 Enum mValue;
117 };
118
119} // namespace MyGUI
120
121#endif // MYGUI_LOG_LEVEL_H_
#define MYGUI_EXPORT
bool operator<=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator>(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
bool operator<(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
int getValue() const
std::string print() const
static LogLevel parse(const std::string &_value)
LogLevel(Enum _value)