mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 00:32:35 +01:00
ircd::json: Default selection to all keys.
This commit is contained in:
parent
cb7d19f7a0
commit
fb1c7236ac
1 changed files with 19 additions and 16 deletions
|
@ -26,7 +26,7 @@ template<class tuple> struct keys;
|
||||||
/// array so you cannot rely on this for a key's index into the tuple.
|
/// array so you cannot rely on this for a key's index into the tuple.
|
||||||
template<class tuple>
|
template<class tuple>
|
||||||
struct ircd::json::keys
|
struct ircd::json::keys
|
||||||
:std::array<ircd::string_view, tuple::size()>
|
:std::array<string_view, tuple::size()>
|
||||||
{
|
{
|
||||||
struct selection;
|
struct selection;
|
||||||
struct include;
|
struct include;
|
||||||
|
@ -36,8 +36,7 @@ struct ircd::json::keys
|
||||||
|
|
||||||
operator vector_view<const string_view>() const;
|
operator vector_view<const string_view>() const;
|
||||||
|
|
||||||
explicit keys(const selection &);
|
constexpr keys(const selection & = {});
|
||||||
keys();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Selection of keys in a tuple represented by a bitset. Users generally
|
/// Selection of keys in a tuple represented by a bitset. Users generally
|
||||||
|
@ -48,14 +47,20 @@ struct ircd::json::keys<tuple>::selection
|
||||||
:std::bitset<tuple::size()>
|
:std::bitset<tuple::size()>
|
||||||
{
|
{
|
||||||
template<class closure>
|
template<class closure>
|
||||||
bool until(closure &&function) const;
|
constexpr bool until(closure &&function) const;
|
||||||
|
|
||||||
template<class closure>
|
template<class closure>
|
||||||
void for_each(closure &&function) const;
|
constexpr void for_each(closure &&function) const;
|
||||||
|
|
||||||
template<class it_a,
|
template<class it_a,
|
||||||
class it_b>
|
class it_b>
|
||||||
it_a transform(it_a it, const it_b end) const;
|
constexpr it_a transform(it_a it, const it_b end) const;
|
||||||
|
|
||||||
|
constexpr selection(const uint64_t &val = -1)
|
||||||
|
:std::bitset<tuple::size()>{val}
|
||||||
|
{}
|
||||||
|
|
||||||
|
static_assert(tuple::size() <= sizeof(uint64_t) * 8);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Construct this class with a list of keys you want to select for a given
|
/// Construct this class with a list of keys you want to select for a given
|
||||||
|
@ -66,7 +71,9 @@ struct ircd::json::keys<tuple>::include
|
||||||
:selection
|
:selection
|
||||||
{
|
{
|
||||||
include(const vector_view<const string_view> &list)
|
include(const vector_view<const string_view> &list)
|
||||||
|
:selection{0}
|
||||||
{
|
{
|
||||||
|
assert(this->none());
|
||||||
for(const auto &key : list)
|
for(const auto &key : list)
|
||||||
this->set(indexof<tuple>(key), true);
|
this->set(indexof<tuple>(key), true);
|
||||||
}
|
}
|
||||||
|
@ -84,8 +91,9 @@ struct ircd::json::keys<tuple>::exclude
|
||||||
:selection
|
:selection
|
||||||
{
|
{
|
||||||
exclude(const vector_view<const string_view> &list)
|
exclude(const vector_view<const string_view> &list)
|
||||||
|
:selection{}
|
||||||
{
|
{
|
||||||
this->set();
|
assert(this->all());
|
||||||
for(const auto &key : list)
|
for(const auto &key : list)
|
||||||
this->set(indexof<tuple>(key), false);
|
this->set(indexof<tuple>(key), false);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +110,7 @@ struct ircd::json::keys<tuple>::exclude
|
||||||
template<class tuple>
|
template<class tuple>
|
||||||
template<class it_a,
|
template<class it_a,
|
||||||
class it_b>
|
class it_b>
|
||||||
it_a
|
constexpr it_a
|
||||||
ircd::json::keys<tuple>::selection::transform(it_a it,
|
ircd::json::keys<tuple>::selection::transform(it_a it,
|
||||||
const it_b end)
|
const it_b end)
|
||||||
const
|
const
|
||||||
|
@ -122,7 +130,7 @@ const
|
||||||
|
|
||||||
template<class tuple>
|
template<class tuple>
|
||||||
template<class closure>
|
template<class closure>
|
||||||
void
|
constexpr void
|
||||||
ircd::json::keys<tuple>::selection::for_each(closure &&function)
|
ircd::json::keys<tuple>::selection::for_each(closure &&function)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -135,7 +143,7 @@ const
|
||||||
|
|
||||||
template<class tuple>
|
template<class tuple>
|
||||||
template<class closure>
|
template<class closure>
|
||||||
bool
|
constexpr bool
|
||||||
ircd::json::keys<tuple>::selection::until(closure &&function)
|
ircd::json::keys<tuple>::selection::until(closure &&function)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -152,12 +160,7 @@ const
|
||||||
//
|
//
|
||||||
|
|
||||||
template<class tuple>
|
template<class tuple>
|
||||||
ircd::json::keys<tuple>::keys()
|
constexpr
|
||||||
{
|
|
||||||
_key_transform<tuple>(this->begin(), this->end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class tuple>
|
|
||||||
ircd::json::keys<tuple>::keys(const selection &selection)
|
ircd::json::keys<tuple>::keys(const selection &selection)
|
||||||
{
|
{
|
||||||
selection.transform(this->begin(), this->end());
|
selection.transform(this->begin(), this->end());
|
||||||
|
|
Loading…
Reference in a new issue