IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_common_version.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
11#include <cstdint>
12#include <sstream>
13#include <string>
14#include <tuple>
15
16namespace peak
17{
18namespace common
19{
20
30{
31
32public:
37 PEAK_COMMON_DEPRECATED_MSG("Deprecated due to SemVer 2.0 migration. Use Version(major, minor, patch) instead.")
38 Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch);
39
43 Version(uint32_t major, uint32_t minor, uint32_t patch);
44
52 PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const;
53
61 PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const;
62
67 "Deprecated due to SemVer 2.0 migration. Always 0; use GetPatch() instead.") PEAK_COMMON_NO_DISCARD uint32_t
68 GetSubminor() const;
69
77 PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const;
78
87 PEAK_COMMON_NO_DISCARD bool operator==(const Version& other) const
88 {
89 return std::tie(other.m_major, other.m_minor, other.m_patch) == std::tie(this->m_major, this->m_minor, this->m_patch);
90 }
91
101 {
102 return !(*this == other);
103 }
104
115 PEAK_COMMON_NO_DISCARD bool operator<(const Version& other) const
116 {
117 return std::tie(this->m_major, this->m_minor, this->m_patch) < std::tie(other.m_major, other.m_minor, other.m_patch);
118 }
119
128 PEAK_COMMON_NO_DISCARD bool operator>(const Version& other) const
129 {
130 return other < *this;
131 }
132
142 friend std::ostream& operator<<(std::ostream& os, Version version)
143 {
144 return os << version.m_major << '.' << version.m_minor << '.' << version.m_patch;
145 }
146
155 {
156 std::ostringstream ss;
157 ss << *this;
158 return ss.str();
159 }
160
161private:
162 friend detail::BackendAccessor<Version>;
163
164 explicit Version(const detail::c_type_of_t<Version>& version)
165 : Version(version.major, version.minor, version.patch)
166 {}
167
168 explicit operator detail::c_type_of_t<Version>() const
169 {
170 auto cVersion = detail::c_type_of_t<Version>();
171 cVersion.major = GetMajor();
172 cVersion.minor = GetMinor();
173 cVersion.patch = GetPatch();
174 return cVersion;
175 }
176
177 std::uint32_t m_major{};
178 std::uint32_t m_minor{};
179 std::uint32_t m_subminor{};
180 std::uint32_t m_patch{};
181};
182
183inline Version::Version(uint32_t major, uint32_t minor, uint32_t patch)
184 : m_major{ major }
185 , m_minor{ minor }
186 , m_patch{ patch }
187{}
188
189inline Version::Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch)
190 : m_major{ major }
191 , m_minor{ minor }
192 , m_subminor{ subminor }
193 , m_patch{ patch }
194{}
195
196inline uint32_t Version::GetMajor() const
197{
198 return m_major;
199}
200
201inline uint32_t Version::GetMinor() const
202{
203 return m_minor;
204}
205
206inline uint32_t Version::GetSubminor() const
207{
208 return m_subminor;
209}
210
211inline uint32_t Version::GetPatch() const
212{
213 return m_patch;
214}
215
216} // namespace common
217} // namespace peak
Represents a structured version identifier following Semantic Versioning 2.0 (major....
Definition peak_common_version.hpp:30
Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch)
Constructs a Version object with legacy 4-digit layout.
Definition peak_common_version.hpp:189
friend std::ostream & operator<<(std::ostream &os, Version version)
Outputs the version in dot-separated string format (e.g., "1.2.3").
Definition peak_common_version.hpp:142
PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const
Retrieves the patch version component.
Definition peak_common_version.hpp:211
PEAK_COMMON_NO_DISCARD bool operator<(const Version &other) const
Checks if this version is less than another version.
Definition peak_common_version.hpp:115
PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const
Retrieves the minor version component.
Definition peak_common_version.hpp:201
PEAK_COMMON_DEPRECATED_MSG("Deprecated due to SemVer 2.0 migration. Always 0; use GetPatch() instead.") PEAK_COMMON_NO_DISCARD uint32_t GetSubminor() const
PEAK_COMMON_NO_DISCARD std::string ToString() const
Converts the version to its string representation (e.g., "1.2.3").
Definition peak_common_version.hpp:154
PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const
Retrieves the major version component.
Definition peak_common_version.hpp:196
PEAK_COMMON_NO_DISCARD bool operator>(const Version &other) const
Checks if this version is greater than another version.
Definition peak_common_version.hpp:128
PEAK_COMMON_NO_DISCARD bool operator!=(const Version &other) const
Checks if two versions are not equal.
Definition peak_common_version.hpp:100
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
#define PEAK_COMMON_DEPRECATED_MSG(MESSAGE)
Definition peak_common_defines.h:52
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89