MyGUI 3.5.3
MyGUI_ResizingPolicy.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_RESIZING_POLICY_H_
8#define MYGUI_RESIZING_POLICY_H_
9
10#include "MyGUI_Prerequest.h"
11#include <iostream>
12#include <string>
13#include <string_view>
14
15namespace MyGUI
16{
17
18 struct MYGUI_EXPORT ResizingPolicy
19 {
20 enum Enum
21 {
22 Auto,
23 Fixed,
24 Fill,
25 MAX
26 };
27
28 ResizingPolicy(Enum _value = MAX) :
29 mValue(_value)
30 {
31 }
32
33 static ResizingPolicy parse(std::string_view _value)
34 {
35 ResizingPolicy type;
36 int value = 0;
37 while (true)
38 {
39 std::string_view name = type.getValueName(value);
40 if (name.empty() || name == _value)
41 break;
42 value++;
43 }
44 type.mValue = Enum(value);
45 return type;
46 }
47
48 friend bool operator==(ResizingPolicy const& a, ResizingPolicy const& b)
49 {
50 return a.mValue == b.mValue;
51 }
52
53 friend bool operator!=(ResizingPolicy const& a, ResizingPolicy const& b)
54 {
55 return a.mValue != b.mValue;
56 }
57
58 friend std::ostream& operator<<(std::ostream& _stream, const ResizingPolicy& _value)
59 {
60 _stream << _value.getValueName(_value.mValue);
61 return _stream;
62 }
63
64 friend std::istream& operator>>(std::istream& _stream, ResizingPolicy& _value)
65 {
66 std::string value;
67 _stream >> value;
68 _value = parse(value);
69 return _stream;
70 }
71
72 std::string_view print() const
73 {
74 return getValueName(mValue);
75 }
76
77 int getValue() const
78 {
79 return mValue;
80 }
81
82 private:
83 std::string_view getValueName(int _index) const
84 {
85 if (_index < 0 || _index >= MAX)
86 return {};
87 static const std::string_view values[MAX] = {"Auto", "Fixed", "Fill"};
88 return values[_index];
89 }
90
91 private:
92 Enum mValue;
93 };
94
95} // namespace MyGUI
96
97#endif // MYGUI_RESIZING_POLICY_H_
#define MYGUI_EXPORT