ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::query::Select< SelectedQueryables > Struct Template Reference

Advanced Query. More...

#include <Select.hpp>

Classes

struct  FilterQueryables
 
struct  SorteredTie
 

Public Types

using SelectedTuple = std::tuple< SelectedQueryables &... >
 Resulting selected Queryable tuple.
 

Static Public Member Functions

template<typename Conditions = util::meta::Traits<>, Queryable FirstWhere, Queryable... Wheres>
static QueryImplementation< util::meta::Traits< SelectedQueryables... >, Conditions > where (FirstWhere &firstWhere, Wheres &...wheres)
 Execute a AND query with all the given Queryables but returns only the one in SelectedQueryables.
 

Static Private Member Functions

template<Queryable Q>
static constexpr bool isQueryableSelected () noexcept
 
template<Queryable... Qs>
static constexpr SelectedTuple tieQueryables (Qs &...queryables) noexcept
 
template<Queryable... Queryables>
static constexpr SelectedTuple filterQueryables (Queryables &...queryables) noexcept
 Isolate the given queryables to keep only the SelectedQueryables ones.
 

Detailed Description

template<Queryable... SelectedQueryables>
struct ecstasy::query::Select< SelectedQueryables >

Advanced Query.

It allows to select which data must be kept from a query request.

Note
Cannot do AutoLock at this scope because of variable lifetimes (see where method). For thread safety, queryables lock must be done before calling the where method.
Template Parameters
SelectedQueryablesQueryables to keep in the resulting query.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-22)

Definition at line 40 of file Select.hpp.

Member Typedef Documentation

◆ SelectedTuple

template<Queryable... SelectedQueryables>
using ecstasy::query::Select< SelectedQueryables >::SelectedTuple = std::tuple<SelectedQueryables &...>

Resulting selected Queryable tuple.

Definition at line 43 of file Select.hpp.

Member Function Documentation

◆ filterQueryables()

template<Queryable... SelectedQueryables>
template<Queryable... Queryables>
static constexpr SelectedTuple ecstasy::query::Select< SelectedQueryables >::filterQueryables ( Queryables &...  queryables)
inlinestaticconstexprprivatenoexcept

Isolate the given queryables to keep only the SelectedQueryables ones.

Template Parameters
Queryablesgiven queryables types.
Parameters
[in]queryablesgiven queryables.
Returns
SelectedTuple selected queryables.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-22)

Definition at line 239 of file Select.hpp.

240 {
241 return FilterQueryables<isQueryableSelected<typename util::meta::Traits<Queryables...>::First>(),
242 typename util::meta::Traits<Queryables...>::First>::value(std::forward<Queryables &>(queryables)...);
243 }
static constexpr bool isQueryableSelected() noexcept
Definition Select.hpp:57
Empty parameter pack helper type.
Definition Traits.hpp:28

◆ isQueryableSelected()

template<Queryable... SelectedQueryables>
template<Queryable Q>
static constexpr bool ecstasy::query::Select< SelectedQueryables >::isQueryableSelected ( )
inlinestaticconstexprprivatenoexcept

Definition at line 57 of file Select.hpp.

58 {
59 return util::meta::contains<Q, SelectedQueryables...>;
60 }
constexpr bool contains
Checks if the type T exists in the types Ts.
Definition contains.hpp:29

◆ tieQueryables()

template<Queryable... SelectedQueryables>
template<Queryable... Qs>
static constexpr SelectedTuple ecstasy::query::Select< SelectedQueryables >::tieQueryables ( Qs &...  queryables)
inlinestaticconstexprprivatenoexcept

Definition at line 129 of file Select.hpp.

130 {
131 static_assert(util::meta::type_set_eq_v<std::tuple<SelectedQueryables...>, std::tuple<Qs...>>,
132 "Missing queryables in where clause");
133 if constexpr (std::is_same_v<std::tuple<SelectedQueryables...>, std::tuple<Qs...>>)
134 return std::tie(std::forward<Qs &>(queryables)...);
135 else
136 return SorteredTie<>::template sort(std::forward<Qs &>(queryables)...);
137 }
T is_same_v
bool constexpr type_set_eq_v
Helper for type_set_eq.
T sort(T... args)
T tie(T... args)

◆ where()

template<Queryable... SelectedQueryables>
template<typename Conditions = util::meta::Traits<>, Queryable FirstWhere, Queryable... Wheres>
static QueryImplementation< util::meta::Traits< SelectedQueryables... >, Conditions > ecstasy::query::Select< SelectedQueryables >::where ( FirstWhere &  firstWhere,
Wheres &...  wheres 
)
inlinestatic

Execute a AND query with all the given Queryables but returns only the one in SelectedQueryables.

Warning
All queryables specified in SelectedQueryables must be passed as parameters.
Template Parameters
Conditionsutil::meta::Traits of multiple Condition.
FirstWhereFirst Queryable type.
WheresOthers Queryable types.
Parameters
[in]firstWherefirst Queryable instance.
[in]wheresothers Queryable instances.
Returns
QueryImplementation<util::meta::Traits<SelectedQueryables...>, Conditions> Resulting query that can be iterated.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-22)

Adjusts the masks only if required

Definition at line 265 of file Select.hpp.

267 {
269 if constexpr (is_queryable_with_adjust_v<FirstWhere>
270 || std::disjunction_v<is_queryable_with_adjust<Wheres>...>) {
271 size_t maxSize = std::max({getQueryableMask(firstWhere).size(), getQueryableMask(wheres).size()...});
272
273 adjustMask(firstWhere, maxSize);
274 (adjustMask(wheres, maxSize), ...);
275 }
276
277 util::BitSet mask = (util::BitSet(getQueryableMask(firstWhere)) &= ... &= getQueryableMask(wheres));
278
279 return QueryImplementation<util::meta::Traits<SelectedQueryables...>, Conditions>(
280 mask, filterQueryables(firstWhere, wheres...));
281 }
Mimics the API of std::bitset but with the dynamic properties of std::vector<bool>
Definition BitSet.hpp:35
constexpr std::size_t size() const noexcept
Definition BitSet.hpp:87
T max(T... args)
constexpr const util::BitSet & getQueryableMask(const Q &queryable)
Get the mask of the queryable object.
constexpr void adjustMask(T &queryable, size_t maxSize) noexcept
Adjust the queryable mask if needed.
static constexpr SelectedTuple filterQueryables(Queryables &...queryables) noexcept
Isolate the given queryables to keep only the SelectedQueryables ones.
Definition Select.hpp:239

The documentation for this struct was generated from the following file: