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

Iterator for query results without entity information. More...

#include <iterator.hpp>

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

Public Types

using ComponentManagerType
using iterator_category = std::bidirectional_iterator_tag
using iterator_concept = std::input_iterator_tag
using value_type = std::tuple<details::ComponentAccessType_t<Components>...>
using reference = value_type
using pointer = void
using difference_type = ptrdiff_t

Public Member Functions

 BasicQueryIter (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.
 BasicQueryIter (const BasicQueryIter &) noexcept=default
 BasicQueryIter (BasicQueryIter &&) noexcept=default
 ~BasicQueryIter () noexcept=default
BasicQueryIteroperator= (const BasicQueryIter &) noexcept=default
BasicQueryIteroperator= (BasicQueryIter &&) noexcept=default
BasicQueryIteroperator++ ()
 Advances iterator to next matching entity.
BasicQueryIter operator++ (int)
 Advances iterator to next matching entity (postfix).
BasicQueryIteroperator-- ()
 Moves iterator to previous matching entity.
BasicQueryIter operator-- (int)
 Moves iterator to previous matching entity (postfix).
reference operator* () const
 Dereferences iterator to get component tuple.
pointer operator-> () const =delete
bool operator== (const BasicQueryIter &other) const noexcept
 Compares iterators for equality.
bool operator!= (const BasicQueryIter &other) const noexcept
 Compares iterators for inequality.
BasicQueryIter begin () const noexcept
 Returns copy of this iterator as begin iterator (for range-based for).
BasicQueryIter end () const noexcept
 Returns end iterator for this query.
Public Member Functions inherited from helios::utils::FunctionalAdapterBase< BasicQueryIter< IsConst, Components... > >
constexpr auto Filter (Pred predicate) const noexcept(noexcept(FilterAdapter< BasicQueryIter< 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< BasicQueryIter< 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< BasicQueryIter< 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< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), count)))
 Skips the first count elements.
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(TakeWhileAdapter< BasicQueryIter< 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< BasicQueryIter< IsConst, Components... >, Pred >(GetDerived().begin(), GetDerived().end(), std::move(predicate))))
 Skips elements while a predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(EnumerateAdapter< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end())))
 Adds an index to each element.
constexpr auto Inspect (Func inspector) const noexcept(noexcept(InspectAdapter< BasicQueryIter< 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< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), step)))
 Takes every Nth element.
constexpr auto Chain (OtherIter begin, OtherIter end) const noexcept(noexcept(ChainAdapter< BasicQueryIter< 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< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end())))
 Reverses the order of elements.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(SlideAdapter< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), window_size)))
 Creates sliding windows over elements.
constexpr auto Stride (size_t stride) const noexcept(noexcept(StrideAdapter< BasicQueryIter< IsConst, Components... > >(GetDerived().begin(), GetDerived().end(), stride)))
 Takes every Nth element with stride.
constexpr auto Zip (OtherIter begin, OtherIter end) const noexcept(noexcept(ZipAdapter< BasicQueryIter< 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< BasicQueryIter< IsConst, Components... > >
constexpr BasicQueryIter< 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::BasicQueryIter< IsConst, Components >

Iterator for query results without entity information.

Provides bidirectional iteration over entities matching the query criteria, returning tuples of requested component references/values. Supports all access patterns including const ref, mutable ref, rvalue ref (move), value copy, and nullable pointer (T*, const T*).

Note
Not thread-safe.
Template Parameters
IsConstWhether the query operates on a const world (read-only mode)
ComponentsRequested component access types (may include const qualifiers, references, T*, const T*)

Definition at line 164 of file iterator.hpp.

Member Typedef Documentation

◆ ComponentManagerType

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

Definition at line 167 of file iterator.hpp.

◆ difference_type

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

Definition at line 175 of file iterator.hpp.

◆ iterator_category

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

Definition at line 170 of file iterator.hpp.

◆ iterator_concept

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

Definition at line 171 of file iterator.hpp.

◆ pointer

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

Definition at line 174 of file iterator.hpp.

◆ reference

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

Definition at line 173 of file iterator.hpp.

◆ value_type

template<bool IsConst, typename... Components>
using helios::ecs::BasicQueryIter< IsConst, Components >::value_type = std::tuple<details::ComponentAccessType_t<Components>...>

Definition at line 172 of file iterator.hpp.

Constructor & Destructor Documentation

◆ BasicQueryIter() [1/3]

template<bool IsConst, typename... Components>
helios::ecs::BasicQueryIter< IsConst, Components >::BasicQueryIter ( 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.

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 185 of file iterator.hpp.

◆ BasicQueryIter() [2/3]

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

◆ BasicQueryIter() [3/3]

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

◆ ~BasicQueryIter()

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

Member Function Documentation

◆ begin()

template<bool IsConst, typename... Components>
BasicQueryIter helios::ecs::BasicQueryIter< 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 264 of file iterator.hpp.

◆ end()

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

Returns end iterator for this query.

Returns
End iterator (points past the last valid entity)

Definition at line 270 of file iterator.hpp.

◆ operator!=()

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

Compares iterators for inequality.

Parameters
otherIterator to compare with
Returns
True if iterators point to different positions

Definition at line 255 of file iterator.hpp.

◆ operator*()

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

Dereferences iterator to get component tuple.

Returns tuple of component values/references/pointers for the current entity.

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

Definition at line 506 of file iterator.hpp.

◆ operator++() [1/2]

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

Advances iterator to next matching entity.

Returns
Reference to this iterator after advancement

Definition at line 450 of file iterator.hpp.

◆ operator++() [2/2]

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

Advances iterator to next matching entity (postfix).

Returns
Copy of iterator before advancement

Definition at line 460 of file iterator.hpp.

◆ operator--() [1/2]

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

Moves iterator to previous matching entity.

Returns
Reference to this iterator after moving backward

Definition at line 470 of file iterator.hpp.

◆ operator--() [2/2]

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

Moves iterator to previous matching entity (postfix).

Returns
Copy of iterator before moving backward

Definition at line 496 of file iterator.hpp.

◆ operator->()

template<bool IsConst, typename... Components>
pointer helios::ecs::BasicQueryIter< IsConst, Components >::operator-> ( ) const
delete

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

Compares iterators for equality.

Parameters
otherIterator to compare with
Returns
True if iterators point to the same position

Definition at line 245 of file iterator.hpp.