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