Files
scylladb/version.hh
Glauber Costa 5d3c7165d2 version: use a tuple internally.
As Avi suggested, we can use a tuple to make some comparisons more natural.
However, instead of doing a make_tuple on the comparison only, we can go
further and store the tuple internally.

I am still keeping the outer type, so it can host convenience functions like
to_sstring() and current().

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-08-07 18:24:54 +03:00

53 lines
1.1 KiB
C++

#pragma once
#include "core/sstring.hh"
#include "core/print.hh"
#include <tuple>
namespace version {
class version {
std::tuple<uint8_t, uint8_t, uint16_t> _version;
public:
version(uint8_t x, uint8_t y = 0, uint16_t z = 0): _version(std::make_tuple(x, y, z)) {}
sstring to_sstring() {
return sprint("%d.%d.%d", std::get<0>(_version), std::get<1>(_version), std::get<2>(_version));
}
static version current() {
static version v(2, 1, 8);
return v;
}
bool operator==(version v) const {
return _version == v._version;
}
bool operator!=(version v) const {
return _version != v._version;
}
bool operator<(version v) const {
return _version < v._version;
}
bool operator<=(version v) {
return _version <= v._version;
}
bool operator>(version v) {
return _version > v._version;
}
bool operator>=(version v) {
return _version >= v._version;
}
};
inline const int native_protocol() {
return 3;
}
inline const sstring& release() {
static thread_local auto str_ver = version::current().to_sstring();
return str_ver;
}
}