Skip to main content

Iterator Struct

Forward iterator for View traversal. More...

Declaration

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

Public Member Typedefs Index

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...

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

Public Member Typedefs

LeadComponent

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

The first component type determines iteration order.

Definition at line 138 of file View.ixx.

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

LeadIterator

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

Iterator type from the lead component's SparseSet.

Definition at line 143 of file View.ixx.

Public Constructors

Iterator()

helios::engine::ecs::View< Components >::Iterator::Iterator ()
default

Default constructor creating an invalid iterator.

Definition at line 152 of file View.ixx.

Referenced by helios::engine::ecs::View< Components >::Iterator::operator!= and helios::engine::ecs::View< Components >::Iterator::operator++.

Iterator()

helios::engine::ecs::View< 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 161 of file View.ixx.

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

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

Public Operators

operator!=()

bool helios::engine::ecs::View< 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 264 of file View.ixx.

264 bool operator!=(const Iterator& other) const noexcept {
265 return current_ != other.current_;
266 }

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

operator*()

auto helios::engine::ecs::View< 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 275 of file View.ixx.

275 [[nodiscard]] auto operator*() const {
276 EntityId entityId = current_.entityId();
277
278 auto handle = view_->em_->handle(entityId);
279
280
281 return std::tuple_cat(
282 std::make_tuple(GameObject(handle, view_->em_)),
283 std::apply([entityId](auto*... sets) {
284 return std::make_tuple(sets->get(entityId)...);
285 }, view_->includeSets_)
286 );
287 }

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

operator++()

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

Pre-increment operator.

Returns

Reference to this iterator after advancing.

Definition at line 252 of file View.ixx.

252 Iterator& operator++() noexcept {
253 advance();
254 return *this;
255 }

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

Public Member Functions

advance()

void helios::engine::ecs::View< 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 241 of file View.ixx.

241 void advance() {
242 do {
243 ++current_;
244 } while (current_ != end_ && !isValid());
245 }

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

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

isValid()

bool helios::engine::ecs::View< 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 175 of file View.ixx.

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

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

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


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.