MyGUI
3.0.3
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #ifndef __MYGUI_TPONT_H__ 00024 #define __MYGUI_TPONT_H__ 00025 00026 #include "MyGUI_Prerequest.h" 00027 00028 namespace MyGUI 00029 { 00030 namespace types 00031 { 00032 template< typename T > struct TPoint 00033 { 00034 T left, top; 00035 00036 TPoint() : left( 0 ), top( 0 ) { } 00037 TPoint( T const& _left, T const& _top) : left( _left ), top( _top ) { } 00038 TPoint( TPoint const& o ) : left( o.left ), top( o.top ) { } 00039 00040 TPoint& operator-=( TPoint const& o ) 00041 { 00042 left -= o.left; 00043 top -= o.top; 00044 return *this; 00045 } 00046 00047 TPoint& operator+=( TPoint const& o ) 00048 { 00049 left += o.left; 00050 top += o.top; 00051 return *this; 00052 } 00053 00054 TPoint operator-( TPoint const& o ) const 00055 { 00056 return TPoint(left - o.left, top - o.top); 00057 } 00058 00059 TPoint operator+( TPoint const& o ) const 00060 { 00061 return TPoint(left + o.left, top + o.top); 00062 } 00063 00064 TPoint& operator=( TPoint const& o ) 00065 { 00066 left = o.left; 00067 top = o.top; 00068 return *this; 00069 } 00070 00071 template< typename U > 00072 TPoint& operator=( TPoint<U> const& o ) 00073 { 00074 left = o.left; 00075 top = o.top; 00076 return *this; 00077 } 00078 00079 bool operator==( TPoint const& o ) const 00080 { 00081 return ((left == o.left) && (top == o.top)); 00082 } 00083 00084 bool operator!=( TPoint const& o ) const 00085 { 00086 return ! ((left == o.left) && (top == o.top)); 00087 } 00088 00089 void clear() 00090 { 00091 left = top = 0; 00092 } 00093 00094 void set( T const& _left, T const& _top) 00095 { 00096 left = _left; 00097 top = _top; 00098 } 00099 00100 void swap(TPoint& _value) 00101 { 00102 TPoint tmp = _value; 00103 _value = *this; 00104 *this = tmp; 00105 } 00106 00107 bool empty() const 00108 { 00109 return ((left == 0) && (top == 0)); 00110 } 00111 00112 std::string print() const 00113 { 00114 std::ostringstream stream; 00115 stream << *this; 00116 return stream.str(); 00117 } 00118 00119 static TPoint<T> parse(const std::string& _value) 00120 { 00121 TPoint<T> result; 00122 std::istringstream stream(_value); 00123 stream >> result.left >> result.top; 00124 if (stream.fail()) return TPoint<T>(); 00125 else 00126 { 00127 int item = stream.get(); 00128 while (item != -1) 00129 { 00130 if (item != ' ' && item != '\t') return TPoint<T>(); 00131 item = stream.get(); 00132 } 00133 } 00134 return result; 00135 } 00136 00137 friend std::ostream& operator << ( std::ostream& _stream, const TPoint<T>& _value ) 00138 { 00139 _stream << _value.left << " " << _value.top; 00140 return _stream; 00141 } 00142 00143 friend std::istream& operator >> ( std::istream& _stream, TPoint<T>& _value ) 00144 { 00145 _stream >> _value.left >> _value.top; 00146 if (_stream.fail()) _value.clear(); 00147 return _stream; 00148 } 00149 00150 }; 00151 00152 } // namespace types 00153 } // namespace MyGUI 00154 00155 #endif // __MYGUI_TPONT_H__