IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_version.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
11
13#include <peak/dll_interface/peak_dll_interface_util.hpp>
14
15#include <cstdint>
16#include <sstream>
17#include <string>
18
19
20namespace peak
21{
22namespace core
23{
24
32class Version final
33{
34public:
35 Version() = delete;
36 Version(uint32_t major, uint32_t minor, uint32_t patch);
37 ~Version() = default;
38 Version(const Version& other) = default;
39 Version& operator=(const Version& other) = default;
40 Version(Version&& other) = default;
41 Version& operator=(Version&& other) = default;
42
48 PEAK_COMMON_NO_DISCARD std::string ToString() const;
49
57 PEAK_COMMON_NO_DISCARD uint32_t Major() const;
58
66 PEAK_COMMON_NO_DISCARD uint32_t Minor() const;
67
71 PEAK_COMMON_DEPRECATED_MSG("Deprecated due to SemVer 2.0 migration. Use Patch() instead.")
72 PEAK_COMMON_NO_DISCARD uint32_t Subminor() const;
73
81 PEAK_COMMON_NO_DISCARD uint32_t Patch() const;
82
83private:
84 uint32_t m_major;
85 uint32_t m_minor;
86 uint32_t m_patch;
87};
88
89bool operator<(const Version& lhs, const Version& rhs);
90bool operator>(const Version& lhs, const Version& rhs);
91bool operator==(const Version& lhs, const Version& rhs);
92bool operator!=(const Version& lhs, const Version& rhs);
93
94} /* namespace core */
95} /* namespace peak */
96
97/* Implementation */
98namespace peak
99{
100namespace core
101{
102
103inline Version::Version(uint32_t major, uint32_t minor, uint32_t patch)
104 : m_major(major)
105 , m_minor(minor)
106 , m_patch(patch)
107{}
108
109inline std::string Version::ToString() const
110{
111 std::stringstream strStream;
112
113 strStream << Major() << '.' << Minor() << '.' << Patch();
114
115 return strStream.str();
116}
117
118inline uint32_t Version::Major() const
119{
120 return m_major;
121}
122
123inline uint32_t Version::Minor() const
124{
125 return m_minor;
126}
127
128inline uint32_t Version::Subminor() const
129{
130 return 0;
131}
132
133inline uint32_t Version::Patch() const
134{
135 return m_patch;
136}
137
138
139inline bool operator<(const Version& lhs, const Version& rhs)
140{
141 if (lhs.Major() < rhs.Major())
142 {
143 return true;
144 }
145 else if (lhs.Minor() < rhs.Minor())
146 {
147 return true;
148 }
149 else if (lhs.Patch() < rhs.Patch())
150 {
151 return true;
152 }
153
154 return false;
155}
156
157inline bool operator>(const Version& lhs, const Version& rhs)
158{
159 return rhs < lhs;
160}
161
162inline bool operator==(const Version& lhs, const Version& rhs)
163{
164 return !(lhs < rhs) && !(lhs > rhs);
165}
166
167inline bool operator!=(const Version& lhs, const Version& rhs)
168{
169 return !(lhs == rhs);
170}
171
172} /* namespace core */
173} /* namespace peak */
Implements versioning functionality.
Definition peak_version.hpp:33
PEAK_COMMON_NO_DISCARD uint32_t Major() const
Returns the major part of the version which is the first part of the version scheme separated by dots...
Definition peak_version.hpp:118
PEAK_COMMON_NO_DISCARD uint32_t Patch() const
Returns the minor part of the version which is the second part of the version scheme separated by dot...
Definition peak_version.hpp:133
PEAK_COMMON_NO_DISCARD uint32_t Subminor() const
Definition peak_version.hpp:128
Version & operator=(Version &&other)=default
PEAK_COMMON_NO_DISCARD std::string ToString() const
Returns the version as string.
Definition peak_version.hpp:109
Version(Version &&other)=default
PEAK_COMMON_NO_DISCARD uint32_t Minor() const
Returns the minor part of the version which is the second part of the version scheme separated by dot...
Definition peak_version.hpp:123
Version(const Version &other)=default
Version & operator=(const Version &other)=default
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
bool operator<(const Version &lhs, const Version &rhs)
Definition peak_version.hpp:139
bool operator>(const Version &lhs, const Version &rhs)
Definition peak_version.hpp:157
bool operator!=(const Version &lhs, const Version &rhs)
Definition peak_version.hpp:167
bool operator==(const Version &lhs, const Version &rhs)
Definition peak_version.hpp:162
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