@@ -40,24 +40,33 @@ namespace rexsapi
4040 explicit TRexsVersion (const std::string& version)
4141 {
4242 static std::regex regExpr{R"( ^(\d+)\.(\d+)$)" };
43+ static std::regex regExpr_semantic_versioning{R"( ^(\d+)\.(\d+)\.(\d+)$)" };
4344 std::smatch match;
4445 if (std::regex_search (version, match, regExpr)) {
4546 m_Major = static_cast <uint32_t >(std::stoul (match[1 ]));
4647 m_Minor = static_cast <uint32_t >(std::stoul (match[2 ]));
47- } else {
48+ m_Patch = 0 ;
49+ }
50+ else if (std::regex_search (version, match, regExpr_semantic_versioning)) {
51+ m_Major = static_cast <uint32_t >(std::stoul (match[1 ]));
52+ m_Minor = static_cast <uint32_t >(std::stoul (match[2 ]));
53+ m_Patch = static_cast <uint32_t >(std::stoul (match[3 ]));
54+ }
55+ else {
4856 throw TException{fmt::format (" not a valid version: '{}'" , version)};
4957 }
5058 }
5159
52- TRexsVersion (uint32_t major, uint32_t minor)
60+ TRexsVersion (uint32_t major, uint32_t minor, uint32_t patch= 0 )
5361 : m_Major{major}
5462 , m_Minor{minor}
63+ , m_Patch{patch}
5564 {
5665 }
5766
5867 friend bool operator ==(const TRexsVersion& lhs, const TRexsVersion& rhs) noexcept
5968 {
60- return lhs.getMajor () == rhs.getMajor () && lhs.getMinor () == rhs.getMinor ();
69+ return lhs.getMajor () == rhs.getMajor () && lhs.getMinor () == rhs.getMinor () && lhs. getPatch () == rhs. getPatch () ;
6170 }
6271
6372 friend bool operator !=(const TRexsVersion& lhs, const TRexsVersion& rhs) noexcept
@@ -67,12 +76,12 @@ namespace rexsapi
6776
6877 friend bool operator <(const TRexsVersion& lhs, const TRexsVersion& rhs) noexcept
6978 {
70- return lhs.getMajor () < rhs.getMajor () || (lhs.getMajor () == rhs.getMajor () && lhs.getMinor () < rhs.getMinor ());
79+ return lhs.getMajor () < rhs.getMajor () || (lhs.getMajor () == rhs.getMajor () && lhs.getMinor () < rhs.getMinor ()) || (lhs. getMajor () == rhs. getMajor () && lhs. getMinor () < rhs. getMinor () && lhs. getPatch () < rhs. getPatch ()) ;
7180 }
7281
7382 friend bool operator >(const TRexsVersion& lhs, const TRexsVersion& rhs) noexcept
7483 {
75- return lhs.getMajor () > rhs.getMajor () || (lhs.getMajor () == rhs.getMajor () && lhs.getMinor () > rhs.getMinor ());
84+ return lhs.getMajor () > rhs.getMajor () || (lhs.getMajor () == rhs.getMajor () && lhs.getMinor () > rhs.getMinor ()) || (lhs. getMajor () == rhs. getMajor () && lhs. getMinor () > rhs. getMinor () && lhs. getPatch () > rhs. getPatch ()) ;
7685 }
7786
7887 friend bool operator <=(const TRexsVersion& lhs, const TRexsVersion& rhs) noexcept
@@ -95,19 +104,25 @@ namespace rexsapi
95104 return m_Minor;
96105 }
97106
107+ uint32_t getPatch () const noexcept
108+ {
109+ return m_Patch;
110+ }
111+
98112 /* *
99113 * @brief Returns string representation of the version.
100114 *
101115 * @return std::string containing a major and a minor version number separated with a dot
102116 */
103117 std::string asString () const
104118 {
105- return fmt::format (" {}.{}" , m_Major, m_Minor);
119+ return (m_Major<= 1 ) ? fmt::format (" {}.{}" , m_Major, m_Minor) : fmt::format ( " {}.{}.{} " , m_Major, m_Minor, m_Patch );
106120 }
107121
108122 private:
109123 uint32_t m_Major;
110124 uint32_t m_Minor;
125+ uint32_t m_Patch;
111126 };
112127}
113128
@@ -122,7 +137,7 @@ namespace std
122137 struct hash <rexsapi::TRexsVersion> {
123138 std::size_t operator ()(const rexsapi::TRexsVersion& version) const noexcept
124139 {
125- return std::hash<uint64_t >{}(static_cast <uint64_t >(version.getMajor ()) * 100 + version.getMinor ());
140+ return std::hash<uint64_t >{}(static_cast <uint64_t >(version.getMajor ()) * 10000 + static_cast < uint64_t >( version.getMinor ()) * 100 + version. getPatch ());
126141 }
127142 };
128143}
0 commit comments