MyGUI
3.0.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
include
MyGUI_TSize.h
Go to the documentation of this file.
1
7
/*
8
This file is part of MyGUI.
9
10
MyGUI is free software: you can redistribute it and/or modify
11
it under the terms of the GNU Lesser General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
14
15
MyGUI is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU Lesser General Public License for more details.
19
20
You should have received a copy of the GNU Lesser General Public License
21
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
#ifndef __MYGUI_TSIZE_H__
24
#define __MYGUI_TSIZE_H__
25
26
#include "
MyGUI_Prerequest.h
"
27
28
namespace
MyGUI
29
{
30
namespace
types
31
{
32
33
template
<
typename
T >
struct
TSize
34
{
35
T
width
,
height
;
36
37
TSize
() :
width
( 0 ),
height
( 0 ) { }
38
TSize
( T
const
& w, T
const
& h) :
width
( w ),
height
( h ) { }
39
TSize
(
TSize
const
& o ) :
width
( o.
width
),
height
( o.
height
) { }
40
41
TSize
&
operator-=
(
TSize
const
& o )
42
{
43
width
-= o.
width
;
44
height
-= o.
height
;
45
return
*
this
;
46
}
47
48
TSize
&
operator+=
(
TSize
const
& o )
49
{
50
width
+= o.
width
;
51
height
+= o.
height
;
52
return
*
this
;
53
}
54
55
TSize
operator-
(
TSize
const
& o )
const
56
{
57
return
TSize
(
width
- o.
width
,
height
- o.
height
);
58
}
59
60
TSize
operator+
(
TSize
const
& o )
const
61
{
62
return
TSize
(
width
+ o.
width
,
height
+ o.
height
);
63
}
64
65
TSize
&
operator=
(
TSize
const
& o )
66
{
67
width
= o.
width
;
68
height
= o.
height
;
69
return
*
this
;
70
}
71
72
template
<
typename
U >
73
TSize
&
operator=
(
TSize<U>
const
& o )
74
{
75
width
= o.
width
;
76
height
= o.
height
;
77
return
*
this
;
78
}
79
80
bool
operator==
(
TSize
const
& o )
const
81
{
82
return
((
width
== o.
width
) && (
height
== o.
height
));
83
}
84
85
bool
operator!=
(
TSize
const
& o )
const
86
{
87
return
! ((
width
== o.
width
) && (
height
== o.
height
));
88
}
89
90
void
clear
()
91
{
92
width
=
height
= 0;
93
}
94
95
void
set
( T
const
& w, T
const
& h)
96
{
97
width
= w;
98
height
= h;
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())
return
TSize<T>
();
126
else
127
{
128
int
item = stream.get();
129
while
(item != -1)
130
{
131
if
(item !=
' '
&& item !=
'\t'
)
return
TSize<T>
();
132
item = stream.get();
133
}
134
}
135
return
result;
136
}
137
138
friend
std::ostream& operator << ( std::ostream& _stream, const TSize<T>& _value )
139
{
140
_stream << _value.
width
<<
" "
<< _value.height;
141
return
_stream;
142
}
143
144
friend
std::istream&
operator >>
( std::istream& _stream,
TSize<T>
& _value )
145
{
146
_stream >> _value.
width
>> _value.
height
;
147
if
(_stream.fail()) _value.
clear
();
148
return
_stream;
149
}
150
151
};
152
153
}
// namespace types
154
}
// namespace MyGUI
155
156
#endif // __MYGUI_TSIZE_H__
Generated by
1.8.1.2