IDS peak AFL v1.8.0
Loading...
Searching...
No Matches
peak_common_version.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
14
15#include <cstdint>
16#include <sstream>
17#include <string>
18#include <tuple>
19
20namespace peak
21{
22namespace common
23{
24
35class Version
36{
37
38public:
39 Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch);
40
50 PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const;
51
61 PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const;
62
72 PEAK_COMMON_NO_DISCARD uint32_t GetSubminor() const;
73
83 PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const;
84
93 PEAK_COMMON_NO_DISCARD bool operator==(const Version& other) const
94 {
95 return std::tie(other.m_major, other.m_minor, other.m_subminor, other.m_patch)
96 == std::tie(this->m_major, this->m_minor, this->m_subminor, this->m_patch);
97 }
98
107 PEAK_COMMON_NO_DISCARD bool operator!=(const Version& other) const
108 {
109 return !(*this == other);
110 }
111
122 PEAK_COMMON_NO_DISCARD bool operator<(const Version& other) const
123 {
124 return std::tie(this->m_major, this->m_minor, this->m_subminor, this->m_patch)
125 < std::tie(other.m_major, other.m_minor, other.m_subminor, other.m_patch);
126 }
127
136 PEAK_COMMON_NO_DISCARD bool operator>(const Version& other) const
137 {
138 return other < *this;
139 }
140
150 friend std::ostream& operator<<(std::ostream& os, Version version)
151 {
152 return os << version.m_major << '.' << version.m_minor << '.' << version.m_subminor << '.' << version.m_patch;
153 }
154
163 {
164 std::ostringstream ss;
165 ss << *this;
166 return ss.str();
167 }
168
169private:
170 std::uint32_t m_major{};
171 std::uint32_t m_minor{};
172 std::uint32_t m_subminor{};
173 std::uint32_t m_patch{};
174};
175
176inline Version::Version(uint32_t major, uint32_t minor, uint32_t subminor, uint32_t patch)
177 : m_major{ major }
178 , m_minor{ minor }
179 , m_subminor{ subminor }
180 , m_patch{ patch }
181{}
182
183inline uint32_t Version::GetMajor() const
184{
185 return m_major;
186}
187
188inline uint32_t Version::GetMinor() const
189{
190 return m_minor;
191}
192
193inline uint32_t Version::GetSubminor() const
194{
195 return m_subminor;
196}
197
198inline uint32_t Version::GetPatch() const
199{
200 return m_patch;
201}
202
203} // namespace common
204} // namespace peak
PEAK_COMMON_NO_DISCARD bool operator!=(const Version &other) const
Checks if two versions are not equal.
Definition peak_common_version.hpp:107
PEAK_COMMON_NO_DISCARD bool operator==(const Version &other) const
Checks if two versions are equal.
Definition peak_common_version.hpp:93
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:150
PEAK_COMMON_NO_DISCARD uint32_t GetSubminor() const
Retrieves the subminor version component.
Definition peak_common_version.hpp:193
PEAK_COMMON_NO_DISCARD bool operator>(const Version &other) const
Checks if this version is greater than another version.
Definition peak_common_version.hpp:136
PEAK_COMMON_NO_DISCARD bool operator<(const Version &other) const
Checks if this version is less than another version.
Definition peak_common_version.hpp:122
PEAK_COMMON_NO_DISCARD uint32_t GetPatch() const
Retrieves the patch version component.
Definition peak_common_version.hpp:198
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:162
PEAK_COMMON_NO_DISCARD uint32_t GetMajor() const
Retrieves the major version component.
Definition peak_common_version.hpp:183
PEAK_COMMON_NO_DISCARD uint32_t GetMinor() const
Retrieves the minor version component.
Definition peak_common_version.hpp:188
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22