2021-06-08 06:09:26 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2021-06-08 06:09:26 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Simple numeric version representation.
|
|
|
|
///
|
2021-06-14 07:23:29 +00:00
|
|
|
/// Based on QVersionNumber.
|
2021-06-08 06:09:26 +00:00
|
|
|
struct VersionNumber
|
|
|
|
{
|
|
|
|
explicit VersionNumber() = default;
|
|
|
|
|
2021-06-14 07:41:36 +00:00
|
|
|
VersionNumber(const std::initializer_list<Int64> & init)
|
2021-06-14 07:23:29 +00:00
|
|
|
: components(init)
|
2021-06-08 06:09:26 +00:00
|
|
|
{}
|
2021-06-14 07:41:36 +00:00
|
|
|
VersionNumber(Int64 major, Int64 minor = 0, Int64 patch = 0)
|
2021-06-14 07:23:29 +00:00
|
|
|
: components{major, minor, patch}
|
|
|
|
{}
|
2021-06-14 07:41:36 +00:00
|
|
|
VersionNumber(const std::vector<Int64> & components_)
|
2021-06-14 07:23:29 +00:00
|
|
|
: components(components_)
|
2021-06-08 06:09:26 +00:00
|
|
|
{}
|
|
|
|
|
2021-06-14 07:23:29 +00:00
|
|
|
/// Parse version number from string.
|
|
|
|
VersionNumber(std::string version);
|
2021-06-08 06:09:26 +00:00
|
|
|
|
|
|
|
/// NOTE: operator<=> can be used once libc++ will be upgraded.
|
2021-06-14 07:23:29 +00:00
|
|
|
bool operator<(const VersionNumber & rhs) const { return compare(rhs.components) < 0; }
|
|
|
|
bool operator<=(const VersionNumber & rhs) const { return compare(rhs.components) <= 0; }
|
|
|
|
bool operator==(const VersionNumber & rhs) const { return compare(rhs.components) == 0; }
|
|
|
|
bool operator>(const VersionNumber & rhs) const { return compare(rhs.components) > 0; }
|
|
|
|
bool operator>=(const VersionNumber & rhs) const { return compare(rhs.components) >= 0; }
|
2021-06-08 06:09:26 +00:00
|
|
|
|
|
|
|
std::string toString() const;
|
|
|
|
friend std::ostream & operator<<(std::ostream & os, const VersionNumber & v)
|
|
|
|
{
|
|
|
|
return os << v.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-06-14 07:41:36 +00:00
|
|
|
using Components = std::vector<Int64>;
|
2021-06-14 07:23:29 +00:00
|
|
|
Components components;
|
2021-06-08 06:09:26 +00:00
|
|
|
|
2021-06-14 07:23:29 +00:00
|
|
|
int compare(const VersionNumber & rhs) const;
|
2021-06-08 06:09:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|