TeiaCareSDK  v0.1.0
TeiaCareSDK is a collection of reusable C++ components
Loading...
Searching...
No Matches
size.hpp
1// Copyright 2024 TeiaCare
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <string>
18
19namespace tc::sdk
20{
21/*!
22 * \class size
23 * \brief 2D size specified by a pair of width/height dimensions.
24 * \tparam T Dimensions type
25 *
26 */
27template <typename T>
28class size
29{
30public:
31 /*!
32 * \brief Default Constructor. Creates a default tc::sdk::size instance.
33 */
34 constexpr size() = default;
35
36 /*!
37 * \brief Copy Constructor. Copy a tc::sdk::size instance into another one.
38 */
39 constexpr size(const size&) = default;
40
41 /*!
42 * \brief Move Constructor. Copy a tc::sdk::size instance into another one.
43 */
44 constexpr size(size&&) = default;
45
46 /*!
47 * \brief Constructor. Creates tc::sdk::size instance with given width and height dimensions.
48 * \param w the width of the size.
49 * \param h the height of the size.
50 */
51 constexpr explicit size(T w, T h) noexcept
52 : _width{w}
53 , _height{h}
54 {
55 }
56
57 /*!
58 * \brief Assignment operator. Assign a tc::sdk::size instance to another one.
59 */
60 size& operator=(const size&) = default;
61
62 /*!
63 * \brief Move assignment operator. Assign a tc::sdk::size instance to another one.
64 */
65 size& operator=(size&&) = default;
66
67 /*!
68 * \brief Equality operator.
69 * \param other the size to compare against.
70 * \return true if the two sizes have the same dimensions.
71 */
72 constexpr inline bool operator==(const size& other) const noexcept
73 {
74 return _width == other._width && _height == other._height;
75 }
76
77 /*!
78 * \brief Inequality operator.
79 * \param other the size to compare against.
80 * \return true if the two sizes have the different dimensions.
81 */
82 constexpr inline bool operator!=(const size& other) const noexcept
83 {
84 return !operator==(other);
85 }
86
87 /*!
88 * \brief Check if the size is the null.
89 * \return true if both width and height are zero.
90 */
91 constexpr bool is_null() const noexcept
92 {
93 return _width == 0 && _height == 0;
94 }
95
96 /*!
97 * \brief Width dimension getter.
98 * \return Width dimension of the size.
99 */
100 constexpr inline T width() const noexcept
101 {
102 return _width;
103 }
104
105 /*!
106 * \brief Height dimension getter.
107 * \return Height dimension of the size.
108 */
109 constexpr inline T height() const noexcept
110 {
111 return _height;
112 }
113
114 /*!
115 * \brief Width coordinate setter. Set the width dimension of the size.
116 */
117 inline void set_width(T width) noexcept
118 {
119 _width = width;
120 }
121
122 /*!
123 * \brief Height coordinate setter. Set the height dimension of the size.
124 */
125 inline void set_height(T height) noexcept
126 {
127 _height = height;
128 }
129
130 /*!
131 * \brief Get the size string representation
132 * \return String representation of the current size.
133 */
134 constexpr std::string to_string() const
135 {
136 return std::string("(" + std::to_string(_width) + "x" + std::to_string(_height) + ")");
137 }
138
139 /*!
140 * \brief Output stream operator.
141 * \param stream the output stream to write into.
142 * \param s the size object to stream.
143 * \return reference to the output stream operator, with the size string representation written into it.
144 */
145 friend std::ostream& operator<<(std::ostream& stream, const size& s)
146 {
147 return stream << s.to_string();
148 }
149
150private:
151 T _width{};
152 T _height{};
153};
154
155}
Thread safe, blocking queue.
2D size specified by a pair of width/height dimensions.
Definition size.hpp:29
constexpr size(T w, T h) noexcept
Constructor. Creates tc::sdk::size instance with given width and height dimensions.
Definition size.hpp:51
constexpr size(const size &)=default
Copy Constructor. Copy a tc::sdk::size instance into another one.
constexpr T width() const noexcept
Width dimension getter.
Definition size.hpp:100
void set_width(T width) noexcept
Width coordinate setter. Set the width dimension of the size.
Definition size.hpp:117
void set_height(T height) noexcept
Height coordinate setter. Set the height dimension of the size.
Definition size.hpp:125
constexpr bool is_null() const noexcept
Check if the size is the null.
Definition size.hpp:91
size & operator=(const size &)=default
Assignment operator. Assign a tc::sdk::size instance to another one.
constexpr size()=default
Default Constructor. Creates a default tc::sdk::size instance.
friend std::ostream & operator<<(std::ostream &stream, const size &s)
Output stream operator.
Definition size.hpp:145
constexpr bool operator==(const size &other) const noexcept
Equality operator.
Definition size.hpp:72
size & operator=(size &&)=default
Move assignment operator. Assign a tc::sdk::size instance to another one.
constexpr std::string to_string() const
Get the size string representation.
Definition size.hpp:134
constexpr T height() const noexcept
Height dimension getter.
Definition size.hpp:109
constexpr bool operator!=(const size &other) const noexcept
Inequality operator.
Definition size.hpp:82
constexpr size(size &&)=default
Move Constructor. Copy a tc::sdk::size instance into another one.