mirror of
https://github.com/ceph/ceph
synced 2025-01-20 01:51:34 +00:00
denc: Clean up tuples even more
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
This commit is contained in:
parent
dcd6d70eef
commit
98572fba64
@ -46,6 +46,8 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
|
|
||||||
|
#include "common/convenience.h"
|
||||||
|
|
||||||
template<typename T, typename=void>
|
template<typename T, typename=void>
|
||||||
struct denc_traits {
|
struct denc_traits {
|
||||||
static constexpr bool supported = false;
|
static constexpr bool supported = false;
|
||||||
@ -1120,46 +1122,6 @@ private:
|
|||||||
"Zero-length tuples are not supported.");
|
"Zero-length tuples are not supported.");
|
||||||
using container = std::tuple<Ts...>;
|
using container = std::tuple<Ts...>;
|
||||||
|
|
||||||
template<typename U = container, size_t... Is>
|
|
||||||
static std::enable_if_t<denc_traits<U>::featured>
|
|
||||||
bound_encode_helper(const U& s, size_t& p,
|
|
||||||
std::uint64_t f,
|
|
||||||
std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p, f), ..., void());
|
|
||||||
}
|
|
||||||
template<typename U = container, size_t... Is>
|
|
||||||
static std::enable_if_t<!denc_traits<U>::featured>
|
|
||||||
bound_encode_helper(const U& s, size_t& p,
|
|
||||||
std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p), ..., void());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U = container, size_t... Is>
|
|
||||||
static std::enable_if_t<denc_traits<U>::featured>
|
|
||||||
encode_helper(const U& s, buffer::list::contiguous_appender& p,
|
|
||||||
std::uint64_t f,
|
|
||||||
std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p, f), ..., void());
|
|
||||||
}
|
|
||||||
template<typename U = container, size_t... Is>
|
|
||||||
static std::enable_if_t<!denc_traits<U>::featured>
|
|
||||||
encode_helper(const U& s, buffer::list::contiguous_appender& p,
|
|
||||||
std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p), ..., void());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t... Is>
|
|
||||||
static void decode_helper(container& s, buffer::ptr::iterator& p,
|
|
||||||
std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p), ..., void());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U = container, size_t... Is>
|
|
||||||
static std::enable_if_t<!denc_traits<U>::need_contiguous>
|
|
||||||
decode_helper(U& s, buffer::list::iterator& p, std::index_sequence<Is...>) {
|
|
||||||
(denc(std::get<Is>(s), p), ..., void());
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static constexpr bool supported = true;
|
static constexpr bool supported = true;
|
||||||
@ -1171,33 +1133,53 @@ public:
|
|||||||
template<typename U = container>
|
template<typename U = container>
|
||||||
static std::enable_if_t<denc_traits<U>::featured>
|
static std::enable_if_t<denc_traits<U>::featured>
|
||||||
bound_encode(const container& s, size_t& p, uint64_t f) {
|
bound_encode(const container& s, size_t& p, uint64_t f) {
|
||||||
bound_encode_helper(s, p, f, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p, f] (const auto& e) {
|
||||||
|
if constexpr (denc_traits<std::decay_t<decltype(p)>>::featured) {
|
||||||
|
denc(e, p, f);
|
||||||
|
} else {
|
||||||
|
denc(e, p);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
template<typename U = container>
|
template<typename U = container>
|
||||||
static std::enable_if_t<!denc_traits<U>::featured>
|
static std::enable_if_t<!denc_traits<U>::featured>
|
||||||
bound_encode(const container& s, size_t& p) {
|
bound_encode(const container& s, size_t& p) {
|
||||||
bound_encode_helper(s, p, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p] (const auto& e) {
|
||||||
|
denc(e, p);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U = container>
|
template<typename U = container>
|
||||||
static std::enable_if_t<denc_traits<U>::featured>
|
static std::enable_if_t<denc_traits<U>::featured>
|
||||||
encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f) {
|
encode(const container& s, buffer::list::contiguous_appender& p, uint64_t f) {
|
||||||
encode_helper(s, p, f, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p, f] (const auto& e) {
|
||||||
|
if constexpr (denc_traits<std::decay_t<decltype(p)>>::featured) {
|
||||||
|
denc(e, p, f);
|
||||||
|
} else {
|
||||||
|
denc(e, p);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
template<typename U = container>
|
template<typename U = container>
|
||||||
static std::enable_if_t<!denc_traits<U>::featured>
|
static std::enable_if_t<!denc_traits<U>::featured>
|
||||||
encode(const container& s, buffer::list::contiguous_appender& p) {
|
encode(const container& s, buffer::list::contiguous_appender& p) {
|
||||||
encode_helper(s, p, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p] (const auto& e) {
|
||||||
|
denc(e, p);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decode(container& s, buffer::ptr::iterator& p, uint64_t f = 0) {
|
static void decode(container& s, buffer::ptr::iterator& p, uint64_t f = 0) {
|
||||||
decode_helper(s, p, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p] (auto& e) {
|
||||||
|
denc(e, p);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U = container>
|
template<typename U = container>
|
||||||
static std::enable_if_t<!denc_traits<U>::need_contiguous>
|
static std::enable_if_t<!denc_traits<U>::need_contiguous>
|
||||||
decode(container& s, buffer::list::iterator& p, uint64_t f = 0) {
|
decode(container& s, buffer::list::iterator& p, uint64_t f = 0) {
|
||||||
decode_helper(s, p, std::index_sequence_for<Ts...>{});
|
ceph::for_each(s, [&p] (auto& e) {
|
||||||
|
denc(e, p);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user