Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches

Unique identifier for an archetype, represented as a sorted set of component type indices. More...

#include <archetype_id.hpp>

Public Types

using size_type = size_t

Public Member Functions

constexpr ArchetypeId ()=default
 Constructs an empty archetype id (no components).
constexpr ArchetypeId (std::vector< ComponentTypeIndex > types)
 Constructs an archetype id from a span of component type indices.
constexpr ArchetypeId (std::initializer_list< ComponentTypeIndex > types)
 Constructs an archetype id from an initializer list of component type indices.
constexpr ArchetypeId (const ArchetypeId &)=default
constexpr ArchetypeId (ArchetypeId &&) noexcept=default
constexpr ~ArchetypeId ()=default
constexpr ArchetypeIdoperator= (const ArchetypeId &)=default
constexpr ArchetypeIdoperator= (ArchetypeId &&) noexcept=default
constexpr ArchetypeId With (ComponentTypeIndex type) const
 Returns a new archetype id with the given component type added.
constexpr ArchetypeId Without (ComponentTypeIndex type) const
 Returns a new archetype id with the given component type removed.
template<ComponentTrait T>
constexpr ArchetypeId With () const
 Returns a new archetype id with the given component type added.
template<ComponentTrait T>
constexpr ArchetypeId Without () const
 Returns a new archetype id with the given component type removed.
constexpr bool operator== (const ArchetypeId &other) const noexcept
constexpr bool operator!= (const ArchetypeId &other) const noexcept
constexpr bool operator< (const ArchetypeId &other) const noexcept
constexpr bool Contains (ComponentTypeIndex type) const noexcept
 Checks if this archetype id contains the given component type.
template<ComponentTrait T>
constexpr bool Contains () const noexcept
 Checks if this archetype id contains the given component type.
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
constexpr bool ContainsAll (const R &types) const noexcept
 Checks if this archetype id contains all the given component types.
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
constexpr bool ContainsAny (const R &types) const noexcept
 Checks if this archetype id contains any of the given component types.
template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
constexpr bool ContainsNone (const R &types) const noexcept
 Checks if this archetype id contains none of the given component types.
constexpr auto Types () const noexcept -> std::span< const ComponentTypeIndex >
 Gets the sorted component type indices.
constexpr size_t Hash () const noexcept
 Gets the precomputed hash of this archetype id.
constexpr bool Empty () const noexcept
 Checks if this archetype id has no component types.
constexpr size_type Size () const noexcept
 Gets the number of component types in this archetype id.

Static Public Member Functions

template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...>
static constexpr ArchetypeId From ()
 Creates an archetype id from a set of component types.

Detailed Description

Unique identifier for an archetype, represented as a sorted set of component type indices.

An archetype is defined by the exact set of component types it contains. The type indices are kept sorted to ensure consistent identity regardless of insertion order. Only archetype-storage components are tracked here; sparse-set components are managed separately.

Definition at line 25 of file archetype_id.hpp.

Member Typedef Documentation

◆ size_type

Definition at line 27 of file archetype_id.hpp.

Constructor & Destructor Documentation

◆ ArchetypeId() [1/5]

helios::ecs::ArchetypeId::ArchetypeId ( )
constexprdefault

Constructs an empty archetype id (no components).

◆ ArchetypeId() [2/5]

helios::ecs::ArchetypeId::ArchetypeId ( std::vector< ComponentTypeIndex > types)
explicitconstexpr

Constructs an archetype id from a span of component type indices.

Indices are copied and sorted internally. Duplicates are removed.

Parameters
typesSpan of component type indices

Definition at line 206 of file archetype_id.hpp.

◆ ArchetypeId() [3/5]

helios::ecs::ArchetypeId::ArchetypeId ( std::initializer_list< ComponentTypeIndex > types)
constexpr

Constructs an archetype id from an initializer list of component type indices.

Indices are copied and sorted internally. Duplicates are removed.

Parameters
typesInitializer list of component type indices

Definition at line 212 of file archetype_id.hpp.

◆ ArchetypeId() [4/5]

helios::ecs::ArchetypeId::ArchetypeId ( const ArchetypeId & )
constexprdefault

◆ ArchetypeId() [5/5]

helios::ecs::ArchetypeId::ArchetypeId ( ArchetypeId && )
constexprdefaultnoexcept

◆ ~ArchetypeId()

helios::ecs::ArchetypeId::~ArchetypeId ( )
constexprdefault

Member Function Documentation

◆ Contains() [1/2]

template<ComponentTrait T>
bool helios::ecs::ArchetypeId::Contains ( ) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id contains the given component type.

Template Parameters
TComponent type to check
Returns
True if the type is present

Definition at line 124 of file archetype_id.hpp.

◆ Contains() [2/2]

bool helios::ecs::ArchetypeId::Contains ( ComponentTypeIndex type) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id contains the given component type.

