MyGUI: MyGUI_MenuItemType.h Source File

MyGUI 3.4.3

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
12namespace 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(std::string_view _value)
31 {
32 MenuItemType type;
33 int value = 0;
34 while (true)
35 {
36 std::string_view name = type.getValueName(value);
37 if (name.empty() || name == _value)
38 break;
39 value++;
40 }
41 type.mValue = static_cast<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_view print() const
70 {
71 return getValueName(mValue);
72 }
73
74 int getValue() const
75 {
76 return mValue;
77 }
78
79 private:
80 std::string_view getValueName(int _index) const
81 {
82 if (_index < 0 || _index >= MAX)
83 return {};
84 static const std::string_view values[MAX] = {"Normal", "Popup", "Separator"};
85 return values[_index];
86 }
87
88 private:
89 Enum mValue;
90 };
91
92} // namespace MyGUI
93
94#endif // MYGUI_MENU_ITEM_TYPE_H_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI::FontCodeType::Enum
Enum
Definition MyGUI_FontData.h:20
MyGUI
Definition MyGUI_ActionController.h:15