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