Files
scylladb/version.hh
Glauber Costa ae2ce78ee6 version: change all fields to uint16_t
Ok, shame on me: the version string was so obviously correct that I only
verified that the comparisons were working as expected.

Turns out it isn't: http://lists.boost.org/boost-users/2006/12/24194.php

boost::format will treat uint8_t arguments as char, and therefore we will end
up with the version string misprinted.

We can just cast it to uint16_t before we print, but since this is not exactly
a struct that we will be using all the time, let's favor readability over
saving a few bytes, and change all fields to uint16_t.

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

53 lines
1.2 KiB
C++

#pragma once
#include "core/sstring.hh"
#include "core/print.hh"
#include <tuple>
namespace version {
class version {
std::tuple<uint16_t, uint16_t, uint16_t> _version;
public:
version(uint16_t x, uint16_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;
}
}