MyGUI 3.4.3
MyGUI_TPoint.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_TPONT_H_
8#define MYGUI_TPONT_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_StringUtility.h"
12
13namespace MyGUI::types
14{
15
16 template<typename T>
17 struct TPoint
18 {
19 T left{};
20 T top{};
21
22 TPoint() = default;
23
24 TPoint(T const& _left, T const& _top) :
25 left(_left),
26 top(_top)
27 {
28 }
29
30 TPoint& operator-=(TPoint const& _obj)
31 {
32 left -= _obj.left;
33 top -= _obj.top;
34 return *this;
35 }
36
37 TPoint& operator+=(TPoint const& _obj)
38 {
39 left += _obj.left;
40 top += _obj.top;
41 return *this;
42 }
43
44 TPoint operator-(TPoint const& _obj) const
45 {
46 return TPoint(left - _obj.left, top - _obj.top);
47 }
48
49 TPoint operator+(TPoint const& _obj) const
50 {
51 return TPoint(left + _obj.left, top + _obj.top);
52 }
53
54 template<typename U>
56 {
57 left = _obj.left;
58 top = _obj.top;
59 return *this;
60 }
61
62 bool operator==(TPoint const& _obj) const
63 {
64 return ((left == _obj.left) && (top == _obj.top));
65 }
66
67 bool operator!=(TPoint const& _obj) const
68 {
69 return !((left == _obj.left) && (top == _obj.top));
70 }
71
72 void clear()
73 {
74 left = top = 0;
75 }
76
77 void set(T const& _left, T const& _top)
78 {
79 left = _left;
80 top = _top;
81 }
82
83 void swap(TPoint& _value)
84 {
85 TPoint tmp = _value;
86 _value = *this;
87 *this = tmp;
88 }
89
90 bool empty() const
91 {
92 return ((left == 0) && (top == 0));
93 }
94
95 std::string print() const
96 {
97 std::ostringstream stream;
98 stream << *this;
99 return stream.str();
100 }
101
102 static TPoint<T> parse(std::string_view _value)
103 {
104 return utility::parseValue<TPoint<T>>(_value);
105 }
106
107 friend std::ostream& operator<<(std::ostream& _stream, const TPoint<T>& _value)
108 {
109 _stream << _value.left << " " << _value.top;
110 return _stream;
111 }
112
113 friend std::istream& operator>>(std::istream& _stream, TPoint<T>& _value)
114 {
115 _stream >> _value.left >> _value.top;
116 if (_stream.fail())
117 _value.clear();
118 return _stream;
119 }
120 };
121
122} // namespace MyGUI
123
124#endif // MYGUI_TPONT_H_
T parseValue(std::string_view _value)
TPoint & operator-=(TPoint const &_obj)
bool operator==(TPoint const &_obj) const
TPoint operator-(TPoint const &_obj) const
static TPoint< T > parse(std::string_view _value)
friend std::ostream & operator<<(std::ostream &_stream, const TPoint< T > &_value)
TPoint(T const &_left, T const &_top)
TPoint operator+(TPoint const &_obj) const
void set(T const &_left, T const &_top)
void swap(TPoint &_value)
TPoint & operator+=(TPoint const &_obj)
bool operator!=(TPoint const &_obj) const
TPoint & operator=(TPoint< U > const &_obj)
std::string print() const
friend std::istream & operator>>(std::istream &_stream, TPoint< T > &_value)