From f93f867c3da084c6d6c5e3ed23896609cff0e692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 5 Oct 2015 01:47:27 +0200 Subject: NOISSUE dissolve util library --- logic/Version.h | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 logic/Version.h (limited to 'logic/Version.h') diff --git a/logic/Version.h b/logic/Version.h new file mode 100644 index 00000000..b5946ced --- /dev/null +++ b/logic/Version.h @@ -0,0 +1,110 @@ +#pragma once + +#include +#include + +#include "multimc_logic_export.h" + +class QUrl; + +struct MULTIMC_LOGIC_EXPORT Version +{ + Version(const QString &str); + Version() {} + + bool operator<(const Version &other) const; + bool operator<=(const Version &other) const; + bool operator>(const Version &other) const; + bool operator>=(const Version &other) const; + bool operator==(const Version &other) const; + bool operator!=(const Version &other) const; + + QString toString() const + { + return m_string; + } + +private: + QString m_string; + struct Section + { + explicit Section(const QString &fullString) + { + m_fullString = fullString; + int cutoff = m_fullString.size(); + for(int i = 0; i < m_fullString.size(); i++) + { + if(!m_fullString[i].isDigit()) + { + cutoff = i; + break; + } + } + auto numPart = m_fullString.leftRef(cutoff); + if(numPart.size()) + { + numValid = true; + m_numPart = numPart.toInt(); + } + auto stringPart = m_fullString.midRef(cutoff); + if(stringPart.size()) + { + m_stringPart = stringPart.toString(); + } + } + explicit Section() {} + bool numValid = false; + int m_numPart = 0; + QString m_stringPart; + QString m_fullString; + + inline bool operator!=(const Section &other) const + { + if(numValid && other.numValid) + { + return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart; + } + else + { + return m_fullString != other.m_fullString; + } + } + inline bool operator<(const Section &other) const + { + if(numValid && other.numValid) + { + if(m_numPart < other.m_numPart) + return true; + if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart) + return true; + return false; + } + else + { + return m_fullString < other.m_fullString; + } + } + inline bool operator>(const Section &other) const + { + if(numValid && other.numValid) + { + if(m_numPart > other.m_numPart) + return true; + if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart) + return true; + return false; + } + else + { + return m_fullString > other.m_fullString; + } + } + }; + QList
m_sections; + + void parse(); +}; + +MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const QString &version, const QString &interval); +MULTIMC_LOGIC_EXPORT bool versionIsInInterval(const Version &version, const QString &interval); + -- cgit v1.2.3