Instead of lengthy blurbs, switch to single-line, machine-readable standardized (https://spdx.dev) license identifiers. The Linux kernel switched long ago, so there is strong precedent. Three cases are handled: AGPL-only, Apache-only, and dual licensed. For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0), reasoning that our changes are extensive enough to apply our license. The changes we applied mechanically with a script, except to licenses/README.md. Closes #9937
109 lines
2.7 KiB
C++
109 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
#pragma once
|
|
|
|
#include <ostream>
|
|
#include <functional>
|
|
#include "utils/UUID.hh"
|
|
|
|
namespace raft {
|
|
namespace internal {
|
|
|
|
template<typename Tag>
|
|
class tagged_uint64 {
|
|
uint64_t _val;
|
|
public:
|
|
tagged_uint64() : _val(0) {}
|
|
explicit tagged_uint64(uint64_t v) : _val(v) {}
|
|
tagged_uint64(const tagged_uint64&) = default;
|
|
tagged_uint64(tagged_uint64&&) = default;
|
|
tagged_uint64& operator=(const tagged_uint64&) = default;
|
|
auto operator<=>(const tagged_uint64&) const = default;
|
|
explicit operator bool() const { return _val != 0; }
|
|
|
|
uint64_t get_value() const {
|
|
return _val;
|
|
}
|
|
operator uint64_t() const {
|
|
return get_value();
|
|
}
|
|
tagged_uint64& operator++() { // pre increment
|
|
++_val;
|
|
return *this;
|
|
}
|
|
tagged_uint64 operator++(int) { // post increment
|
|
uint64_t v = _val++;
|
|
return tagged_uint64(v);
|
|
}
|
|
tagged_uint64& operator--() { // pre decrement
|
|
--_val;
|
|
return *this;
|
|
}
|
|
tagged_uint64 operator--(int) { // post decrement
|
|
uint64_t v = _val--;
|
|
return tagged_uint64(v);
|
|
}
|
|
tagged_uint64 operator+(const tagged_uint64& o) const {
|
|
return tagged_uint64(_val + o._val);
|
|
}
|
|
tagged_uint64 operator-(const tagged_uint64& o) const {
|
|
return tagged_uint64(_val - o._val);
|
|
}
|
|
friend std::ostream& operator<<(std::ostream& os, const tagged_uint64<Tag>& u) {
|
|
os << u._val;
|
|
return os;
|
|
}
|
|
};
|
|
|
|
template<typename Tag>
|
|
struct tagged_id {
|
|
utils::UUID id;
|
|
bool operator==(const tagged_id& o) const {
|
|
return id == o.id;
|
|
}
|
|
bool operator<(const tagged_id& o) const {
|
|
return id < o.id;
|
|
}
|
|
explicit operator bool() const {
|
|
// The default constructor sets the id to nil, which is
|
|
// guaranteed to not match any valid id.
|
|
return id != utils::UUID();
|
|
}
|
|
static tagged_id create_random_id() { return tagged_id{utils::make_random_uuid()}; }
|
|
explicit tagged_id(const utils::UUID& uuid) : id(uuid) {}
|
|
tagged_id() = default;
|
|
};
|
|
|
|
template<typename Tag>
|
|
std::ostream& operator<<(std::ostream& os, const tagged_id<Tag>& id) {
|
|
os << id.id;
|
|
return os;
|
|
}
|
|
|
|
} // end of namespace internal
|
|
} // end of namespace raft
|
|
|
|
namespace std {
|
|
|
|
template<typename Tag>
|
|
struct hash<raft::internal::tagged_id<Tag>> {
|
|
size_t operator()(const raft::internal::tagged_id<Tag>& id) const {
|
|
return hash<utils::UUID>()(id.id);
|
|
}
|
|
};
|
|
|
|
template<typename Tag>
|
|
struct hash<raft::internal::tagged_uint64<Tag>> {
|
|
size_t operator()(const raft::internal::tagged_uint64<Tag>& val) const {
|
|
return hash<uint64_t>()(val);
|
|
}
|
|
};
|
|
|
|
} // end of namespace std
|
|
|