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