MyGUI  3.2.0
MyGUI_MenuItemType.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_MENU_ITEM_TYPE_H__
23 #define __MYGUI_MENU_ITEM_TYPE_H__
24 
25 #include "MyGUI_Prerequest.h"
26 
27 namespace MyGUI
28 {
29 
31  {
32  enum Enum
33  {
37  MAX
38  };
39 
40  MenuItemType(Enum _value = MAX) :
41  value(_value)
42  {
43  }
44 
45  static MenuItemType parse(const std::string& _value)
46  {
47  MenuItemType type;
48  int value = 0;
49  while (true)
50  {
51  const char* name = type.getValueName(value);
52  if (strcmp(name, "") == 0 || name == _value)
53  break;
54  value++;
55  }
56  type.value = Enum(value);
57  return type;
58  }
59 
60  friend bool operator == (MenuItemType const& a, MenuItemType const& b)
61  {
62  return a.value == b.value;
63  }
64 
65  friend bool operator != (MenuItemType const& a, MenuItemType const& b)
66  {
67  return a.value != b.value;
68  }
69 
70  friend std::ostream& operator << (std::ostream& _stream, const MenuItemType& _value)
71  {
72  _stream << _value.getValueName(_value.value);
73  return _stream;
74  }
75 
76  friend std::istream& operator >> (std::istream& _stream, MenuItemType& _value)
77  {
78  std::string value;
79  _stream >> value;
80  _value = parse(value);
81  return _stream;
82  }
83 
84  std::string print() const
85  {
86  return getValueName(value);
87  }
88 
89  private:
90  const char* getValueName(int _index) const
91  {
92  static const char* values[MAX + 1] = { "Normal", "Popup", "Separator", "" };
93  return values[(_index < MAX && _index >= 0) ? _index : MAX];
94  }
95 
96  private:
97  Enum value;
98  };
99 
100 } // namespace MyGUI
101 
102 #endif // __MYGUI_MENU_ITEM_TYPE_H__