MyGUI: MyGUI_FlowDirection.h Source File

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
18 struct MYGUI_EXPORT FlowDirection
19 {
20 enum Enum
21 {
22 LeftToRight,
23 RightToLeft,
24 TopToBottom,
25 BottomToTop,
26 MAX
27 };
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_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI::FontCodeType::Enum
Enum
Definition MyGUI_FontData.h:20
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::FlowDirection::isVertical
bool isVertical() const
Definition MyGUI_FlowDirection.h:54
MyGUI::FlowDirection::getValue
int getValue() const
Definition MyGUI_FlowDirection.h:88
MyGUI::FlowDirection::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const FlowDirection &_value)
Definition MyGUI_FlowDirection.h:69
MyGUI::FlowDirection::FlowDirection
FlowDirection(Enum _value=LeftToRight)
Definition MyGUI_FlowDirection.h:29
MyGUI::FlowDirection::Enum
Enum
Definition MyGUI_FlowDirection.h:21
MyGUI::FlowDirection::TopToBottom
@ TopToBottom
Definition MyGUI_FlowDirection.h:24
MyGUI::FlowDirection::MAX
@ MAX
Definition MyGUI_FlowDirection.h:26
MyGUI::FlowDirection::RightToLeft
@ RightToLeft
Definition MyGUI_FlowDirection.h:23
MyGUI::FlowDirection::BottomToTop
@ BottomToTop
Definition MyGUI_FlowDirection.h:25
MyGUI::FlowDirection::LeftToRight
@ LeftToRight
Definition MyGUI_FlowDirection.h:22
MyGUI::FlowDirection::parse
static FlowDirection parse(std::string_view _value)
Definition MyGUI_FlowDirection.h:34
MyGUI::FlowDirection::isHorizontal
bool isHorizontal() const
Definition MyGUI_FlowDirection.h:49
MyGUI::FlowDirection::operator!=
friend bool operator!=(FlowDirection const &a, FlowDirection const &b)
Definition MyGUI_FlowDirection.h:64
MyGUI::FlowDirection::print
std::string_view print() const
Definition MyGUI_FlowDirection.h:83
MyGUI::FlowDirection::operator>>
friend std::istream & operator>>(std::istream &_stream, FlowDirection &_value)
Definition MyGUI_FlowDirection.h:75
MyGUI::FlowDirection::operator==
friend bool operator==(FlowDirection const &a, FlowDirection const &b)
Definition MyGUI_FlowDirection.h:59