Skip to main content

Iterator Struct

Forward iterator for View traversal. More...

Declaration

struct helios::ecs::PartialView::Iterator<TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator { ... }

Public Member Typedefs Index

usingEntity_type = Entity< TEntityManager >
usingLeadComponent = std::tuple_element_t< 0, std::tuple< TRequired... > >

The first component type determines iteration order. More...

usingLeadIterator = typename SparseSet< LeadComponent >::Iterator

Iterator type from the lead component's SparseSet. More...

Public Constructors Index

Iterator ()=default

Default constructor creating an invalid iterator. More...

Iterator (LeadIterator current, LeadIterator end, const PartialView *view)

Constructs an iterator with the given range and view. More...

Public Operators Index

Iterator &operator++ () noexcept

Pre-increment operator. More...

booloperator!= (const Iterator &other) const noexcept

Inequality comparison. More...

autooperator* () const

Dereference operator. More...

booloperator== (const Iterator &other) const noexcept

Public Member Functions Index

boolisValid () const

Validates if the current entity matches all filter criteria. More...

voidadvance ()

Advances to the next valid entity. More...

Public Member Attributes Index

LeadIteratorcurrent_
LeadIteratorend_
const PartialView *view_

Description

Forward iterator for View traversal.

Uses the first component type as the "lead" iterator and validates each entity against all include/exclude criteria before yielding.

Definition at line 274 of file View.ixx.

Public Member Typedefs

Entity_type

using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::Entity_type = Entity<TEntityManager>

Definition at line 276 of file View.ixx.

LeadComponent

using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::LeadComponent = std::tuple_element_t<0, std::tuple<TRequired...> >

The first component type determines iteration order.

Definition at line 281 of file View.ixx.

281 using LeadComponent = std::tuple_element_t<0, std::tuple<TRequired...>>;

LeadIterator

using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::LeadIterator = typename SparseSet<LeadComponent>::Iterator

Iterator type from the lead component's SparseSet.

Definition at line 286 of file View.ixx.

Public Constructors

Iterator()

helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::Iterator ()
default

Default constructor creating an invalid iterator.

Definition at line 295 of file View.ixx.

Iterator()

helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::Iterator (LeadIterator current, LeadIterator end, const PartialView * view)
inline

Constructs an iterator with the given range and view.

Parameters
current

Iterator to the current position.

end

Iterator to the end position.

view

Pointer to the owning View for filter access.

Definition at line 304 of file View.ixx.

304 Iterator(LeadIterator current, LeadIterator end, const PartialView* view)
305 : current_(current), end_(end), view_(view) {}

Public Operators

operator!=()

bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::operator!= (const Iterator & other)
inline noexcept

Inequality comparison.

Parameters
other

The iterator to compare against.

Returns

True if iterators point to different positions.

Definition at line 394 of file View.ixx.

394 bool operator!=(const Iterator& other) const noexcept {
395 return current_ != other.current_;
396 }

operator*()

auto helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::operator* ()
inline

Dereference operator.

Returns

A tuple containing: 1) Entity_type, 2) pointers to all required components, 3) pointers to all optional components.

Optional component pointers may be nullptr when the current entity does not own the respective component.

info

Returns by value to support C++17 structured binding.

Definition at line 411 of file View.ixx.

411 [[nodiscard]] auto operator*() const {
412 EntityId entityId = current_.entityId();
413 auto handle = view_->em_->handle(entityId);
414
415
416 return std::tuple_cat(
417 std::make_tuple(Entity_type(handle, view_->em_)),
418 std::apply([entityId](auto*... sets) {
419 return std::make_tuple(sets->get(entityId)...);
420 }, view_->includeSets_),
421
422 std::apply([
423 entityId
424 ](auto*... sets) {
425 return std::make_tuple(
426 ([entityId, &sets]() {
427 if (!sets || !sets->contains(entityId)) {
428 return nullptr;
429 }
430
431 return sets->get(entityId);
432 }())...
433
434 );
435 }, view_->optionalSets_)
436
437 );
438 }

operator++()

Iterator & helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::operator++ ()
inline noexcept

Pre-increment operator.

Returns

Reference to this iterator after advancing.

Definition at line 382 of file View.ixx.

382 Iterator& operator++() noexcept {
383 advance();
384 return *this;
385 }

operator==()

bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::operator== (const Iterator & other)
inline noexcept

Definition at line 440 of file View.ixx.

440 [[nodiscard]] bool operator==(const Iterator& other) const noexcept {
441 return current_ == other.current_;
442 }

Public Member Functions

advance()

void helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::advance ()
inline

Advances to the next valid entity.

Increments the underlying iterator and skips invalid entities until a valid one is found or end is reached.

Definition at line 371 of file View.ixx.

371 void advance() {
372 do {
373 ++current_;
374 } while (current_ != end_ && !isValid());
375 }

isValid()

bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::isValid ()
inline

Validates if the current entity matches all filter criteria.

Performs the following checks in order:

  1. Entity validity in the registry
  2. Include check - entity has all required components
  3. Exclude check - entity has none of the excluded components
Returns

True if the entity passes all checks, false otherwise.

Definition at line 317 of file View.ixx.

317 [[nodiscard]] bool isValid() const {
318 if (current_ == end_) {
319 return true;
320 }
321
322 // 1 Get Entity ID (from the Lead Iterator)
323 EntityId entityId = current_.entityId();
324
325 if (!view_->em_->isValid(entityId)) {
326 return false;
327 }
328
329 // 2 INCLUDE CHECK (Do we have all other required components?)
330 // We iterate over the tuple of sets and check 'contains' for each.
331 const bool hasAllIncludes = std::apply([entityId](auto*... sets) {
332 return ((sets && sets->contains(entityId)) && ...);
333 }, view_->includeSets_);
334
335 if (view_->filterActiveOnly_ && (!view_->activeSet_ || !view_->activeSet_->contains(entityId))) {
336 return false;
337 }
338
339 if (!hasAllIncludes) {
340 return false;
341 }
342
343 // dirty check
344 if constexpr (sizeof...(TDirty) > 0) {
345 const bool hasAnyDirtyIncludes = std::apply([entityId](auto*... sets) {
346 return ((sets && sets->contains(entityId)) || ...);
347 }, view_->anyDirtySets_);
348
349 if (!hasAnyDirtyIncludes) {
350 return false;
351 }
352 }
353
354 // 3 EXCLUDE CHECK (Must NOT be present)
355 for (const auto& excludeCheck : view_->excludeChecks_) {
356 if (excludeCheck(entityId)) {
357 return false; // If check returns true (has component), the entity is invalid.
358 }
359 }
360
361
362 return true;
363 }

Public Member Attributes

current_

LeadIterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::current_

Definition at line 288 of file View.ixx.

end_

LeadIterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::end_

Definition at line 289 of file View.ixx.

view_

const PartialView* helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::Iterator::view_

Definition at line 290 of file View.ixx.


The documentation for this struct was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.