MyGUI: MyGUI_TSize.h Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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