ClickHouse/src/Common/VersionNumber.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.5 KiB
C++
Raw Normal View History

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