ECSTASY
All in the name
Loading...
Searching...
No Matches
Xor.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_QUERY_MODIFIERS_XOR_HPP_
13#define ECSTASY_QUERY_MODIFIERS_XOR_HPP_
14
15#include "BinaryModifier.hpp"
18
20{
36 template <bool AutoLock, Queryable Q1, Queryable Q2, Queryable... Qs>
37 class XorImpl
38 : public BinaryModifier<XorImpl<AutoLock, Q1, Q2, Qs...>, AutoLock, util::meta::add_optional, Q1, Q2, Qs...> {
41 BinaryModifier<XorImpl<AutoLock, Q1, Q2, Qs...>, AutoLock, util::meta::add_optional, Q1, Q2, Qs...>;
42
43 public:
54 XorImpl(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
55 : ModifierClass(firstOperand, secondOperand, otherOperands...)
56 {
57 }
58
73 template <size_t operandId>
74 [[nodiscard]] inline typename ModifierClass::template OperandData<operandId> getOperandData(size_t index)
75 {
76 auto &operand = std::get<operandId>(this->_operands);
77
78 if (index < getQueryableMask(operand).size() && getQueryableMask(operand)[index])
79 return getQueryableData(operand, index);
80 return std::nullopt;
81 }
82
89 inline void reloadMask()
90 {
91 if constexpr (sizeof...(Qs) > 0)
93 else {
94 auto &leftOperand = std::get<0>(this->_operands);
95 auto &rightOperand = std::get<1>(this->_operands);
96
97 if (getQueryableMask(leftOperand).size() > getQueryableMask(rightOperand).size()) {
98 this->_mask = getQueryableMask(leftOperand);
99 this->_mask.inplaceXor(getQueryableMask(rightOperand));
100 } else {
101 this->_mask = getQueryableMask(rightOperand);
102 this->_mask.inplaceXor(getQueryableMask(leftOperand));
103 }
104 }
105 }
106
107 private:
116 inline void combineMask(const util::BitSet &mask)
117 {
118 if (this->_mask.size() < mask.size())
119 this->_mask = util::BitSet(mask).inplaceXor(this->_mask);
120 else
121 this->_mask.inplaceXor(mask);
122 }
123
134 template <size_t... ints>
136 {
137 (void)int_seq;
138 this->_mask = getQueryableMask(std::get<0>(this->_operands));
139 combineMask(getQueryableMask(std::get<1>(this->_operands)));
140 std::ignore = std::make_tuple((combineMask(getQueryableMask(std::get<ints + 2>(this->_operands))), 0)...);
141 }
142 };
143
159 template <Queryable Q1, Queryable Q2, Queryable... Qs>
160 [[nodiscard]] auto constexpr Xor(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
161 {
162 return XorImpl<false, Q1, Q2, Qs...>(firstOperand, secondOperand, otherOperands...);
163 }
164} // namespace ecstasy::query::modifier
165
166#endif /* !ECSTASY_QUERY_MODIFIERS_XOR_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 xor between at least two queryables.
Definition Xor.hpp:38
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 Xor.hpp:74
void reloadMask()
Update the mask to be up to date with the operands bitmasks.
Definition Xor.hpp:89
void combineOperandMasks(std::integer_sequence< size_t, ints... > int_seq)
Combine all the operands' bitmasks.
Definition Xor.hpp:135
XorImpl(Q1 &firstOperand, Q2 &secondOperand, Qs &...otherOperands)
Construct a new Xor Queryable modifier.
Definition Xor.hpp:54
void combineMask(const util::BitSet &mask)
Combine the current bitmask with the given one.
Definition Xor.hpp:116
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 & inplaceXor(BitSet const &other) noexcept
Performs a bitwise XOR with this set and other in place without resizing this.
Definition BitSet.cpp:144
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 Xor.
Definition Xor.hpp:31
Add optional to a type if required.