summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/corelib/tools/version.cpp70
-rw-r--r--src/lib/corelib/tools/version.h46
2 files changed, 35 insertions, 81 deletions
diff --git a/src/lib/corelib/tools/version.cpp b/src/lib/corelib/tools/version.cpp
index dfb7f49b7..f653256b3 100644
--- a/src/lib/corelib/tools/version.cpp
+++ b/src/lib/corelib/tools/version.cpp
@@ -44,50 +44,6 @@
namespace qbs {
-Version::Version(int major, int minor, int patch, int buildNr)
- : m_major(major), m_minor(minor), m_patch(patch), m_build(buildNr)
-{
-}
-
-int Version::majorVersion() const
-{
- return m_major;
-}
-
-void Version::setMajorVersion(int major)
-{
- m_major = major;
-}
-
-int Version::minorVersion() const
-{
- return m_minor;
-}
-
-void Version::setMinorVersion(int minor)
-{
- m_minor = minor;
-}
-int Version::patchLevel() const
-{
- return m_patch;
-}
-
-void Version::setPatchLevel(int patch)
-{
- m_patch = patch;
-}
-
-int Version::buildNumber() const
-{
- return m_build;
-}
-
-void Version::setBuildNumber(int nr)
-{
- m_build = nr;
-}
-
Version Version::fromString(const QString &versionString, bool buildNumberAllowed)
{
QString pattern = QStringLiteral("(\\d+)"); // At least one number.
@@ -118,32 +74,6 @@ QString Version::toString(const QChar &separator, const QChar &buildSeparator) c
QString::number(m_patch), separator);
}
-int compare(const Version &lhs, const Version &rhs)
-{
- if (lhs.majorVersion() < rhs.majorVersion())
- return -1;
- if (lhs.majorVersion() > rhs.majorVersion())
- return 1;
- if (lhs.minorVersion() < rhs.minorVersion())
- return -1;
- if (lhs.minorVersion() > rhs.minorVersion())
- return 1;
- if (lhs.patchLevel() < rhs.patchLevel())
- return -1;
- if (lhs.patchLevel() > rhs.patchLevel())
- return 1;
- if (lhs.buildNumber() < rhs.buildNumber())
- return -1;
- if (lhs.buildNumber() > rhs.buildNumber())
- return 1;
- return 0;
-}
-
-VersionRange::VersionRange(const Version &minVersion, const Version &maxVersion)
- : minimum(minVersion), maximum(maxVersion)
-{
-}
-
VersionRange &VersionRange::narrowDown(const VersionRange &other)
{
if (other.minimum > minimum)
diff --git a/src/lib/corelib/tools/version.h b/src/lib/corelib/tools/version.h
index a0239a6e4..9e31d13b0 100644
--- a/src/lib/corelib/tools/version.h
+++ b/src/lib/corelib/tools/version.h
@@ -55,21 +55,23 @@ class QBS_EXPORT Version
{
public:
explicit Version(int majorVersion = 0, int minorVersion = 0, int patchLevel = 0,
- int buildNr = 0);
+ int buildNr = 0)
+ : m_major(majorVersion), m_minor(minorVersion), m_patch(patchLevel), m_build(buildNr)
+ { }
bool isValid() const { return m_major || m_minor || m_patch || m_build; }
- int majorVersion() const;
- void setMajorVersion(int majorVersion);
+ int majorVersion() const { return m_major; }
+ void setMajorVersion(int majorVersion) { m_major = majorVersion; }
- int minorVersion() const;
- void setMinorVersion(int minorVersion);
+ int minorVersion() const { return m_minor; }
+ void setMinorVersion(int minorVersion) { m_minor = minorVersion;}
- int patchLevel() const;
- void setPatchLevel(int patchLevel);
+ int patchLevel() const { return m_patch; }
+ void setPatchLevel(int patchLevel) { m_patch = patchLevel; }
- int buildNumber() const;
- void setBuildNumber(int nr);
+ int buildNumber() const { return m_build; }
+ void setBuildNumber(int nr) { m_build = nr; }
static Version fromString(const QString &versionString, bool buildNumberAllowed = false);
QString toString(const QChar &separator = QLatin1Char('.'),
@@ -86,7 +88,9 @@ class VersionRange
{
public:
VersionRange() = default;
- VersionRange(const Version &minVersion, const Version &maxVersion);
+ VersionRange(const Version &minVersion, const Version &maxVersion)
+ : minimum(minVersion), maximum(maxVersion)
+ { }
Version minimum;
Version maximum; // exclusive
@@ -94,7 +98,27 @@ public:
VersionRange &narrowDown(const VersionRange &other);
};
-QBS_EXPORT int compare(const Version &lhs, const Version &rhs);
+inline int compare(const Version &lhs, const Version &rhs)
+{
+ if (lhs.majorVersion() < rhs.majorVersion())
+ return -1;
+ if (lhs.majorVersion() > rhs.majorVersion())
+ return 1;
+ if (lhs.minorVersion() < rhs.minorVersion())
+ return -1;
+ if (lhs.minorVersion() > rhs.minorVersion())
+ return 1;
+ if (lhs.patchLevel() < rhs.patchLevel())
+ return -1;
+ if (lhs.patchLevel() > rhs.patchLevel())
+ return 1;
+ if (lhs.buildNumber() < rhs.buildNumber())
+ return -1;
+ if (lhs.buildNumber() > rhs.buildNumber())
+ return 1;
+ return 0;
+}
+
inline bool operator==(const Version &lhs, const Version &rhs) { return compare(lhs, rhs) == 0; }
inline bool operator!=(const Version &lhs, const Version &rhs) { return !operator==(lhs, rhs); }
inline bool operator<(const Version &lhs, const Version &rhs) { return compare(lhs, rhs) < 0; }