MyGUI  3.2.0
MyGUI_LogLevel.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_LOG_LEVEL_H__
00023 #define __MYGUI_LOG_LEVEL_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 
00027 namespace MyGUI
00028 {
00029 
00030     struct MYGUI_EXPORT LogLevel
00031     {
00032         enum Enum
00033         {
00034             Info, // Информационное сообщение.
00035             Warning, // Несущественная проблема.
00036             Error, // Устранимая ошибка.
00037             Critical, // Неустранимая ошибка или сбой в работе приложения.
00038             MAX
00039         };
00040 
00041         LogLevel() :
00042             value(Info)
00043         {
00044         }
00045 
00046         LogLevel(Enum _value) :
00047             value(_value)
00048         {
00049         }
00050 
00051         static LogLevel parse(const std::string& _value)
00052         {
00053             LogLevel type;
00054             int value = 0;
00055             while (true)
00056             {
00057                 const char* name = type.getValueName(value);
00058                 if (strcmp(name, "") == 0 || name == _value)
00059                     break;
00060                 value++;
00061             }
00062             type.value = (Enum)value;
00063             return type;
00064         }
00065 
00066         friend bool operator < (LogLevel const& a, LogLevel const& b)
00067         {
00068             return a.value < b.value;
00069         }
00070 
00071         friend bool operator >= (LogLevel const& a, LogLevel const& b)
00072         {
00073             return !(a < b);
00074         }
00075 
00076         friend bool operator > (LogLevel const& a, LogLevel const& b)
00077         {
00078             return (b < a);
00079         }
00080 
00081         friend bool operator <= (LogLevel const& a, LogLevel const& b)
00082         {
00083             return !(a > b);
00084         }
00085 
00086         friend bool operator == (LogLevel const& a, LogLevel const& b)
00087         {
00088             return !(a < b) && !(a > b);
00089         }
00090 
00091         friend bool operator != (LogLevel const& a, LogLevel const& b)
00092         {
00093             return !(a == b);
00094         }
00095 
00096         friend std::ostream& operator << (std::ostream& _stream, const LogLevel&  _value)
00097         {
00098             _stream << _value.getValueName(_value.value);
00099             return _stream;
00100         }
00101 
00102         friend std::istream& operator >> (std::istream& _stream, LogLevel&  _value)
00103         {
00104             std::string value;
00105             _stream >> value;
00106             _value = parse(value);
00107             return _stream;
00108         }
00109 
00110         std::string print() const
00111         {
00112             return getValueName(value);
00113         }
00114 
00115     private:
00116         const char* getValueName(int _index) const
00117         {
00118             static const char* values[MAX + 1] = { "Info", "Warning", "Error", "Critical", "" };
00119             return values[(_index < MAX && _index >= 0) ? _index : MAX];
00120         }
00121 
00122     private:
00123         Enum value;
00124     };
00125 
00126 } // namespace MyGUI
00127 
00128 #endif // __MYGUI_LOG_LEVEL_H__