34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 42 #include "final/ftypes.h" 43 #include "final/util/fstring.h" 59 using size_type = std::size_t;
60 using size_reference = size_type&;
61 using area_type = std::size_t;
64 constexpr
FSize () noexcept =
default;
66 template<
typename WidthT,
typename HeightT
67 ,
typename = std::enable_if_t< std::is_arithmetic<WidthT>::value
68 && std::is_arithmetic<HeightT>::value >>
69 constexpr
FSize (WidthT, HeightT) noexcept;
72 constexpr
FSize (
const FSize&) noexcept =
default;
78 ~
FSize() noexcept =
default;
81 constexpr
auto operator = (
const FSize&) noexcept ->
FSize& =
default;
84 constexpr
auto operator = (
FSize&&) noexcept ->
FSize& =
default;
87 auto operator += (
const FSize&) noexcept ->
FSize&;
88 auto operator -= (
const FSize&) noexcept ->
FSize&;
91 auto getClassName()
const ->
FString;
92 constexpr
auto getWidth()
const noexcept -> size_type;
93 constexpr
auto getHeight()
const noexcept -> size_type;
94 constexpr
auto getArea()
const noexcept -> area_type;
97 constexpr
void setWidth (size_type) noexcept;
98 constexpr
void setHeight (size_type) noexcept;
99 constexpr
void setSize (
const FSize&) noexcept;
100 constexpr
void setSize (size_type, size_type) noexcept;
103 constexpr
auto isEmpty()
const noexcept -> bool;
106 constexpr
auto width_ref() & noexcept -> size_reference;
107 constexpr
auto height_ref() & noexcept -> size_reference;
110 void scaleBy (
int,
int) noexcept;
111 void scaleBy (
const FPoint&) noexcept;
112 constexpr
void swap (
FSize&) noexcept;
120 friend constexpr
auto operator < (
const FSize& s1,
const FSize& s2) ->
bool 122 return s1.width < s2.width && s1.height < s2.height;
125 friend constexpr
auto operator <= (
const FSize& s1,
const FSize& s2) ->
bool 127 return s1.width <= s2.width && s1.height <= s2.height;
130 friend constexpr
auto operator == (
const FSize& s1,
const FSize& s2) ->
bool 132 return s1.width == s2.width && s1.height == s2.height;
135 friend constexpr
auto operator != (
const FSize& s1,
const FSize& s2) ->
bool 137 return s1.width != s2.width || s1.height != s2.height;
140 friend constexpr
auto operator >= (
const FSize& s1,
const FSize& s2) ->
bool 142 return s1.width >= s2.width && s1.height >= s2.height;
145 friend constexpr
auto operator > (
const FSize& s1,
const FSize& s2) ->
bool 147 return s1.width > s2.width && s1.height > s2.height;
150 friend constexpr
auto operator + (
const FSize& s1,
const FSize& s2) ->
FSize 152 constexpr size_type max = std::numeric_limits<size_type>::max();
153 const size_type w = ( s1.width < max - s2.width) ? s1.width + s2.width : max;
154 const size_type h = ( s1.height < max - s2.height) ? s1.height + s2.height : max;
155 return {
FSize{w, h} };
158 friend constexpr
auto operator - (
const FSize& s1,
const FSize& s2) ->
FSize 160 const size_type w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0;
161 const size_type h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0;
162 return {
FSize{w, h} };
165 friend inline auto operator << (std::ostream& outstr,
const FSize& s) -> std::ostream&
167 outstr << s.width <<
" " << s.height;
171 friend inline auto operator >> (std::istream& instr,
FSize& s) -> std::istream&
176 if ( instr >> w >> h )
185 template<
typename W
idthT,
typename HeightT,
typename>
186 constexpr FSize::FSize (WidthT w, HeightT h) noexcept
187 : width{
static_cast<size_type
>(w > 0 ? w : 0)}
188 , height{
static_cast<size_type
>(h > 0 ? h : 0)}
192 inline auto FSize::getClassName()
const ->
FString 196 constexpr
auto FSize::getWidth()
const noexcept -> size_type
200 constexpr
auto FSize::getHeight()
const noexcept -> size_type
204 constexpr
auto FSize::getArea()
const noexcept -> area_type
205 {
return width * height; }
208 constexpr
void FSize::setWidth (size_type w) noexcept
212 constexpr
void FSize::setHeight (size_type h) noexcept
216 constexpr
void FSize::setSize (
const FSize& s) noexcept
223 constexpr
void FSize::setSize (size_type w, size_type h) noexcept
230 constexpr
auto FSize::isEmpty()
const noexcept ->
bool 231 {
return width == 0 && height == 0; }
234 constexpr
auto FSize::width_ref() & noexcept -> size_reference
238 constexpr
auto FSize::height_ref() & noexcept -> size_reference
242 constexpr
void FSize::swap (
FSize& s) noexcept
244 size_type tmp_width{width};
245 size_type tmp_height{height};
249 s.height = tmp_height;
Definition: class_template.cpp:25