MyGUI_TSize.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_TSIZE_H_
#define MYGUI_TSIZE_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_StringUtility.h"
namespace MyGUI::types
{
template<typename T>
struct TSize
{
T width{};
T height{};
TSize() = default;
TSize(T const& _width, T const& _height) :
width(_width),
height(_height)
{
}
TSize& operator-=(TSize const& _obj)
{
width -= _obj.width;
height -= _obj.height;
return *this;
}
TSize& operator+=(TSize const& _obj)
{
width += _obj.width;
height += _obj.height;
return *this;
}
TSize operator-(TSize const& _obj) const
{
return TSize(width - _obj.width, height - _obj.height);
}
TSize operator+(TSize const& _obj) const
{
return TSize(width + _obj.width, height + _obj.height);
}
template<typename U>
TSize& operator=(TSize<U> const& _obj)
{
width = _obj.width;
height = _obj.height;
return *this;
}
bool operator==(TSize const& _obj) const
{
return ((width == _obj.width) && (height == _obj.height));
}
bool operator!=(TSize const& _obj) const
{
return !((width == _obj.width) && (height == _obj.height));
}
void clear()
{
width = height = 0;
}
void set(T const& _width, T const& _height)
{
width = _width;
height = _height;
}
void swap(TSize& _value)
{
TSize tmp = _value;
_value = *this;
*this = tmp;
}
bool empty() const
{
return ((width == 0) && (height == 0));
}
std::string print() const
{
std::ostringstream stream;
stream << *this;
return stream.str();
}
static TSize<T> parse(std::string_view _value)
{
return utility::parseValue<TSize<T>>(_value);
}
friend std::ostream& operator<<(std::ostream& _stream, const TSize<T>& _value)
{
_stream << _value.width << " " << _value.height;
return _stream;
}
friend std::istream& operator>>(std::istream& _stream, TSize<T>& _value)
{
_stream >> _value.width >> _value.height;
if (_stream.fail())
_value.clear();
return _stream;
}
};
} // namespace MyGUI
#endif // MYGUI_TSIZE_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::TSize< int >::width
int width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::TSize
TSize()=default
MyGUI::types::TSize::operator>>
friend std::istream & operator>>(std::istream &_stream, TSize< T > &_value)
Definition MyGUI_TSize.h:113
MyGUI::types::TSize::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const TSize< T > &_value)
Definition MyGUI_TSize.h:107
MyGUI::types::TSize::operator+
TSize operator+(TSize const &_obj) const
Definition MyGUI_TSize.h:49
MyGUI::types::TSize::empty
bool empty() const
Definition MyGUI_TSize.h:90
MyGUI::types::TSize::operator-
TSize operator-(TSize const &_obj) const
Definition MyGUI_TSize.h:44
MyGUI::types::TSize::parse
static TSize< T > parse(std::string_view _value)
Definition MyGUI_TSize.h:102
MyGUI::types::TSize< int >::height
int height
Definition MyGUI_TSize.h:20
MyGUI::types::TSize::operator+=
TSize & operator+=(TSize const &_obj)
Definition MyGUI_TSize.h:37
MyGUI::types::TSize::TSize
TSize(T const &_width, T const &_height)
Definition MyGUI_TSize.h:24
MyGUI::types::TSize::print
std::string print() const
Definition MyGUI_TSize.h:95
MyGUI::types::TSize::operator!=
bool operator!=(TSize const &_obj) const
Definition MyGUI_TSize.h:67
MyGUI::types::TSize::operator=
TSize & operator=(TSize< U > const &_obj)
Definition MyGUI_TSize.h:55
MyGUI::types::TSize::operator-=
TSize & operator-=(TSize const &_obj)
Definition MyGUI_TSize.h:30
MyGUI::types::TSize::set
void set(T const &_width, T const &_height)
Definition MyGUI_TSize.h:77
MyGUI::types::TSize::clear
void clear()
Definition MyGUI_TSize.h:72
MyGUI::types::TSize::operator==
bool operator==(TSize const &_obj) const
Definition MyGUI_TSize.h:62
MyGUI::types::TSize::swap
void swap(TSize &_value)
Definition MyGUI_TSize.h:83