IDS peak IPL v1.17.2
Loading...
Searching...
No Matches
peak_common_version.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
16#include <cstdint>
17#include <sstream>
18#include <string>
19#include <tuple>
20
21namespace peak
22{
23namespace common
24{
25
37{
38
39public:
40 Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch);
41
51 PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const;
52
62 PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const;
63
73 PEAK_COMMON_NO_DISCARD uint32_t GetSubminor() const;
74
84 PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const;
85
94 PEAK_COMMON_NO_DISCARD bool operator==(const Version& other) const
95 {
96 return std::tie(other.m_major, other.m_minor, other.m_subminor, other.m_patch)
97 == std::tie(this->m_major, this->m_minor, this->m_subminor, this->m_patch);
98 }
99
109 {
110 return !(*this == other);
111 }
112
123 PEAK_COMMON_NO_DISCARD bool operator<(const Version& other) const
124 {
125 return std::tie(this->m_major, this->m_minor, this->m_subminor, this->m_patch)
126 < std::tie(other.m_major, other.m_minor, other.m_subminor, other.m_patch);
127 }
128
137 PEAK_COMMON_NO_DISCARD bool operator>(const Version& other) const
138 {
139 return other < *this;
140 }
141
151 friend std::ostream& operator<<(std::ostream& os, Version version)
152 {
153 return os << version.m_major << '.' << version.m_minor << '.' << version.m_subminor << '.' << version.m_patch;
154 }
155
164 {
165 std::ostringstream ss;
166 ss << *this;
167 return ss.str();
168 }
169
170private:
171 friend detail::BackendAccessor<Version>;
172
173 explicit Version(const detail::c_type_of_t<Version>& version)
174 : Version(version.major, version.minor, version.subminor, version.patch)
175 {}
176
177 explicit operator detail::c_type_of_t<Version>() const
178 {
179 return { this->GetMajor(), this->GetMinor(), this->GetSubminor(), this->GetPatch() };
180 }
181
182 std::uint32_t m_major{};
183 std::uint32_t m_minor{};
184 std::uint32_t m_subminor{};
185 std::uint32_t m_patch{};
186};
187
188inline Version::Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch)
189 : m_major{ major }
190 , m_minor{ minor }
191 , m_subminor{ subminor }
192 , m_patch{ patch }
193{}
194
195inline uint32_t Version::GetMajor() const
196{
197 return m_major;
198}
199
200inline uint32_t Version::GetMinor() const
201{
202 return m_minor;
203}
204
205inline uint32_t Version::GetSubminor() const
206{
207 return m_subminor;
208}
209
210inline uint32_t Version::GetPatch() const
211{
212 return m_patch;
213}
214
215} // namespace common
216} // namespace peak
Represents a structured version identifier with four components: major, minor, subminor,...
Definition peak_common_version.hpp:37
Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch)
Definition peak_common_version.hpp:188
friend std::ostream & operator<<(std::ostream &os, Version version)
Outputs the version in dot-separated string format (e.g., "1.2.3.4").
Definition peak_common_version.hpp:151
PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const
Retrieves the patch version component.
Definition peak_common_version.hpp:210
PEAK_COMMON_NO_DISCARD bool operator<(const Version &other) const
Checks if this version is less than another version.
Definition peak_common_version.hpp:123
PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const
Retrieves the minor version component.
Definition peak_common_version.hpp:200
PEAK_COMMON_NO_DISCARD bool operator==(const Version &other) const
Checks if two versions are equal.
Definition peak_common_version.hpp:94
PEAK_COMMON_NO_DISCARD uint32_t GetSubminor() const
Retrieves the subminor version component.
Definition peak_common_version.hpp:205
PEAK_COMMON_NO_DISCARD std::string ToString() const
Converts the version to its string representation (e.g., "1.2.3.4").
Definition peak_common_version.hpp:163
PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const
Retrieves the major version component.
Definition peak_common_version.hpp:195
PEAK_COMMON_NO_DISCARD bool operator>(const Version &other) const
Checks if this version is greater than another version.
Definition peak_common_version.hpp:137
PEAK_COMMON_NO_DISCARD bool operator!=(const Version &other) const
Checks if two versions are not equal.
Definition peak_common_version.hpp:108
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:94