Skip to main content

Iterator Struct

Forward iterator for View traversal. More...

Declaration

struct helios::ecs::View::Iterator { ... }

Public Member Typedefs Index

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

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 View *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 View *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 146 of file View.ixx.

Public Member Typedefs

Entity_type

using helios::ecs::View< TEntityManager, Components >::Iterator::Entity_type = Entity<TEntityManager>

Definition at line 148 of file View.ixx.

LeadComponent

using helios::ecs::View< TEntityManager, Components >::Iterator::LeadComponent = std::tuple_element_t<0, std::tuple<Components...>>

The first component type determines iteration order.

Definition at line 153 of file View.ixx.

153 using LeadComponent = std::tuple_element_t<0, std::tuple<Components...>>;

LeadIterator

using helios::ecs::View< TEntityManager, Components >::Iterator::LeadIterator = typename SparseSet<LeadComponent>::Iterator

Iterator type from the lead component's SparseSet.

Definition at line 158 of file View.ixx.

Public Constructors

Iterator()

helios::ecs::View< TEntityManager, Components >::Iterator::Iterator ()
default

Iterator()

helios::ecs::View< TEntityManager, Components >::Iterator::Iterator (LeadIterator current, LeadIterator end, const View * 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 176 of file View.ixx.

176 Iterator(LeadIterator current, LeadIterator end, const View* view)
177 : current_(current), end_(end), view_(view) {}

References helios::ecs::View< TEntityManager, Components >::Iterator::current_, helios::ecs::View< TEntityManager, Components >::end, helios::ecs::View< TEntityManager, Components >::Iterator::end_, helios::ecs::View< TEntityManager, Components >::View and helios::ecs::View< TEntityManager, Components >::Iterator::view_.

Public Operators

operator!=()

bool helios::ecs::View< TEntityManager, Components >::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 279 of file View.ixx.

279 bool operator!=(const Iterator& other) const noexcept {
280 return current_ != other.current_;
281 }

References helios::ecs::View< TEntityManager, Components >::Iterator::current_ and helios::ecs::View< TEntityManager, Components >::Iterator::Iterator.

operator*()

auto helios::ecs::View< TEntityManager, Components >::Iterator::operator* ()
inline nodiscard

Dereference operator.

Returns

A tuple containing {GameObject, Component*...}.

info

Returns by value to support C++17 Structured Binding (auto [go, comp] : view).

Definition at line 290 of file View.ixx.

290 [[nodiscard]] auto operator*() const {
291 EntityId entityId = current_.entityId();
292
293 auto handle = view_->em_->handle(entityId);
294
295
296 return std::tuple_cat(
297 std::make_tuple(Entity_type(handle, view_->em_)),
298 std::apply([entityId](auto*... sets) {
299 return std::make_tuple(sets->get(entityId)...);
300 }, view_->includeSets_)
301 );
302 }

References helios::ecs::View< TEntityManager, Components >::Iterator::current_ and helios::ecs::View< TEntityManager, Components >::Iterator::view_.

operator++()

Iterator & helios::ecs::View< TEntityManager, Components >::Iterator::operator++ ()
inline noexcept

Pre-increment operator.

Returns

Reference to this iterator after advancing.

Definition at line 267 of file View.ixx.

267 Iterator& operator++() noexcept {
268 advance();
269 return *this;
270 }

References helios::ecs::View< TEntityManager, Components >::Iterator::advance and helios::ecs::View< TEntityManager, Components >::Iterator::Iterator.

operator==()

bool helios::ecs::View< TEntityManager, Components >::Iterator::operator== (const Iterator & other)
inline nodiscard noexcept

Definition at line 304 of file View.ixx.

304 [[nodiscard]] bool operator==(const Iterator& other) const noexcept {
305 return current_ == other.current_;
306 }

References helios::ecs::View< TEntityManager, Components >::Iterator::current_ and helios::ecs::View< TEntityManager, Components >::Iterator::Iterator.

Public Member Functions

advance()

void helios::ecs::View< TEntityManager, Components >::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 256 of file View.ixx.

256 void advance() {
257 do {
258 ++current_;
259 } while (current_ != end_ && !isValid());
260 }

References helios::ecs::View< TEntityManager, Components >::Iterator::current_, helios::ecs::View< TEntityManager, Components >::Iterator::end_ and helios::ecs::View< TEntityManager, Components >::Iterator::isValid.

Referenced by helios::ecs::View< TEntityManager, Components >::begin and helios::ecs::View< TEntityManager, Components >::Iterator::operator++.

isValid()

bool helios::ecs::View< TEntityManager, Components >::Iterator::isValid ()
inline nodiscard

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 190 of file View.ixx.

190 [[nodiscard]] bool isValid() const {
191 if (current_ == end_) {
192 return true;
193 }
194
195 // 1 Get Entity ID (from the Lead Iterator)
196 EntityId entityId = current_.entityId();
197
198 if (!view_->em_->isValid(entityId)) {
199 return false;
200 }
201
202 // 2 INCLUDE CHECK (Do we have all other required components?)
203 // We iterate over the tuple of sets and check 'contains' for each.
204 bool hasAllIncludes = std::apply([entityId](auto*... sets) {
205 return ((sets && sets->contains(entityId)) && ...);
206 }, view_->includeSets_);
207
208 if (!hasAllIncludes) {
209 return false;
210 }
211
212 // 3 EXCLUDE CHECK (Must NOT be present)
213 for (const auto& excludeCheck : view_->excludeChecks_) {
214 if (excludeCheck(entityId)) {
215 return false; // If check returns true (has component), the entity is invalid.
216 }
217 }
218
219 // 4 ENABLED CHECK (State)
220 if (view_->filterEnabledOnly_) {
221
222 // SFINAE Helper Lambda: Checks if .isEnabled() exists.
223 auto isComponentEnabled = [](const auto& comp) -> bool {
224 if constexpr (requires { comp.isEnabled(); }) {
225 return comp.isEnabled();
226 } else {
227 return true; // Assume enabled if method is missing.
228 }
229 };
230
231 // Check the Lead component (*current_ returns the component reference)
232 if (!isComponentEnabled(*current_)) {
233 return false;
234 }
235
236 // Check all other included components
237 bool allEnabled = std::apply([&](auto*... sets) {
238 // sets->get(id) returns a pointer, *ptr gives the reference.
239 return (isComponentEnabled(*sets->get(entityId)) && ...);
240 }, view_->includeSets_);
241
242 if (!allEnabled) {
243 return false;
244 }
245 }
246
247 return true;
248 }

References helios::ecs::View< TEntityManager, Components >::Iterator::current_, helios::ecs::View< TEntityManager, Components >::Iterator::end_ and helios::ecs::View< TEntityManager, Components >::Iterator::view_.

Referenced by helios::ecs::View< TEntityManager, Components >::Iterator::advance and helios::ecs::View< TEntityManager, Components >::begin.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.