Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::ecs::BasicQueryBuilder< WorldT, Allocator > Class Template Reference

#include <query.hpp>

Public Types

using allocator_type = Allocator
 

Public Member Functions

 BasicQueryBuilder (WorldT &world, Allocator alloc={}) noexcept
 Constructs query builder for the specified world.
 
 BasicQueryBuilder (WorldT &world, const app::AccessPolicy &policy, Allocator alloc={})
 Constructs query builder for the specified world with access validation.
 
 BasicQueryBuilder (const BasicQueryBuilder &)=delete
 
 BasicQueryBuilder (BasicQueryBuilder &&) noexcept=default
 
 ~BasicQueryBuilder ()=default
 
BasicQueryBuilderoperator= (const BasicQueryBuilder &)=delete
 
BasicQueryBuilderoperator= (BasicQueryBuilder &&) noexcept=default
 
template<ComponentTrait... Comps>
requires utils::UniqueTypes<Comps...>
auto With (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Adds required component types to the query.
 
template<ComponentTrait... Comps>
requires utils::UniqueTypes<Comps...>
auto Without (this auto &&self) -> decltype(std::forward< decltype(self)>(self))
 Adds forbidden component types to the query.
 
template<ComponentTrait... Comps>
requires (sizeof...(Comps) > 0 && utils::UniqueTypes<details::ComponentTypeExtractor_t<Comps>...>)
auto Get (this auto &&self) -> BasicQuery< WorldT, Allocator, Comps... >
 Builds and executes the query, returning components with specified access.
 
auto Get (this auto &&self) -> BasicQuery< WorldT, Allocator >
 Builds and executes the query, returning no components.
 
allocator_type get_allocator () const noexcept
 Gets the allocator used by this builder.
 

Detailed Description

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
class helios::ecs::BasicQueryBuilder< WorldT, Allocator >

Definition at line 2363 of file query.hpp.

Member Typedef Documentation

◆ allocator_type

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
using helios::ecs::BasicQueryBuilder< WorldT, Allocator >::allocator_type = Allocator

Constructor & Destructor Documentation

◆ BasicQueryBuilder() [1/4]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
helios::ecs::BasicQueryBuilder< WorldT, Allocator >::BasicQueryBuilder ( WorldT world,
Allocator  alloc = {} 
)
inlineexplicitnoexcept

Constructs query builder for the specified world.

Parameters
worldReference to ECS world to query
allocAllocator for internal storage

Definition at line 2372 of file query.hpp.

2372 {}) noexcept
2373 : world_(world), with_components_(alloc), without_components_(alloc), alloc_(alloc) {}
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481

◆ BasicQueryBuilder() [2/4]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
helios::ecs::BasicQueryBuilder< WorldT, Allocator >::BasicQueryBuilder ( WorldT world,
const app::AccessPolicy policy,
Allocator  alloc = {} 
)
inline

Constructs query builder for the specified world with access validation.

Parameters
worldReference to ECS world to query
policyAccess policy for validation
allocAllocator for internal storage

Definition at line 2381 of file query.hpp.

2381 {})
2382 : world_(world), policy_(&policy), with_components_(alloc), without_components_(alloc), alloc_(alloc) {}

◆ BasicQueryBuilder() [3/4]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
helios::ecs::BasicQueryBuilder< WorldT, Allocator >::BasicQueryBuilder ( const BasicQueryBuilder< WorldT, Allocator > &  )
delete

◆ BasicQueryBuilder() [4/4]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
helios::ecs::BasicQueryBuilder< WorldT, Allocator >::BasicQueryBuilder ( BasicQueryBuilder< WorldT, Allocator > &&  )
defaultnoexcept

◆ ~BasicQueryBuilder()

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
helios::ecs::BasicQueryBuilder< WorldT, Allocator >::~BasicQueryBuilder ( )
default

Member Function Documentation

◆ Get() [1/2]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
auto helios::ecs::BasicQueryBuilder< WorldT, Allocator >::Get ( this auto &&  self) -> BasicQuery<WorldT, Allocator>
inline

Builds and executes the query, returning no components.

Creates query object that only filters entities based on presence/absence of specified components, without returning any component data. Useful for existence checks or counting entities.

Returns
BasicQuery object for iteration over matching entities

Definition at line 2439 of file query.hpp.

2439 {
2440 return {self.world_.get(), std::forward_like<decltype(self)>(self.with_components_),
2441 std::forward_like<decltype(self)>(self.without_components_), self.alloc_};
2442 }

◆ Get() [2/2]

template<WorldType WorldT, typename Allocator >
requires (sizeof...(Comps) > 0 && utils::UniqueTypes<details::ComponentTypeExtractor_t<Comps>...>)
template<ComponentTrait... Comps>
requires (sizeof...(Comps) > 0 && utils::UniqueTypes<details::ComponentTypeExtractor_t<Comps>...>)
auto helios::ecs::BasicQueryBuilder< WorldT, Allocator >::Get ( this auto &&  self) -> BasicQuery<WorldT, Allocator, Comps...>
inline

Builds and executes the query, returning components with specified access.

Creates query object with the specified component access types. Supports const-qualified access for read-only operations and mixed access patterns.

