MyGUI: MyGUI_LogLevel.h Source File

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
18 struct MYGUI_EXPORT LogLevel
19 {
20 enum Enum
21 {
22 Info, // Информационное сообщение.
23 Warning, // Несущественная проблема.
24 Error, // Устранимая ошибка.
25 Critical, // Неустранимая ошибка или сбой в работе приложения.
26 MAX
27 };
28
29 LogLevel() :
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_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI::FontCodeType::Enum
Enum
Definition MyGUI_FontData.h:20
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::LogLevel::LogLevel
LogLevel()
Definition MyGUI_LogLevel.h:29
MyGUI::LogLevel::getValue
int getValue() const
Definition MyGUI_LogLevel.h:103
MyGUI::LogLevel::Enum
Enum
Definition MyGUI_LogLevel.h:21
MyGUI::LogLevel::Info
@ Info
Definition MyGUI_LogLevel.h:22
MyGUI::LogLevel::Error
@ Error
Definition MyGUI_LogLevel.h:24
MyGUI::LogLevel::Warning
@ Warning
Definition MyGUI_LogLevel.h:23
MyGUI::LogLevel::Critical
@ Critical
Definition MyGUI_LogLevel.h:25
MyGUI::LogLevel::MAX
@ MAX
Definition MyGUI_LogLevel.h:26
MyGUI::LogLevel::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const LogLevel &_value)
Definition MyGUI_LogLevel.h:84
MyGUI::LogLevel::operator<
friend bool operator<(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:54
MyGUI::LogLevel::operator>
friend bool operator>(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:64
MyGUI::LogLevel::operator==
friend bool operator==(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:74
MyGUI::LogLevel::operator!=
friend bool operator!=(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:79
MyGUI::LogLevel::parse
static LogLevel parse(std::string_view _value)
Definition MyGUI_LogLevel.h:39
MyGUI::LogLevel::operator>=
friend bool operator>=(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:59
MyGUI::LogLevel::operator<=
friend bool operator<=(LogLevel const &a, LogLevel const &b)
Definition MyGUI_LogLevel.h:69
MyGUI::LogLevel::operator>>
friend std::istream & operator>>(std::istream &_stream, LogLevel &_value)
Definition MyGUI_LogLevel.h:90
MyGUI::LogLevel::LogLevel
LogLevel(Enum _value)
Definition MyGUI_LogLevel.h:34
MyGUI::LogLevel::print
std::string_view print() const
Definition MyGUI_LogLevel.h:98