MyGUI  3.2.1
MyGUI_WidgetStyle.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_WIDGET_STYLE_H__
8 #define __MYGUI_WIDGET_STYLE_H__
9 
10 #include "MyGUI_Prerequest.h"
11 #include <string.h>
12 
13 namespace MyGUI
14 {
15 
17  {
18  enum Enum
19  {
23  MAX
24  };
25 
27  mValue(MAX)
28  {
29  }
30 
31  WidgetStyle(Enum _value) :
32  mValue(_value)
33  {
34  }
35 
36  static WidgetStyle parse(const std::string& _value)
37  {
38  WidgetStyle type;
39  int value = 0;
40  while (true)
41  {
42  const char* name = type.getValueName(value);
43  if (strcmp(name, "") == 0 || name == _value)
44  break;
45  value++;
46  }
47  type.mValue = (Enum)value;
48  return type;
49  }
50 
51  friend bool operator == (WidgetStyle const& a, WidgetStyle const& b)
52  {
53  return a.mValue == b.mValue;
54  }
55 
56  friend bool operator != (WidgetStyle const& a, WidgetStyle const& b)
57  {
58  return a.mValue != b.mValue;
59  }
60 
61  friend std::ostream& operator << (std::ostream& _stream, const WidgetStyle& _value)
62  {
63  _stream << _value.getValueName(_value.mValue);
64  return _stream;
65  }
66 
67  friend std::istream& operator >> (std::istream& _stream, WidgetStyle& _value)
68  {
69  std::string value;
70  _stream >> value;
71  _value = parse(value);
72  return _stream;
73  }
74 
75  std::string print() const
76  {
77  return getValueName(mValue);
78  }
79 
80  int getValue() const
81  {
82  return mValue;
83  }
84 
85  private:
86  const char* getValueName(int _index) const
87  {
88  static const char* values[MAX + 1] = { "Child", "Popup", "Overlapped", "" };
89  return values[(_index < MAX && _index >= 0) ? _index : MAX];
90  }
91 
92  private:
93  Enum mValue;
94  };
95 
96 } // namespace MyGUI
97 
98 #endif // __MYGUI_WIDGET_STYLE_H__