MyGUI: MyGUI_TPoint.h Source File

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>
55 TPoint& operator=(TPoint<U> const& _obj)
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_
MyGUI_Prerequest.h
MyGUI_StringUtility.h
MyGUI::types
Definition MyGUI_TCoord.h:15
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI::types::TPoint::operator-=
TPoint & operator-=(TPoint const &_obj)
Definition MyGUI_TPoint.h:30
MyGUI::types::TPoint::empty
bool empty() const
Definition MyGUI_TPoint.h:90
MyGUI::types::TPoint::operator==
bool operator==(TPoint const &_obj) const
Definition MyGUI_TPoint.h:62
MyGUI::types::TPoint::operator-
TPoint operator-(TPoint const &_obj) const
Definition MyGUI_TPoint.h:44
MyGUI::types::TPoint::parse
static TPoint< T > parse(std::string_view _value)
Definition MyGUI_TPoint.h:102
MyGUI::types::TPoint< int >::left
int left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const TPoint< T > &_value)
Definition MyGUI_TPoint.h:107
MyGUI::types::TPoint::TPoint
TPoint(T const &_left, T const &_top)
Definition MyGUI_TPoint.h:24
MyGUI::types::TPoint::clear
void clear()
Definition MyGUI_TPoint.h:72
MyGUI::types::TPoint::operator+
TPoint operator+(TPoint const &_obj) const
Definition MyGUI_TPoint.h:49
MyGUI::types::TPoint::set
void set(T const &_left, T const &_top)
Definition MyGUI_TPoint.h:77
MyGUI::types::TPoint::swap
void swap(TPoint &_value)
Definition MyGUI_TPoint.h:83
MyGUI::types::TPoint::operator+=
TPoint & operator+=(TPoint const &_obj)
Definition MyGUI_TPoint.h:37
MyGUI::types::TPoint::operator!=
bool operator!=(TPoint const &_obj) const
Definition MyGUI_TPoint.h:67
MyGUI::types::TPoint::TPoint
TPoint()=default
MyGUI::types::TPoint< int >::top
int top
Definition MyGUI_TPoint.h:20
MyGUI::types::TPoint::operator=
TPoint & operator=(TPoint< U > const &_obj)
Definition MyGUI_TPoint.h:55
MyGUI::types::TPoint::print
std::string print() const
Definition MyGUI_TPoint.h:95
MyGUI::types::TPoint::operator>>
friend std::istream & operator>>(std::istream &_stream, TPoint< T > &_value)
Definition MyGUI_TPoint.h:113