68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
/*
|
|
* Copyright (C) 2016 ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* This file is part of Scylla.
|
|
*
|
|
* Scylla is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Scylla is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "query-request.hh"
|
|
#include <experimental/optional>
|
|
|
|
// Wraps ring_position so it is compatible with old-style C++: default constructor,
|
|
// stateless comparators, yada yada
|
|
class compatible_ring_position {
|
|
const schema* _schema = nullptr;
|
|
// optional to supply a default constructor, no more
|
|
std::experimental::optional<dht::ring_position> _rp;
|
|
public:
|
|
compatible_ring_position() noexcept = default;
|
|
compatible_ring_position(const schema& s, const dht::ring_position& rp)
|
|
: _schema(&s), _rp(rp) {
|
|
}
|
|
compatible_ring_position(const schema& s, dht::ring_position&& rp)
|
|
: _schema(&s), _rp(std::move(rp)) {
|
|
}
|
|
const dht::token& token() const {
|
|
return _rp->token();
|
|
}
|
|
friend int tri_compare(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return x._rp->tri_compare(*x._schema, *y._rp);
|
|
}
|
|
friend bool operator<(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) < 0;
|
|
}
|
|
friend bool operator<=(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) <= 0;
|
|
}
|
|
friend bool operator>(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) > 0;
|
|
}
|
|
friend bool operator>=(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) >= 0;
|
|
}
|
|
friend bool operator==(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) == 0;
|
|
}
|
|
friend bool operator!=(const compatible_ring_position& x, const compatible_ring_position& y) {
|
|
return tri_compare(x, y) != 0;
|
|
}
|
|
};
|
|
|