00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_MENU_ITEM_TYPE_H__
00024 #define __MYGUI_MENU_ITEM_TYPE_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027
00028 namespace MyGUI
00029 {
00030
00031 struct MYGUI_EXPORT MenuItemType
00032 {
00033 enum Enum
00034 {
00035 Normal,
00036 Popup,
00037 Separator,
00038 MAX
00039 };
00040
00041 static MenuItemType parse(const std::string& _value)
00042 {
00043 MenuItemType type;
00044 int value = 0;
00045 while (true)
00046 {
00047 const char * name = type.getValueName(value);
00048 if (strcmp(name, "") == 0 || name == _value) break;
00049 value++;
00050 }
00051 type.value = MenuItemType::Enum(value);
00052 return type;
00053 }
00054
00055 MenuItemType(Enum _value = MAX) : value(_value) { }
00056
00057 friend bool operator == (MenuItemType const& a, MenuItemType const& b) { return a.value == b.value; }
00058 friend bool operator != (MenuItemType const& a, MenuItemType const& b) { return a.value != b.value; }
00059
00060 friend std::ostream& operator << ( std::ostream& _stream, const MenuItemType& _value )
00061 {
00062 _stream << _value.getValueName(_value.value);
00063 return _stream;
00064 }
00065
00066 friend std::istream& operator >> ( std::istream& _stream, MenuItemType& _value )
00067 {
00068 std::string value;
00069 _stream >> value;
00070 _value = MenuItemType::parse(value);
00071 return _stream;
00072 }
00073
00074 std::string print() const { return getValueName(value); }
00075
00076 private:
00077 const char * getValueName(int _index) const
00078 {
00079 static const char * values[MAX + 1] = { "Normal", "Popup", "Separator", "" };
00080 return values[(_index < MAX && _index >= 0) ? _index : MAX];
00081 }
00082
00083 private:
00084 Enum value;
00085 };
00086
00087 }
00088
00089 #endif // __MYGUI_MENU_ITEM_TYPE_H__