40 template <
typename T, std::
size_t N, std::
size_t Mandatory = N>
43 static_assert(N > 0,
"The number of version components may not be smaller than 1");
44 static_assert(N >= Mandatory,
45 "The number of mandatory components may not be larger than the total number of components");
53 template <
typename ... Other>
66 :
Version {version.split(QLatin1Char(
'.'))}
83 static_assert(N >= 1,
"The number of version components is too small");
84 return m_components[0];
89 static_assert(N >= 2,
"The number of version components is too small");
90 return m_components[1];
95 static_assert(N >= 3,
"The number of version components is too small");
96 return m_components[2];
101 static_assert(N >= 4,
"The number of version components is too small");
102 return m_components[3];
107 return m_components.at(i);
110 operator QString()
const
113 std::size_t lastSignificantIndex = N - 1;
114 while ((lastSignificantIndex > 0) && ((*
this)[lastSignificantIndex] == 0))
115 --lastSignificantIndex;
117 if (lastSignificantIndex + 1 < Mandatory)
118 lastSignificantIndex = Mandatory - 1;
120 QString res = QString::number((*
this)[0]);
121 for (std::size_t i = 1; i <= lastSignificantIndex; ++i)
122 res += QLatin1Char(
'.') + QString::number((*
this)[i]);
142 template <
typename StringClassWithSplitMethod>
151 qDebug() <<
"Error parsing version:" << error.
message();
152 return defaultVersion;
159 template <
typename StringsList>
162 if ((
static_cast<std::size_t
>(versionParts.size()) > N)
163 || (
static_cast<std::size_t
>(versionParts.size()) < Mandatory))
165 throw RuntimeError(QLatin1String(
"Incorrect number of version components"));
170 for (std::size_t i = 0; i < static_cast<std::size_t>(versionParts.size()); ++i)
172 res[i] =
static_cast<T
>(versionParts[
static_cast<typename StringsList::size_type
>(i)].toInt(&ok));
174 throw RuntimeError(QLatin1String(
"Can not parse version component"));
179 template <
typename StringsList>
181 : m_components (parseList(versionParts))
188 template <
typename T, std::
size_t N, std::
size_t Mandatory>
191 return !(left == right);
194 template <
typename T, std::
size_t N, std::
size_t Mandatory>
197 return (right < left);
200 template <
typename T, std::
size_t N, std::
size_t Mandatory>
203 return !(left > right);
206 template <
typename T, std::
size_t N, std::
size_t Mandatory>
209 return !(left < right);
QString message() const noexcept
static ComponentsArray parseList(const StringsList &versionParts)
static Version tryParse(const StringClassWithSplitMethod &s, const Version &defaultVersion)
friend bool operator<(const ThisType &left, const ThisType &right)
Version(const QByteArray &version)
Creates version from byte array in format "x.y.z".
ComponentsArray m_components
constexpr ComponentType minorNumber() const
Version(const StringsList &versionParts)
Version< T, N, Mandatory > ThisType
Version(const QString &version)
Creates version from string in format "x.y.z".
std::array< T, N > ComponentsArray
friend bool operator==(const ThisType &left, const ThisType &right)
constexpr Version(Other ... components)
constexpr ComponentType patchNumber() const
constexpr ComponentType operator[](const std::size_t i) const
constexpr bool isValid() const
constexpr ComponentType revisionNumber() const
constexpr ComponentType majorNumber() const
constexpr Version()=default
bool operator!=(const Digest32< N > &left, const Digest32< N > &right)
constexpr bool operator>(const Version< T, N, Mandatory > &left, const Version< T, N, Mandatory > &right)
constexpr bool operator>=(const Version< T, N, Mandatory > &left, const Version< T, N, Mandatory > &right)
constexpr bool operator<=(const Version< T, N, Mandatory > &left, const Version< T, N, Mandatory > &right)