Access type examples:

  • T& - Mutable reference to component T
  • const T& - Const reference to component T
  • T - Copy of component T

Const World Restriction:

  • When BasicQueryBuilder is constructed with const World&, only const component access is allowed
  • Attempting to use mutable component access (e.g., Get<Position&>()) will fail at compile time
Template Parameters
CompsComponent access types (may include const qualifiers and references)
Returns
BasicQuery object for iteration over matching entities
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/query.hpp.

Definition at line 2516 of file query.hpp.

2516 {
2517 // Compile-time validation: const World requires const Components
2518 static_assert(details::ValidWorldComponentAccess<WorldT, Comps...>,
2519 "Cannot request mutable component access from const World! "
2520 "Use const-qualified components (e.g., 'const Position&') or pass mutable World.");
2521
2522#ifdef HELIOS_ENABLE_ASSERTS
2523 if (self.policy_ != nullptr) [[likely]] {
2524 // Check that all requested component types are declared in at least one query
2525 const auto queries = self.policy_->GetQueries();
2526
2527 // Collect all requested component type IDs
2529
2530 // Check if each requested type is in any query (read or write)
2531 for (const auto& requested_id : requested_types) {
2532 bool found = false;
2533 for (const auto& query : queries) {
2534 auto matches_id = [requested_id](const auto& info) { return info.type_id == requested_id; };
2535 if (std::ranges::any_of(query.read_components, matches_id) ||
2536 std::ranges::any_of(query.write_components, matches_id)) {
2537 found = true;
2538 break;
2539 }
2540 }
2541
2543 "Attempted to query component that was not declared in app::AccessPolicy! "
2544 "Add .Query<>() with this component type to GetAccessPolicy().");
2545 }
2546 }
2547#endif
2548
2549 // Add required components for Get<> to with_components_ if not already there
2550 auto add_if_not_present = [&self](ComponentTypeId type_id) {
2551 if (std::ranges::find(self.with_components_, type_id) == self.with_components_.end()) {
2552 self.with_components_.push_back(type_id);
2553 }
2554 };
2555
2556 (add_if_not_present(ComponentTypeIdOf<details::ComponentTypeExtractor_t<Comps>>()), ...);
2557 return {self.world_.get(), std::forward_like<decltype(self)>(self.with_components_),
2558 std::forward_like<decltype(self)>(self.without_components_), self.alloc_};
2559}
#define HELIOS_ASSERT(condition,...)
Assertion macro that aborts execution in debug builds.
Definition assert.hpp:140
size_t ComponentTypeId
Type ID for components.
constexpr ComponentTypeId ComponentTypeIdOf() noexcept
Type ID for components using CTTI.

◆ get_allocator()

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
allocator_type helios::ecs::BasicQueryBuilder< WorldT, Allocator >::get_allocator ( ) const
inlinenoexcept

Gets the allocator used by this builder.

Returns
Copy of the allocator
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/query.hpp.

Definition at line 2448 of file query.hpp.

2448{ return alloc_; }

◆ operator=() [1/2]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
BasicQueryBuilder & helios::ecs::BasicQueryBuilder< WorldT, Allocator >::operator= ( BasicQueryBuilder< WorldT, Allocator > &&  )
defaultnoexcept

◆ operator=() [2/2]

template<WorldType WorldT = World, typename Allocator = std::allocator<ComponentTypeId>>
BasicQueryBuilder & helios::ecs::BasicQueryBuilder< WorldT, Allocator >::operator= ( const BasicQueryBuilder< WorldT, Allocator > &  )
delete

◆ With()

template<WorldType WorldT, typename Allocator >
requires utils::UniqueTypes<Comps...>
template<ComponentTrait... Comps>
requires utils::UniqueTypes<Comps...>
auto helios::ecs::BasicQueryBuilder< WorldT, Allocator >::With ( this auto &&  self) -> decltype(std::forward<decltype(self)>(self))
inline

Adds required component types to the query.

Entities must have ALL specified component types to match the query.

Template Parameters
CompsComponent types that entities must have
Returns
Reference to this builder for method chaining
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/query.hpp.

Definition at line 2498 of file query.hpp.

2499 {
2500 (self.with_components_.insert(self.with_components_.end(), {ComponentTypeIdOf<Comps>()...}));
2501 return std::forward<decltype(self)>(self);
2502}

◆ Without()

template<WorldType WorldT, typename Allocator >
requires utils::UniqueTypes<Comps...>
template<ComponentTrait... Comps>
requires utils::UniqueTypes<Comps...>
auto helios::ecs::BasicQueryBuilder< WorldT, Allocator >::Without ( this auto &&  self) -> decltype(std::forward<decltype(self)>(self))
inline

Adds forbidden component types to the query.

Entities must NOT have ANY of the specified component types to match the query.

Template Parameters
CompsComponent types that entities must not have
Returns
Reference to this builder for method chaining
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/ecs/query.hpp.

Definition at line 2507 of file query.hpp.

2508 {
2509 (self.without_components_.insert(self.without_components_.end(), {ComponentTypeIdOf<Comps>()...}));
2510 return std::forward<decltype(self)>(self);
2511}