MyGUI 3.2.2

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
16 struct MYGUI_EXPORT FlowDirection
17 {
18 enum Enum
19 {
20 LeftToRight,
21 RightToLeft,
22 TopToBottom,
23 BottomToTop,
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_
MyGUI::FontCodeType::Enum
Enum
Definition: MyGUI_FontData.h:18
MyGUI::FlowDirection::BottomToTop
Definition: MyGUI_FlowDirection.h:23
MyGUI_Prerequest.h
MyGUI::FlowDirection::isHorizontal
bool isHorizontal() const
Definition: MyGUI_FlowDirection.h:46
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1048
MyGUI::FlowDirection::Enum
Enum
Definition: MyGUI_FlowDirection.h:18
MyGUI::FlowDirection::LeftToRight
Definition: MyGUI_FlowDirection.h:20
MyGUI::operator==
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1045
MyGUI::FlowDirection::TopToBottom
Definition: MyGUI_FlowDirection.h:22
MyGUI::FlowDirection::RightToLeft
Definition: MyGUI_FlowDirection.h:21
MyGUI::FlowDirection::FlowDirection
FlowDirection(Enum _value=LeftToRight)
Definition: MyGUI_FlowDirection.h:27
MyGUI::FlowDirection::parse
static FlowDirection parse(const std::string &_value)
Definition: MyGUI_FlowDirection.h:32
MyGUI::FlowDirection
Definition: MyGUI_FlowDirection.h:16
MyGUI
Definition: MyGUI_ActionController.h:14
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::FlowDirection::isVertical
bool isVertical() const
Definition: MyGUI_FlowDirection.h:51
MyGUI::FlowDirection::print
std::string print() const
Definition: MyGUI_FlowDirection.h:80
MyGUI::FlowDirection::getValue
int getValue() const
Definition: MyGUI_FlowDirection.h:85