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