MyGUI
3.2.0
|
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_MENU_ITEM_TYPE_H__ 00023 #define __MYGUI_MENU_ITEM_TYPE_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 00027 namespace MyGUI 00028 { 00029 00030 struct MYGUI_EXPORT MenuItemType 00031 { 00032 enum Enum 00033 { 00034 Normal, 00035 Popup, 00036 Separator, 00037 MAX 00038 }; 00039 00040 MenuItemType(Enum _value = MAX) : 00041 value(_value) 00042 { 00043 } 00044 00045 static MenuItemType parse(const std::string& _value) 00046 { 00047 MenuItemType type; 00048 int value = 0; 00049 while (true) 00050 { 00051 const char* name = type.getValueName(value); 00052 if (strcmp(name, "") == 0 || name == _value) 00053 break; 00054 value++; 00055 } 00056 type.value = Enum(value); 00057 return type; 00058 } 00059 00060 friend bool operator == (MenuItemType const& a, MenuItemType const& b) 00061 { 00062 return a.value == b.value; 00063 } 00064 00065 friend bool operator != (MenuItemType const& a, MenuItemType const& b) 00066 { 00067 return a.value != b.value; 00068 } 00069 00070 friend std::ostream& operator << (std::ostream& _stream, const MenuItemType& _value) 00071 { 00072 _stream << _value.getValueName(_value.value); 00073 return _stream; 00074 } 00075 00076 friend std::istream& operator >> (std::istream& _stream, MenuItemType& _value) 00077 { 00078 std::string value; 00079 _stream >> value; 00080 _value = parse(value); 00081 return _stream; 00082 } 00083 00084 std::string print() const 00085 { 00086 return getValueName(value); 00087 } 00088 00089 private: 00090 const char* getValueName(int _index) const 00091 { 00092 static const char* values[MAX + 1] = { "Normal", "Popup", "Separator", "" }; 00093 return values[(_index < MAX && _index >= 0) ? _index : MAX]; 00094 } 00095 00096 private: 00097 Enum value; 00098 }; 00099 00100 } // namespace MyGUI 00101 00102 #endif // __MYGUI_MENU_ITEM_TYPE_H__