aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/VersionNumber.h
blob: 050c94b957498a62af6999892d290a42db139424 (plain) (blame)
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
#pragma once

#include <string>
#include <vector>
#include <base/types.h>


namespace DB
{

/// Simple numeric version representation.
struct VersionNumber
{
    explicit VersionNumber() = default;

    VersionNumber(const std::initializer_list<Int64> & init) : components(init) {}
    explicit VersionNumber(Int64 major, Int64 minor = 0, Int64 patch = 0) : components{major, minor, patch} {}
    explicit VersionNumber(const std::vector<Int64> & components_) : components(components_) {}

    /// Parse version number from string.
    explicit VersionNumber(std::string version);

    bool operator==(const VersionNumber & rhs) const = default;

    /// There might be negative version code which differs from default comparison.
    auto operator<=>(const VersionNumber & rhs) const { return compare(rhs); }

    std::string toString() const;

private:
    using Components = std::vector<Int64>;
    Components components;

    int compare(const VersionNumber & rhs) const;
};

}