MyGUI 3.2.2

MyGUI_MenuItemType.h
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #ifndef MYGUI_MENU_ITEM_TYPE_H_
8 #define MYGUI_MENU_ITEM_TYPE_H_
9
10 #include "MyGUI_Prerequest.h"
11
12 namespace MyGUI
13 {
14
15 struct MYGUI_EXPORT MenuItemType
16 {
17 enum Enum
18 {
19 Normal,
20 Popup,
21 Separator,
22 MAX
23 };
24
25 MenuItemType(Enum _value = MAX) :
26 mValue(_value)
27 {
28 }
29
30 static MenuItemType parse(const std::string& _value)
31 {
32 MenuItemType type;
33 int value = 0;
34 while (true)
35 {
36 const char* name = type.getValueName(value);
37 if (strcmp(name, "") == 0 || name == _value)
38 break;
39 value++;
40 }
41 type.mValue = Enum(value);
42 return type;
43 }
44
45 friend bool operator == (MenuItemType const& a, MenuItemType const& b)
46 {
47 return a.mValue == b.mValue;
48 }
49
50 friend bool operator != (MenuItemType const& a, MenuItemType const& b)
51 {
52 return a.mValue != b.mValue;
53 }
54
55 friend std::ostream& operator << (std::ostream& _stream, const MenuItemType& _value)
56 {
57 _stream << _value.getValueName(_value.mValue);
58 return _stream;
59 }
60
61 friend std::istream& operator >> (std::istream& _stream, MenuItemType& _value)
62 {
63 std::string value;
64 _stream >> value;
65 _value = parse(value);
66 return _stream;
67 }
68
69 std::string print() const
70 {
71 return getValueName(mValue);
72 }
73
74 int getValue() const
75 {
76 return mValue;
77 }
78
79 private:
80 const char* getValueName(int _index) const
81 {
82 static const char* values[MAX + 1] = { "Normal", "Popup", "Separator", "" };
83 return values[(_index < MAX && _index >= 0) ? _index : MAX];
84 }
85
86 private:
87 Enum mValue;
88 };
89
90 } // namespace MyGUI
91
92 #endif // MYGUI_MENU_ITEM_TYPE_H_
MyGUI::FontCodeType::Enum
Enum
Definition: MyGUI_FontData.h:18
MyGUI_Prerequest.h
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1048
MyGUI::operator==
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1045
MyGUI
Definition: MyGUI_ActionController.h:14
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103