Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::ecs::BasicQueryWithEntityIter< IsConst, Components > Class Template Referencefinal

Iterator for query results including the entity. More...

#include <iterator.hpp>

Inheritance diagram for helios::ecs::BasicQueryWithEntityIter< IsConst, Components >:
helios::utils::FunctionalAdapterBase< BasicQueryWithEntityIter< IsConst, Components... > >

Public Types

using ComponentManagerType
using iterator_category = std::bidirectional_iterator_tag
using iterator_concept = std::input_iterator_tag
using value_type
using reference = value_type
using pointer = void
using difference_type = ptrdiff_t

Public Member Functions

 BasicQueryWithEntityIter (std::span< const std::reference_wrapper< const Archetype > > archetypes, ComponentManagerType &components, size_t archetype_index, size_t entity_index, std::span< const ComponentTypeIndex > without_types={}) noexcept
 Constructs iterator for query results with entity.
 BasicQueryWithEntityIter (const BasicQueryWithEntityIter &) noexcept=default
 BasicQueryWithEntityIter (BasicQueryWithEntityIter &&) noexcept=default
 ~BasicQueryWithEntityIter () noexcept=default
BasicQueryWithEntityIteroperator= (const BasicQueryWithEntityIter &) noexcept=default
BasicQueryWithEntityIteroperator= (BasicQueryWithEntityIter &&) noexcept=default
BasicQueryWithEntityIteroperator++ ()
 Advances iterator to next matching entity.
BasicQueryWithEntityIter operator++ (int)
 Advances iterator to next matching entity (postfix).
BasicQueryWithEntityIteroperator-- ()
 Moves iterator to previous matching entity.
BasicQueryWithEntityIter operator-- (int)
 Moves iterator to previous matching entity (postfix).
reference operator* () const
 Dereferences iterator to get entity and component tuple.
bool operator== (const BasicQueryWithEntityIter &other) const noexcept
bool operator!= (const BasicQueryWithEntityIter &other) const noexcept
BasicQueryWithEntityIter begin () const noexcept
 Returns copy of this iterator as begin iterator (for range-based for).
BasicQueryWithEntityIter end () const noexcept
 Returns end iterator for this query.
Public Member Functions inherited from helios::utils::FunctionalAdapterBase< BasicQueryWithEntityIter< IsConst, Components... > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< BasicQueryWithEntityIter< IsConst, Components... >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Chains another filter operation on top of this iterator.
constexpr auto Map (Func transform) const noexcept(noexcept(MapAdapter< BasicQueryWithEntityIter< IsConst, Components... >, Func >(GetDerived().begin(), GetDerived().end(), std::move(transform))))
 Transforms each element using the given function.
constexpr auto Take (size_t count) const noexcept(noexcept(TakeAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), count)))
 Limits the number of elements to at most count.
constexpr auto Skip (size_t count) const noexcept(noexcept(SkipAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< BasicQueryWithEntityIter< IsConst, Components... >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Takes elements while a predicate is true.
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(SkipWhileAdapter< BasicQueryWithEntityIter< IsConst, Components... >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< BasicQueryWithEntityIter< IsConst, Components... >, Func >(GetDerived().begin(), GetDerived().end(), std::move(inspector))))
 Observes each element without modifying it.
constexpr auto StepBy (size_t step) const noexcept(noexcept(StepByAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< BasicQueryWithEntityIter< IsConst, Components... >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Chains another range after this one.
constexpr auto Reverse () const noexcept(noexcept(ReverseAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< BasicQueryWithEntityIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< BasicQueryWithEntityIter< IsConst, Components... >, OtherIter >(GetDerived().begin(), GetDerived().end(), std::move(begin), std::move(end))))
 Zips another range with this one.
constexpr void ForEach (const Action &action) const
 Terminal operation: applies an action to each element.
constexpr T Fold (T init, const Folder &folder) const
 Terminal operation: reduces elements to a single value using a folder function.
constexpr auto Find (const Pred &predicate) const
 Terminal operation: finds the first element satisfying a predicate.
constexpr size_t CountIf (const Pred &predicate) const
 Terminal operation: counts elements satisfying a predicate.
constexpr auto Partition (const Pred &predicate) const
 Terminal operation: partitions elements into two groups based on a predicate.
constexpr auto PartitionWith (const Pred &predicate, Allocator allocator) const
 Terminal operation: partitions elements with a custom allocator.
constexpr auto MaxBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the maximum value according to a key function.
constexpr auto MinBy (const KeyFunc &key_func) const
 Terminal operation: finds the element with the minimum value according to a key function.
constexpr auto GroupBy (const KeyFunc &key_func) const
 Terminal operation: groups elements by a key function.
constexpr auto GroupByWith (const KeyFunc &key_func, MapAllocator map_allocator, ValueAllocator value_allocator) const
 Terminal operation: groups elements by key with custom allocators.
constexpr auto Collect () const
 Terminal operation: collects all elements into a vector.
constexpr auto CollectWith (Allocator allocator={}) const
 Terminal operation: collects all elements into a vector with a custom allocator.
constexpr void Into (OutIt out) const
 Terminal operation: writes all elements into an output iterator.
constexpr bool Any (const Pred &predicate) const
 Terminal operation: checks if any element satisfies a predicate.
constexpr bool All (const Pred &predicate) const
 Terminal operation: checks if all elements satisfy a predicate.
constexpr bool None (const Pred &predicate) const
 Terminal operation: checks if no elements satisfy a predicate.

Additional Inherited Members

Protected Member Functions inherited from helios::utils::FunctionalAdapterBase< BasicQueryWithEntityIter< IsConst, Components... > >
constexpr BasicQueryWithEntityIter< IsConst, Components... > & GetDerived () noexcept
 Gets reference to derived class instance.

Detailed Description

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
class helios::ecs::BasicQueryWithEntityIter< IsConst, Components >

Iterator for query results including the entity.

Same as BasicQueryIter but each dereferenced value is a tuple starting with the Entity, followed by the requested component access values.

Note
Not thread-safe.
Template Parameters
IsConstWhether the query operates on a const world
ComponentsRequested component access types

Definition at line 328 of file iterator.hpp.

Member Typedef Documentation

◆ ComponentManagerType

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::ComponentManagerType
Initial value:
std::conditional_t<IsConst, const ComponentManager, ComponentManager>

Definition at line 332 of file iterator.hpp.

◆ difference_type

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::difference_type = ptrdiff_t

Definition at line 341 of file iterator.hpp.

◆ iterator_category

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::iterator_category = std::bidirectional_iterator_tag

Definition at line 335 of file iterator.hpp.

◆ iterator_concept

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::iterator_concept = std::input_iterator_tag

Definition at line 336 of file iterator.hpp.

◆ pointer

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::pointer = void

Definition at line 340 of file iterator.hpp.

◆ reference

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::reference = value_type

Definition at line 339 of file iterator.hpp.

◆ value_type

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::value_type
Initial value:
std::tuple<Entity, details::ComponentAccessType_t<Components>...>

Definition at line 337 of file iterator.hpp.

Constructor & Destructor Documentation

◆ BasicQueryWithEntityIter() [1/3]

template<bool IsConst, typename... Components>
helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::BasicQueryWithEntityIter ( std::span< const std::reference_wrapper< const Archetype > > archetypes,
ComponentManagerType & components,
size_t archetype_index,
size_t entity_index,
std::span< const ComponentTypeIndex > without_types = {} )
inlinenoexcept

Constructs iterator for query results with entity.

Parameters
archetypesSpan of archetypes matching the query
componentsComponent manager for accessing component data
archetype_indexStarting archetype index
entity_indexStarting entity index within archetype
without_typesSpan of component types to exclude (default empty)

Definition at line 351 of file iterator.hpp.

◆ BasicQueryWithEntityIter() [2/3]

template<bool IsConst, typename... Components>
helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::BasicQueryWithEntityIter ( const BasicQueryWithEntityIter< IsConst, Components > & )
defaultnoexcept

◆ BasicQueryWithEntityIter() [3/3]

template<bool IsConst, typename... Components>
helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::BasicQueryWithEntityIter ( BasicQueryWithEntityIter< IsConst, Components > && )
defaultnoexcept

◆ ~BasicQueryWithEntityIter()

template<bool IsConst, typename... Components>
helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::~BasicQueryWithEntityIter ( )
defaultnoexcept

Member Function Documentation

◆ begin()

template<bool IsConst, typename... Components>
BasicQueryWithEntityIter helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::begin ( ) const
inlinenodiscardnoexcept

Returns copy of this iterator as begin iterator (for range-based for).

Returns
Copy of this iterator

Definition at line 420 of file iterator.hpp.

◆ end()

template<bool IsConst, typename... Components>
BasicQueryWithEntityIter helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::end ( ) const
inlinenodiscardnoexcept

Returns end iterator for this query.

Returns
End iterator (points past the last valid entity)

Definition at line 428 of file iterator.hpp.

◆ operator!=()

template<bool IsConst, typename... Components>
bool helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator!= ( const BasicQueryWithEntityIter< IsConst, Components > & other) const
inlinenodiscardnoexcept

Definition at line 410 of file iterator.hpp.

◆ operator*()

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
auto helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator* ( ) const
inlinenodiscard

Dereferences iterator to get entity and component tuple.

Warning
Triggers assertion if iterator is at end or in invalid state.
Returns
Tuple of (Entity, component access values...)

Definition at line 646 of file iterator.hpp.

◆ operator++() [1/2]

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
auto helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator++ ( )
inline

Advances iterator to next matching entity.

Returns
Reference to this iterator after advancement

Definition at line 590 of file iterator.hpp.

◆ operator++() [2/2]

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
auto helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator++ ( int )
inline

Advances iterator to next matching entity (postfix).

Returns
Copy of iterator before advancement

Definition at line 600 of file iterator.hpp.

◆ operator--() [1/2]

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
auto helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator-- ( )
inline

Moves iterator to previous matching entity.

Returns
Reference to this iterator after moving backward

Definition at line 610 of file iterator.hpp.

◆ operator--() [2/2]

template<bool IsConst, typename... Components>
requires details::UniqueComponentAccess<Components...> && (details::ValidComponentAccess<Components> && ...)
auto helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator-- ( int )
inline

Moves iterator to previous matching entity (postfix).

Returns
Copy of iterator before moving backward

Definition at line 636 of file iterator.hpp.

◆ operator=() [1/2]

template<bool IsConst, typename... Components>
BasicQueryWithEntityIter & helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator= ( BasicQueryWithEntityIter< IsConst, Components > && )
defaultnoexcept

◆ operator=() [2/2]

template<bool IsConst, typename... Components>
BasicQueryWithEntityIter & helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator= ( const BasicQueryWithEntityIter< IsConst, Components > & )
defaultnoexcept

◆ operator==()

template<bool IsConst, typename... Components>
bool helios::ecs::BasicQueryWithEntityIter< IsConst, Components >::operator== ( const BasicQueryWithEntityIter< IsConst, Components > & other) const
inlinenodiscardnoexcept

Definition at line 404 of file iterator.hpp.