MyGUI 3.4.3
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, // Неустранимая ошибка или сбой в работе приложения.
27 };
28
30 mValue(Info)
31 {
32 }
33
34 LogLevel(Enum _value) :
35 mValue(_value)
36 {
37 }
38
39 static LogLevel parse(std::string_view _value)
40 {
41 LogLevel type;
42 int value = 0;
43 while (true)
44 {
45 std::string_view name = type.getValueName(value);
46 if (name.empty() || name == _value)
47 break;
48 value++;
49 }
50 type.mValue = static_cast<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_view print() const
99 {
100 return getValueName(mValue);
101 }
102
103 int getValue() const
104 {
105 return mValue;
106 }
107
108 private:
109 std::string_view getValueName(int _index) const
110 {
111 if (_index < 0 || _index >= MAX)
112 return {};
113 static const std::string_view values[MAX] = {"Info", "Warning", "Error", "Critical"};
114 return values[_index];
115 }
116
117 private:
118 Enum mValue;
119 };
120
121} // namespace MyGUI
122
123#endif // MYGUI_LOG_LEVEL_H_
#define MYGUI_EXPORT
int getValue() const
friend std::ostream & operator<<(std::ostream &_stream, const LogLevel &_value)
friend bool operator<(LogLevel const &a, LogLevel const &b)
friend bool operator>(LogLevel const &a, LogLevel const &b)
friend bool operator==(LogLevel const &a, LogLevel const &b)
friend bool operator!=(LogLevel const &a, LogLevel const &b)
static LogLevel parse(std::string_view _value)
friend bool operator>=(LogLevel const &a, LogLevel const &b)
friend bool operator<=(LogLevel const &a, LogLevel const &b)
friend std::istream & operator>>(std::istream &_stream, LogLevel &_value)
LogLevel(Enum _value)
std::string_view print() const