Parameters
typeComponent type index to check
Returns
True if the type is present

Definition at line 113 of file archetype_id.hpp.

◆ ContainsAll()

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
bool helios::ecs::ArchetypeId::ContainsAll ( const R & types) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id contains all the given component types.

Template Parameters
RRange of ComponentTypeIndex to check
Parameters
typesRange of component type indices to check
Returns
True if all types are present

Definition at line 136 of file archetype_id.hpp.

◆ ContainsAny()

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
bool helios::ecs::ArchetypeId::ContainsAny ( const R & types) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id contains any of the given component types.

Template Parameters
RRange of ComponentTypeIndex to check
Parameters
typesRange of component type indices to check
Returns
True if any type is present

Definition at line 150 of file archetype_id.hpp.

◆ ContainsNone()

template<std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, ComponentTypeIndex>
bool helios::ecs::ArchetypeId::ContainsNone ( const R & types) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id contains none of the given component types.

Template Parameters
RRange of ComponentTypeIndex to check
Parameters
typesRange of component type indices to check
Returns
True if no type is present

Definition at line 164 of file archetype_id.hpp.

◆ Empty()

bool helios::ecs::ArchetypeId::Empty ( ) const
inlinenodiscardconstexprnoexcept

Checks if this archetype id has no component types.

Returns
True if this archetype id is empty (no component types)

Definition at line 188 of file archetype_id.hpp.

◆ From()

template<ComponentTrait... Ts>
requires utils::UniqueTypes<Ts...>
ArchetypeId helios::ecs::ArchetypeId::From ( )
staticnodiscardconstexpr

Creates an archetype id from a set of component types.

Template Parameters
TsComponent types
Returns
Archetype id containing the type indices of all provided types

Definition at line 221 of file archetype_id.hpp.

◆ Hash()

size_t helios::ecs::ArchetypeId::Hash ( ) const
inlinenodiscardconstexprnoexcept

Gets the precomputed hash of this archetype id.

Returns
Hash value for this archetype id

Definition at line 182 of file archetype_id.hpp.

◆ operator!=()

bool helios::ecs::ArchetypeId::operator!= ( const ArchetypeId & other) const
inlineconstexprnoexcept

Definition at line 101 of file archetype_id.hpp.

◆ operator<()

bool helios::ecs::ArchetypeId::operator< ( const ArchetypeId & other) const
inlineconstexprnoexcept

Definition at line 104 of file archetype_id.hpp.

◆ operator=() [1/2]

ArchetypeId & helios::ecs::ArchetypeId::operator= ( ArchetypeId && )
constexprdefaultnoexcept

◆ operator=() [2/2]

ArchetypeId & helios::ecs::ArchetypeId::operator= ( const ArchetypeId & )
constexprdefault

◆ operator==()

bool helios::ecs::ArchetypeId::operator== ( const ArchetypeId & other) const
inlineconstexprnoexcept

Definition at line 98 of file archetype_id.hpp.

◆ Size()

size_type helios::ecs::ArchetypeId::Size ( ) const
inlinenodiscardconstexprnoexcept

Gets the number of component types in this archetype id.

Returns
Count of component types in this archetype id

Definition at line 194 of file archetype_id.hpp.

◆ Types()

auto helios::ecs::ArchetypeId::Types ( ) const -> std::span< const ComponentTypeIndex >
inlinenodiscardconstexprnoexcept

Gets the sorted component type indices.

Returns
Span of component type indices in this archetype

Definition at line 173 of file archetype_id.hpp.

◆ With() [1/2]

template<ComponentTrait T>
ArchetypeId helios::ecs::ArchetypeId::With ( ) const
inlinenodiscardconstexpr

Returns a new archetype id with the given component type added.

Template Parameters
TComponent type to add
Returns
New archetype id with the type included

Definition at line 84 of file archetype_id.hpp.

◆ With() [2/2]

ArchetypeId helios::ecs::ArchetypeId::With ( ComponentTypeIndex type) const
nodiscardconstexpr

Returns a new archetype id with the given component type added.

If the type is already present, returns a copy of this id.

Parameters
typeComponent type index to add
Returns
New archetype id with the type included

Definition at line 229 of file archetype_id.hpp.

◆ Without() [1/2]

template<ComponentTrait T>
ArchetypeId helios::ecs::ArchetypeId::Without ( ) const
inlinenodiscardconstexpr

Returns a new archetype id with the given component type removed.

Template Parameters
TComponent type to remove
Returns
New archetype id without the type

Definition at line 94 of file archetype_id.hpp.

◆ Without() [2/2]

ArchetypeId helios::ecs::ArchetypeId::Without ( ComponentTypeIndex type) const
nodiscardconstexpr

Returns a new archetype id with the given component type removed.

If the type is not present, returns a copy of this id.

Parameters
typeComponent type index to remove
Returns
New archetype id without the type

Definition at line 243 of file archetype_id.hpp.