MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_LOG_LEVEL_H__ 00008 #define __MYGUI_LOG_LEVEL_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 00012 namespace MyGUI 00013 { 00014 00015 struct MYGUI_EXPORT LogLevel 00016 { 00017 enum Enum 00018 { 00019 Info, // Информационное сообщение. 00020 Warning, // Несущественная проблема. 00021 Error, // Устранимая ошибка. 00022 Critical, // Неустранимая ошибка или сбой в работе приложения. 00023 MAX 00024 }; 00025 00026 LogLevel() : 00027 mValue(Info) 00028 { 00029 } 00030 00031 LogLevel(Enum _value) : 00032 mValue(_value) 00033 { 00034 } 00035 00036 static LogLevel parse(const std::string& _value) 00037 { 00038 LogLevel type; 00039 int value = 0; 00040 while (true) 00041 { 00042 const char* name = type.getValueName(value); 00043 if (strcmp(name, "") == 0 || name == _value) 00044 break; 00045 value++; 00046 } 00047 type.mValue = (Enum)value; 00048 return type; 00049 } 00050 00051 friend bool operator < (LogLevel const& a, LogLevel const& b) 00052 { 00053 return a.mValue < b.mValue; 00054 } 00055 00056 friend bool operator >= (LogLevel const& a, LogLevel const& b) 00057 { 00058 return !(a < b); 00059 } 00060 00061 friend bool operator > (LogLevel const& a, LogLevel const& b) 00062 { 00063 return (b < a); 00064 } 00065 00066 friend bool operator <= (LogLevel const& a, LogLevel const& b) 00067 { 00068 return !(a > b); 00069 } 00070 00071 friend bool operator == (LogLevel const& a, LogLevel const& b) 00072 { 00073 return !(a < b) && !(a > b); 00074 } 00075 00076 friend bool operator != (LogLevel const& a, LogLevel const& b) 00077 { 00078 return !(a == b); 00079 } 00080 00081 friend std::ostream& operator << (std::ostream& _stream, const LogLevel& _value) 00082 { 00083 _stream << _value.getValueName(_value.mValue); 00084 return _stream; 00085 } 00086 00087 friend std::istream& operator >> (std::istream& _stream, LogLevel& _value) 00088 { 00089 std::string value; 00090 _stream >> value; 00091 _value = parse(value); 00092 return _stream; 00093 } 00094 00095 std::string print() const 00096 { 00097 return getValueName(mValue); 00098 } 00099 00100 int getValue() const 00101 { 00102 return mValue; 00103 } 00104 00105 private: 00106 const char* getValueName(int _index) const 00107 { 00108 static const char* values[MAX + 1] = { "Info", "Warning", "Error", "Critical", "" }; 00109 return values[(_index < MAX && _index >= 0) ? _index : MAX]; 00110 } 00111 00112 private: 00113 Enum mValue; 00114 }; 00115 00116 } // namespace MyGUI 00117 00118 #endif // __MYGUI_LOG_LEVEL_H__