00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_TSIZE_H__
00024 #define __MYGUI_TSIZE_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027
00028 namespace MyGUI
00029 {
00030 namespace types
00031 {
00032
00033 template< typename T > struct TSize
00034 {
00035 T width, height;
00036
00037 TSize() : width( 0 ), height( 0 ) { }
00038 TSize( T const& w, T const& h) : width( w ), height( h ) { }
00039 TSize( TSize const& o ) : width( o.width ), height( o.height ) { }
00040
00041 TSize& operator-=( TSize const& o )
00042 {
00043 width -= o.width;
00044 height -= o.height;
00045 return *this;
00046 }
00047
00048 TSize& operator+=( TSize const& o )
00049 {
00050 width += o.width;
00051 height += o.height;
00052 return *this;
00053 }
00054
00055 TSize operator-( TSize const& o ) const
00056 {
00057 return TSize(width - o.width, height - o.height);
00058 }
00059
00060 TSize operator+( TSize const& o ) const
00061 {
00062 return TSize(width + o.width, height + o.height);
00063 }
00064
00065 TSize& operator=( TSize const& o )
00066 {
00067 width = o.width;
00068 height = o.height;
00069 return *this;
00070 }
00071
00072 template< typename U >
00073 TSize& operator=( TSize<U> const& o )
00074 {
00075 width = o.width;
00076 height = o.height;
00077 return *this;
00078 }
00079
00080 bool operator==( TSize const& o ) const
00081 {
00082 return ((width == o.width) && (height == o.height));
00083 }
00084
00085 bool operator!=( TSize const& o ) const
00086 {
00087 return ! ((width == o.width) && (height == o.height));
00088 }
00089
00090 void clear()
00091 {
00092 width = height = 0;
00093 }
00094
00095 void set( T const& w, T const& h)
00096 {
00097 width = w;
00098 height = h;
00099 }
00100
00101 void swap(TSize& _value)
00102 {
00103 TSize tmp = _value;
00104 _value = *this;
00105 *this = tmp;
00106 }
00107
00108 bool empty() const
00109 {
00110 return ((width == 0) && (height == 0));
00111 }
00112
00113 std::string print() const
00114 {
00115 std::ostringstream stream;
00116 stream << *this;
00117 return stream.str();
00118 }
00119
00120 static TSize<T> parse(const std::string& _value)
00121 {
00122 TSize<T> result;
00123 std::istringstream stream(_value);
00124 stream >> result.width >> result.height;
00125 if (stream.fail()) return TSize<T>();
00126 else
00127 {
00128 int item = stream.get();
00129 while (item != -1)
00130 {
00131 if (item != ' ' && item != '\t') return TSize<T>();
00132 item = stream.get();
00133 }
00134 }
00135 return result;
00136 }
00137
00138 friend std::ostream& operator << ( std::ostream& _stream, const TSize<T>& _value )
00139 {
00140 _stream << _value.width << " " << _value.height;
00141 return _stream;
00142 }
00143
00144 friend std::istream& operator >> ( std::istream& _stream, TSize<T>& _value )
00145 {
00146 _stream >> _value.width >> _value.height;
00147 if (_stream.fail()) _value.clear();
00148 return _stream;
00149 }
00150
00151 };
00152
00153 }
00154 }
00155
00156 #endif // __MYGUI_TSIZE_H__