MyGUI_TPoint.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_TPONT_H_
#define MYGUI_TPONT_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_StringUtility.h"
namespace MyGUI::types
{
template<typename T>
struct TPoint
{
T left{};
T top{};
TPoint() = default;
TPoint(T const& _left, T const& _top) :
left(_left),
top(_top)
{
}
TPoint& operator-=(TPoint const& _obj)
{
left -= _obj.left;
top -= _obj.top;
return *this;
}
TPoint& operator+=(TPoint const& _obj)
{
left += _obj.left;
top += _obj.top;
return *this;
}
TPoint operator-(TPoint const& _obj) const
{
return TPoint(left - _obj.left, top - _obj.top);
}
TPoint operator+(TPoint const& _obj) const
{
return TPoint(left + _obj.left, top + _obj.top);
}
template<typename U>
TPoint& operator=(TPoint<U> const& _obj)
{
left = _obj.left;
top = _obj.top;
return *this;
}
bool operator==(TPoint const& _obj) const
{
return ((left == _obj.left) && (top == _obj.top));
}
bool operator!=(TPoint const& _obj) const
{
return !((left == _obj.left) && (top == _obj.top));
}
void clear()
{
left = top = 0;
}
void set(T const& _left, T const& _top)
{
left = _left;
top = _top;
}
void swap(TPoint& _value)
{
TPoint tmp = _value;
_value = *this;
*this = tmp;
}
bool empty() const
{
return ((left == 0) && (top == 0));
}
std::string print() const
{
std::ostringstream stream;
stream << *this;
return stream.str();
}
static TPoint<T> parse(std::string_view _value)
{
return utility::parseValue<TPoint<T>>(_value);
}
friend std::ostream& operator<<(std::ostream& _stream, const TPoint<T>& _value)
{
_stream << _value.left << " " << _value.top;
return _stream;
}
friend std::istream& operator>>(std::istream& _stream, TPoint<T>& _value)
{
_stream >> _value.left >> _value.top;
if (_stream.fail())
_value.clear();
return _stream;
}
};
} // namespace MyGUI
#endif // MYGUI_TPONT_H_
MyGUI_Prerequest.h
MyGUI_StringUtility.h
MyGUI::types
Definition MyGUI_TCoord.h:15
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI::types::TPoint::operator-=
TPoint & operator-=(TPoint const &_obj)
Definition MyGUI_TPoint.h:30
MyGUI::types::TPoint::empty
bool empty() const
Definition MyGUI_TPoint.h:90
MyGUI::types::TPoint::operator==
bool operator==(TPoint const &_obj) const
Definition MyGUI_TPoint.h:62
MyGUI::types::TPoint::operator-
TPoint operator-(TPoint const &_obj) const
Definition MyGUI_TPoint.h:44
MyGUI::types::TPoint::parse
static TPoint< T > parse(std::string_view _value)
Definition MyGUI_TPoint.h:102
MyGUI::types::TPoint< int >::left
int left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const TPoint< T > &_value)
Definition MyGUI_TPoint.h:107
MyGUI::types::TPoint::TPoint
TPoint(T const &_left, T const &_top)
Definition MyGUI_TPoint.h:24
MyGUI::types::TPoint::clear
void clear()
Definition MyGUI_TPoint.h:72
MyGUI::types::TPoint::operator+
TPoint operator+(TPoint const &_obj) const
Definition MyGUI_TPoint.h:49
MyGUI::types::TPoint::set
void set(T const &_left, T const &_top)
Definition MyGUI_TPoint.h:77
MyGUI::types::TPoint::swap
void swap(TPoint &_value)
Definition MyGUI_TPoint.h:83
MyGUI::types::TPoint::operator+=
TPoint & operator+=(TPoint const &_obj)
Definition MyGUI_TPoint.h:37
MyGUI::types::TPoint::operator!=
bool operator!=(TPoint const &_obj) const
Definition MyGUI_TPoint.h:67
MyGUI::types::TPoint::TPoint
TPoint()=default
MyGUI::types::TPoint< int >::top
int top
Definition MyGUI_TPoint.h:20
MyGUI::types::TPoint::operator=
TPoint & operator=(TPoint< U > const &_obj)
Definition MyGUI_TPoint.h:55
MyGUI::types::TPoint::print
std::string print() const
Definition MyGUI_TPoint.h:95
MyGUI::types::TPoint::operator>>
friend std::istream & operator>>(std::istream &_stream, TPoint< T > &_value)
Definition MyGUI_TPoint.h:113