-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsize.h
132 lines (111 loc) · 2.74 KB
/
size.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef TAG_PARSER_SIZE_H
#define TAG_PARSER_SIZE_H
#include "./global.h"
#include <c++utilities/conversion/stringbuilder.h>
#include <cstdint>
#include <string>
#include <string_view>
namespace TagParser {
/*!
* \brief The Size class defines the size of a two-dimensional object using integer point precision.
*/
class TAG_PARSER_EXPORT Size {
public:
constexpr Size();
constexpr Size(std::uint32_t width, std::uint32_t height);
constexpr std::uint32_t width() const;
constexpr std::uint32_t height() const;
void setWidth(std::uint32_t value);
void setHeight(std::uint32_t value);
constexpr std::uint32_t resolution() const;
std::string_view abbreviation() const;
bool constexpr isNull() const;
bool constexpr operator==(const Size &other) const;
bool constexpr operator>=(const Size &other) const;
std::string toString() const;
private:
std::uint32_t m_width;
std::uint32_t m_height;
};
/*!
* \brief Constructs a new Size.
*/
constexpr Size::Size()
: m_width(0)
, m_height(0)
{
}
/*!
* \brief Constructs a new Size of the specified \a width and \a height.
*/
constexpr Size::Size(std::uint32_t width, std::uint32_t height)
: m_width(width)
, m_height(height)
{
}
/*!
* \brief Returns the width.
*/
constexpr std::uint32_t Size::width() const
{
return m_width;
}
/*!
* \brief Returns the height.
*/
constexpr std::uint32_t Size::height() const
{
return m_height;
}
/*!
* \brief Sets the width.
*/
inline void Size::setWidth(std::uint32_t value)
{
m_width = value;
}
/*!
* \brief Sets the height.
*/
inline void Size::setHeight(std::uint32_t value)
{
m_height = value;
}
/*!
* \brief Returns the resolution of the current instance (product of with and height).
*/
constexpr std::uint32_t Size::resolution() const
{
return m_width * m_height;
}
/*!
* \brief Returns an indication whether both the width and height is 0.
*/
constexpr bool Size::isNull() const
{
return (m_width == 0) && (m_height == 0);
}
/*!
* \brief Returns whether this instance equals \a other.
*/
constexpr bool Size::operator==(const Size &other) const
{
return (m_width == other.m_width) && (m_height == other.m_height);
}
/*!
* \brief Returns whether this instance is greater than \a other.
* \remarks Both dimensions must be greater. This operator does *not* take the resolution() into account.
*/
constexpr bool Size::operator>=(const Size &other) const
{
return (m_width >= other.m_width) && (m_height >= other.m_height);
}
/*!
* \brief Returns the string representation of the current size.
*/
inline std::string Size::toString() const
{
return CppUtilities::argsToString("width: ", m_width, ", height: ", m_height);
}
} // namespace TagParser
#endif // TAG_PARSER_SIZE_H