ECSTASY
All in the name
Loading...
Searching...
No Matches
Maybe.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_QUERY_MODIFIER_MAYBE_HPP_
13#define ECSTASY_QUERY_MODIFIER_MAYBE_HPP_
14
15#include <optional>
16#include <type_traits>
17
18#include "Modifier.hpp"
20#include "util/BitSet.hpp"
21#include "util/meta/Traits.hpp"
23
25{
37 template <Queryable Q, bool AutoLock = false>
38 class Maybe : public Modifier<AutoLock> {
39 public:
42
45
48
57 Maybe(Q &internal) : _internal(internal)
58 {
59 adjustMask(getQueryableMask(internal).size());
60 }
61
72 [[nodiscard]] constexpr const util::BitSet &getMask() const noexcept
73 {
74 return _mask;
75 }
76
90 [[nodiscard]] constexpr QueryData getQueryData(size_t index)
91 {
92 if (index < getQueryableMask(_internal).size() && getQueryableMask(_internal)[index])
93 return QueryData{getQueryableData(_internal, index)};
94 return std::nullopt;
95 }
96
105 constexpr void adjustMask(size_t maxSize)
106 {
107 if (maxSize > _mask.size()) {
108 _mask.resize(maxSize);
109 _mask.setAll();
110 }
111 }
112
113 private:
118 };
119} // namespace ecstasy::query::modifier
120
121#endif /* !ECSTASY_QUERY_MODIFIER_MAYBE_HPP_ */
Contains the concepts for queryable objects.
Helper types for parameter packs.
Add std::optional to a type if required.
Query modifier which returns a std::optional filled when the data if existing.
Definition Maybe.hpp:38
queryable_qualifiers_t< Q, AutoLock > Internal
Wrapped queryable.
Definition Maybe.hpp:41
constexpr QueryData getQueryData(size_t index)
Get a std::optional filled with the data at index index if existing.
Definition Maybe.hpp:90
Maybe(Q &internal)
Construct a new Maybe Queryable modifier.
Definition Maybe.hpp:57
util::meta::add_optional_t< queryable_data_t< Q > > QueryData
Queryable constaint.
Definition Maybe.hpp:47
constexpr void adjustMask(size_t maxSize)
Adjust the mask to be at least the maxSize.
Definition Maybe.hpp:105
constexpr const util::BitSet & getMask() const noexcept
Get the flipped mask of the internal queryable.
Definition Maybe.hpp:72
Internal _internal
Wrapped queryable.
Definition Maybe.hpp:115
util::BitSet _mask
Mask of the internal queryable.
Definition Maybe.hpp:117
Mimics the API of std::bitset but with the dynamic properties of std::vector<bool>
Definition BitSet.hpp:35
void resize(std::size_t size)
Changes the number of bits stored in this set.
Definition BitSet.hpp:199
constexpr std::size_t size() const noexcept
Definition BitSet.hpp:87
BitSet & setAll(bool value=true) noexcept
Sets all bits to the given value.
Definition BitSet.cpp:34
Defines a query modifier type.
Definition Modifier.hpp:31
Type erased base class for all query modifiers.
Namespaces regrouping all the available query modifiers.
Definition And.hpp:19
typename queryable_qualifiers< Q, AutoLock >::type queryable_qualifiers_t
Alias for the queryable type with the correct qualifiers.
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.
typename add_optional< T >::type add_optional_t
Helper to add_optional<T>::type.
Empty parameter pack helper type.
Definition Traits.hpp:28