MyGUI 3.4.1
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
12namespace MyGUI
13{
14 namespace types
15 {
16
17 template<typename T>
18 struct TPoint
19 {
21 T top;
22
24 left(0),
25 top(0)
26 {
27 }
28
29 TPoint(T const& _left, T const& _top) :
30 left(_left),
31 top(_top)
32 {
33 }
34
35 TPoint(TPoint const& _obj) :
36 left(_obj.left),
37 top(_obj.top)
38 {
39 }
40
42 {
43 left -= _obj.left;
44 top -= _obj.top;
45 return *this;
46 }
47
49 {
50 left += _obj.left;
51 top += _obj.top;
52 return *this;
53 }
54
55 TPoint operator - (TPoint const& _obj) const
56 {
57 return TPoint(left - _obj.left, top - _obj.top);
58 }
59
60 TPoint operator + (TPoint const& _obj) const
61 {
62 return TPoint(left + _obj.left, top + _obj.top);
63 }
64
66 {
67 left = _obj.left;
68 top = _obj.top;
69 return *this;
70 }
71
72 template<typename U>
74 {
75 left = _obj.left;
76 top = _obj.top;
77 return *this;
78 }
79
80 bool operator == (TPoint const& _obj) const
81 {
82 return ((left == _obj.left) && (top == _obj.top));
83 }
84
85 bool operator != (TPoint const& _obj) const
86 {
87 return ! ((left == _obj.left) && (top == _obj.top));
88 }
89
90 void clear()
91 {
92 left = top = 0;
93 }
94
95 void set(T const& _left, T const& _top)
96 {
97 left = _left;
98 top = _top;
99 }
100
101 void swap(TPoint& _value)
102 {
103 TPoint tmp = _value;
104 _value = *this;
105 *this = tmp;
106 }
107
108 bool empty() const
109 {
110 return ((left == 0) && (top == 0));
111 }
112
113 std::string print() const
114 {
115 std::ostringstream stream;
116 stream << *this;
117 return stream.str();
118 }
119
120 static TPoint<T> parse(const std::string& _value)
121 {
122 TPoint<T> result;
123 std::istringstream stream(_value);
124 stream >> result.left >> result.top;
125 if (stream.fail())
126 {
127 return TPoint<T>();
128 }
129 else
130 {
131 int item = stream.get();
132 while (item != -1)
133 {
134 if (item != ' ' && item != '\t')
135 return TPoint<T>();
136 item = stream.get();
137 }
138 }
139 return result;
140 }
141
142 friend std::ostream& operator << (std::ostream& _stream, const TPoint<T>& _value)
143 {
144 _stream << _value.left << " " << _value.top;
145 return _stream;
146 }
147
148 friend std::istream& operator >> (std::istream& _stream, TPoint<T>& _value)
149 {
150 _stream >> _value.left >> _value.top;
151 if (_stream.fail())
152 _value.clear();
153 return _stream;
154 }
155 };
156
157 } // namespace types
158
159} // namespace MyGUI
160
161#endif // MYGUI_TPONT_H_
TPoint & operator-=(TPoint const &_obj)
Definition: MyGUI_TPoint.h:41
bool empty() const
Definition: MyGUI_TPoint.h:108
bool operator==(TPoint const &_obj) const
Definition: MyGUI_TPoint.h:80
TPoint operator-(TPoint const &_obj) const
Definition: MyGUI_TPoint.h:55
friend std::ostream & operator<<(std::ostream &_stream, const TPoint< T > &_value)
Definition: MyGUI_TPoint.h:142
TPoint(T const &_left, T const &_top)
Definition: MyGUI_TPoint.h:29
TPoint operator+(TPoint const &_obj) const
Definition: MyGUI_TPoint.h:60
void set(T const &_left, T const &_top)
Definition: MyGUI_TPoint.h:95
void swap(TPoint &_value)
Definition: MyGUI_TPoint.h:101
TPoint & operator+=(TPoint const &_obj)
Definition: MyGUI_TPoint.h:48
TPoint(TPoint const &_obj)
Definition: MyGUI_TPoint.h:35
static TPoint< T > parse(const std::string &_value)
Definition: MyGUI_TPoint.h:120
bool operator!=(TPoint const &_obj) const
Definition: MyGUI_TPoint.h:85
TPoint & operator=(TPoint const &_obj)
Definition: MyGUI_TPoint.h:65
std::string print() const
Definition: MyGUI_TPoint.h:113
friend std::istream & operator>>(std::istream &_stream, TPoint< T > &_value)
Definition: MyGUI_TPoint.h:148