Skip to main content

Iterator Struct

Forward iterator for View traversal. More...

Declaration

struct helios::ecs::PartialView::Iterator<TEntityManager, std::tuple< TRequired... >, 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/enabled criteria before yielding.

Definition at line 204 of file View.ixx.

Public Member Typedefs

Entity_type

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

Definition at line 206 of file View.ixx.

LeadComponent

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

The first component type determines iteration order.

Definition at line 211 of file View.ixx.

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

LeadIterator

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

Iterator type from the lead component's SparseSet.

Definition at line 216 of file View.ixx.

Public Constructors

Iterator()

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

Default constructor creating an invalid iterator.

Definition at line 225 of file View.ixx.

Iterator()

helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 234 of file View.ixx.

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

Public Operators

operator!=()

bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 337 of file View.ixx.

337 bool operator!=(const Iterator& other) const noexcept {
338 return current_ != other.current_;
339 }

operator*()

auto helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 (or it is filtered by whereEnabled() when isEnabled() is available).

info

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

Definition at line 355 of file View.ixx.

355 [[nodiscard]] auto operator*() const {
356 EntityId entityId = current_.entityId();
357 auto handle = view_->em_->handle(entityId);
358
359
360 return std::tuple_cat(
361 std::make_tuple(Entity_type(handle, view_->em_)),
362 std::apply([entityId](auto*... sets) {
363 return std::make_tuple(sets->get(entityId)...);
364 }, view_->includeSets_),
365
366 std::apply([entityId, filterEnabledOnly = view_->filterEnabledOnly_](auto*... sets) {
367 return std::make_tuple(
368 ([filterEnabledOnly, entityId, &sets]() {
369 if (!sets || !sets->contains(entityId)) {
370 return nullptr;
371 }
372
373 auto* component = sets->get(entityId);
374
375 if constexpr (requires {component->isEnabled(); }) {
376 if (filterEnabledOnly && !component->isEnabled()) {
377 return nullptr;
378 }
379 }
380
381 return component;
382 }())...
383
384 );
385 }, view_->optionalSets_)
386
387 );
388 }

operator++()

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

Pre-increment operator.

Returns

Reference to this iterator after advancing.

Definition at line 325 of file View.ixx.

325 Iterator& operator++() noexcept {
326 advance();
327 return *this;
328 }

operator==()

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

Definition at line 390 of file View.ixx.

390 [[nodiscard]] bool operator==(const Iterator& other) const noexcept {
391 return current_ == other.current_;
392 }

Public Member Functions

advance()

void helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 314 of file View.ixx.

314 void advance() {
315 do {
316 ++current_;
317 } while (current_ != end_ && !isValid());
318 }

isValid()

bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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
  4. Enabled check - all components pass isEnabled() (if filtered)
Returns

True if the entity passes all checks, false otherwise.

Definition at line 248 of file View.ixx.

248 [[nodiscard]] bool isValid() const {
249 if (current_ == end_) {
250 return true;
251 }
252
253 // 1 Get Entity ID (from the Lead Iterator)
254 EntityId entityId = current_.entityId();
255
256 if (!view_->em_->isValid(entityId)) {
257 return false;
258 }
259
260 // 2 INCLUDE CHECK (Do we have all other required components?)
261 // We iterate over the tuple of sets and check 'contains' for each.
262 const bool hasAllIncludes = std::apply([entityId](auto*... sets) {
263 return ((sets && sets->contains(entityId)) && ...);
264 }, view_->includeSets_);
265
266 if (!hasAllIncludes) {
267 return false;
268 }
269
270 // 3 EXCLUDE CHECK (Must NOT be present)
271 for (const auto& excludeCheck : view_->excludeChecks_) {
272 if (excludeCheck(entityId)) {
273 return false; // If check returns true (has component), the entity is invalid.
274 }
275 }
276
277 // 4 ENABLED CHECK (State)
278 if (view_->filterEnabledOnly_) {
279
280 // SFINAE Helper Lambda: Checks if .isEnabled() exists.
281 auto isComponentEnabled = [](const auto& comp) -> bool {
282 if constexpr (requires { comp.isEnabled(); }) {
283 return comp.isEnabled();
284 } else {
285 return true; // Assume enabled if method is missing.
286 }
287 };
288
289 // Check the Lead component (*current_ returns the component reference)
290 if (!isComponentEnabled(*current_)) {
291 return false;
292 }
293
294 // Check all other included components
295 const bool allEnabled = std::apply([&](auto*... sets) {
296 // sets->get(id) returns a pointer, *ptr gives the reference.
297 return (isComponentEnabled(*sets->get(entityId)) && ...);
298 }, view_->includeSets_);
299
300 if (!allEnabled) {
301 return false;
302 }
303 }
304
305 return true;
306 }

Public Member Attributes

current_

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

Definition at line 218 of file View.ixx.

end_

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

Definition at line 219 of file View.ixx.

view_

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

Definition at line 220 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.