ECSTASY
All in the name
Loading...
Searching...
No Matches
Or.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_QUERY_MODIFIERS_OR_HPP_
13#define ECSTASY_QUERY_MODIFIERS_OR_HPP_
14
15#include "BinaryModifier.hpp"
18
20{
34 template <bool AutoLock, Queryable Q1, Queryable Q2, Queryable... Qs>
35 class OrImpl
36 : public BinaryModifier<OrImpl<AutoLock, Q1, Q2, Qs...>, AutoLock, util::meta::add_optional, Q1, Q2, Qs...> {
39 BinaryModifier<OrImpl<AutoLock, Q1, Q2, Qs...>, AutoLock, util::meta::add_optional, Q1, Q2, Qs...>;
40
41 public:
52 OrImpl(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
53 : ModifierClass(firstOperand, secondOperand, otherOperands...)
54 {
55 }
56
71 template <size_t operandId>
72 [[nodiscard]] inline typename ModifierClass::template OperandData<operandId> getOperandData(size_t index)
73 {
74 auto &operand = std::get<operandId>(this->_operands);
75
76 if (index < getQueryableMask(operand).size() && getQueryableMask(operand)[index])
77 return getQueryableData(operand, index);
78 return std::nullopt;
79 }
80
87 inline void reloadMask()
88 {
89 if constexpr (sizeof...(Qs) > 0)
91 else {
92 auto &leftOperand = std::get<0>(this->_operands);
93 auto &rightOperand = std::get<1>(this->_operands);
94
95 if (ecstasy::query::getQueryableMask(leftOperand).size()
96 > ecstasy::query::getQueryableMask(rightOperand).size()) {
97 this->_mask = ecstasy::query::getQueryableMask(leftOperand);
99 } else {
100 this->_mask = ecstasy::query::getQueryableMask(rightOperand);
102 }
103 }
104 }
105
106 private:
115 inline void combineMask(const util::BitSet &mask) noexcept
116 {
117 if (this->_mask.size() < mask.size())
118 this->_mask = util::BitSet(mask).inplaceOr(this->_mask);
119 else
120 this->_mask.inplaceOr(mask);
121 }
122
133 template <size_t... ints>
135 {
136 (void)int_seq;
137 this->_mask = getQueryableMask(std::get<0>(this->_operands));
138 combineMask(getQueryableMask(std::get<1>(this->_operands)));
139 std::ignore = std::make_tuple((combineMask(getQueryableMask(std::get<ints + 2>(this->_operands))), 0)...);
140 }
141 };
142
158 template <Queryable Q1, Queryable Q2, Queryable... Qs>
159 [[nodiscard]] auto constexpr Or(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
160 {
161 return OrImpl<false, Q1, Q2, Qs...>(firstOperand, secondOperand, otherOperands...);
162 }
163} // namespace ecstasy::query::modifier
164
165#endif /* !ECSTASY_QUERY_MODIFIERS_OR_HPP_ */
Contains the concepts for queryable objects.
Add std::optional to a type if required.
Base class of query modifier operating on at least two queryables.
Binary query modifier which performs a or between at least two queryables.
Definition Or.hpp:36
void combineOperandMasks(std::integer_sequence< size_t, ints... > int_seq)
Combine all the operands' bitmasks.
Definition Or.hpp:134
OrImpl(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
Construct a new Or Queryable modifier.
Definition Or.hpp:52
ModifierClass::template OperandData< operandId > getOperandData(size_t index)
Get a std::optional filled with the data of the specified operand at index index if existing.
Definition Or.hpp:72
void reloadMask()
Update the mask to be up to date with the operands bitmasks.
Definition Or.hpp:87
void combineMask(const util::BitSet &mask) noexcept
Combine the current bitmask with the given one.
Definition Or.hpp:115
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
BitSet & inplaceOr(BitSet const &other) noexcept
Performs a bitwise OR with this set and other in place without resizing this.
Definition BitSet.cpp:136
Defines a type that can be queried.
T make_tuple(T... args)
Namespaces regrouping all the available query modifiers.
Definition And.hpp:19
constexpr queryable_data_t< Q > getQueryableData(Q &queryable, size_t index)
Get the query data at the given index.
constexpr const util::BitSet & getQueryableMask(const Q &queryable)
Get the mask of the queryable object.
Placeholder for Or.
Definition Or.hpp:31
Add optional to a type if required.