summaryrefslogtreecommitdiffstats
path: root/depends/util/include/modutils.h
blob: 1fecd4d503b475832289064c4ccd596552d1767b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include <QString>
#include <QList>

#include "libutil_config.h"

class QUrl;

namespace Util
{
struct 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 &str, const int num) : numValid(true), number(num), string(str) {}
		explicit Section(const QString &str) : numValid(false), string(str) {}
		explicit Section() {}
		bool numValid;
		int number;
		QString string;

		inline bool operator!=(const Section &other) const
		{
			return (numValid && other.numValid) ? (number != other.number) : (string != other.string);
		}
		inline bool operator<(const Section &other) const
		{
			return (numValid && other.numValid) ? (number < other.number) : (string < other.string);
		}
		inline bool operator>(const Section &other) const
		{
			return (numValid && other.numValid) ? (number > other.number) : (string > other.string);
		}
	};
	QList<Section> m_sections;

	void parse();
};

LIBUTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval);
LIBUTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval);
}