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