ECSTASY
All in the name
Loading...
Searching...
No Matches
Queryable.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_QUERY_CONCEPTS_QUERYABLE_HPP_
13#define ECSTASY_QUERY_CONCEPTS_QUERYABLE_HPP_
14
15#include <concepts>
16#include <cstddef>
17
19
20namespace util
21{
22 class BitSet;
23}
24
25namespace ecstasy::query
26{
27 // clang-format off
28
41 template <typename Q>
42 concept QueryableObject = requires(Q &queryable, Q const &cqueryable, std::size_t index) {
44 typename Q::QueryData;
45
47 { cqueryable.getMask() } -> std::same_as<util::BitSet const &>;
48
50 { queryable.getQueryData(index) } -> std::same_as<typename Q::QueryData>;
51 };
52
67 template <typename Q>
68 concept ConstQueryableObject = QueryableObject<Q> && requires(const Q &cqueryable, std::size_t index) {
70 typename Q::ConstQueryData;
71
73 { cqueryable.getQueryData(index) } -> std::same_as<typename Q::ConstQueryData>;
74 };
75
90 template <typename W>
91 concept QueryableWrapper = requires(W const &cwrapper) {
93 typename W::WrappedType;
94
96 { cwrapper->getMask() } -> std::same_as<util::BitSet const &>;
97 }
98 &&
99 (
101 (
103 requires(W const &cwrapper, std::size_t index) {
105 { cwrapper->getQueryData(index) } -> std::same_as<typename W::WrappedType::QueryData>;
106 }
107 )
108 ||
110 (
111 std::is_const_v<typename W::WrappedType> &&
112 ConstQueryableObject<std::remove_const_t<typename W::WrappedType>> &&
113 requires(W const &cwrapper, std::size_t index) {
115 { cwrapper->getQueryData(index) } -> std::same_as<typename W::WrappedType::ConstQueryData>;
116 }
117 )
118 );
119 // clang-format on
120
133 template <typename Q>
136
150 template <Queryable Q>
152 using type = typename Q::QueryData;
153 };
154
156 template <ConstQueryableObject Q>
157 struct queryable_data<const Q> {
158 using type = typename Q::ConstQueryData;
159 };
160
162 template <QueryableWrapper W>
163 struct queryable_data<W> {
165 };
166
175 template <typename Q>
177
189 template <Queryable Q, bool ThreadSafe>
191 using type = Q;
192 };
193
195 template <thread::Lockable Q>
196 struct thread_safe_queryable<Q, true> {
198 };
199
209 template <typename Q, bool ThreadSafe = true>
211
224 template <typename T, bool ThreadSafe>
227 };
228
230 template <thread::Lockable T>
231 struct thread_safe_reference<T, true> {
233 };
234
244 template <typename T, bool ThreadSafe = true>
246
261 template <Queryable Q, bool AutoLock = false>
263 using type = Q &;
264 };
265
267 template <thread::Lockable Q>
268 struct queryable_qualifiers<Q, true> {
270 };
271
281 template <typename Q, bool AutoLock = false>
283
284 // clang-format off
299 // clang-format on
300 template <Queryable Q>
301 constexpr const util::BitSet &getQueryableMask(const Q &queryable)
302 {
303 if constexpr (QueryableWrapper<Q>)
304 return queryable->getMask();
305 else
306 return queryable.getMask();
307 }
308
309 // clang-format off
324 // clang-format on
325 template <Queryable Q>
326 constexpr queryable_data_t<Q> getQueryableData(Q &queryable, size_t index)
327 {
328 if constexpr (QueryableWrapper<Q>)
329 return queryable->getQueryData(index);
330 else
331 return queryable.getQueryData(index);
332 }
333
342 template <typename T>
343 struct is_queryable : public std::false_type {};
344
346 template <Queryable T>
347 struct is_queryable<T> : public std::true_type {};
348
357 template <typename T>
358 static constexpr inline bool is_queryable_v = is_queryable<T>::value;
359
372 template <bool AutoLock, Queryable... Qs>
373 struct views_allocator_size : public std::integral_constant<size_t, 0> {};
374
376 template <bool AutoLock, Queryable Q, Queryable... Qs>
377 struct views_allocator_size<AutoLock, Q, Qs...>
378 : public
379 // clang-format off
380 std::integral_constant<size_t, views_allocator_size<AutoLock, Qs...>::value> {};
381
383 template <thread::Lockable Q, Queryable... Qs>
384 struct views_allocator_size<true, Q, Qs...>
385 : public
386 // clang-format off
388 sizeof(thread_safe_queryable_t<Q, true>) +
389 views_allocator_size<true, Qs...>::value> {};
390 // clang-format on
391
401 template <bool AutoLock, Queryable... Qs>
402 size_t constexpr views_allocator_size_v = views_allocator_size<AutoLock, Qs...>::value;
403
404} // namespace ecstasy::query
405
406#endif /* !ECSTASY_QUERY_CONCEPTS_QUERYABLE_HPP_ */
Thread safe view of a Lockable object.
Thread safe view of a Lockable object.
Mimics the API of std::bitset but with the dynamic properties of std::vector<bool>
Definition BitSet.hpp:35
Defines a type that can be queried in a const context.
Definition Queryable.hpp:68
Defines a type that can be queried.
Defines a type that can be queried.
Definition Queryable.hpp:42
Defines a type that can be queried through a wrapper.
Definition Queryable.hpp:91
Defines a type that can be locked.
Definition Lockable.hpp:30
Namespace regrouping the internal ecstasy query system.
Definition Condition.hpp:18
typename thread_safe_queryable< Q, ThreadSafe >::type thread_safe_queryable_t
Alias for the thread safe type of a queryable type.
typename queryable_data< Q >::type queryable_data_t
Alias for the query data type of a queryable object.
size_t constexpr views_allocator_size_v
Helper for views_allocator_size<AutoLock, Qs...>::value.
static constexpr bool is_queryable_v
Helper for is_queryable<T>::value.
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.
typename thread_safe_reference< T, ThreadSafe >::type thread_safe_reference_t
Alias for the reference type of a maybe thread safe type.
constexpr const util::BitSet & getQueryableMask(const Q &queryable)
Get the mask of the queryable object.
Namespace regrouping helpers used by ecstasy but not specific to ecstasy.
Definition Queryable.hpp:21
Checks if the given type match the Queryable concept.
typename queryable_data< typename W::WrappedType >::type type
Get the query data type of a queryable object.
typename Q::QueryData type
thread_safe_queryable_t< Q, true > type
Get the queryable type with the correct qualifiers.
Get the thread safe type of a queryable type.
Get the reference type of a maybe thread safe type.
Get the size of the allocator required for the given queryable types.