Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Cogs::ComponentModel::ComponentHandle Struct Reference

Handle to a Component instance. More...

#include <Component.h>

Public Member Functions

 ComponentHandle ()=default
 Defaulted constructor.
 
 ComponentHandle (const ComponentHandle &other)=default
 Defaulted copy constructor.
 
ComponentHandleoperator= (const ComponentHandle &rhs)=default
 Defaulted assign operator.
 
constexpr ComponentHandle (class ComponentPoolBase *pool, ComponentIndex index, Reflection::TypeId typeId, uint16_t generation)
 Explicit full initialization.
 
COGSFOUNDATION_API class Componentresolve () const
 Resolve the handle, returning a pointer to the held Component instance.
 
template<typename ComponentType >
ComponentType * resolveComponent () const
 
 operator bool () const
 Explicit bool conversion for checking if a handle is valid.
 

Static Public Member Functions

static ComponentHandle Empty ()
 Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().
 

Detailed Description

Handle to a Component instance.

Constructor & Destructor Documentation

◆ ComponentHandle() [1/3]

Cogs::ComponentModel::ComponentHandle::ComponentHandle ( )
default

Defaulted constructor.

◆ ComponentHandle() [2/3]

Cogs::ComponentModel::ComponentHandle::ComponentHandle ( const ComponentHandle other)
default

Defaulted copy constructor.

◆ ComponentHandle() [3/3]

constexpr Cogs::ComponentModel::ComponentHandle::ComponentHandle ( class ComponentPoolBase pool,
ComponentIndex  index,
Reflection::TypeId  typeId,
uint16_t  generation 
)
inlineconstexpr

Explicit full initialization.

Member Function Documentation

◆ Empty()

static ComponentHandle Cogs::ComponentModel::ComponentHandle::Empty ( )
inlinestatic

Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().

Referenced by Cogs::ComponentModel::Component::getComponentHandle(), and Cogs::ComponentModel::Entity::getComponentHandle().

◆ operator bool()

Cogs::ComponentModel::ComponentHandle::operator bool ( ) const
inlineexplicit

Explicit bool conversion for checking if a handle is valid.

Since we check the generation counter, this is essentially the same as a resolve.

To avoid paying the resolve cost twice when subsequently resolving the handle, use the following pattern

auto handle = ...
if(auto * comp = handle.resolv(); comp) {
comp->doStuff();
}

instead of

auto handle = ...
if (handle) {
handle.resolve()->doStuff();
}

References resolve().

◆ operator=()

ComponentHandle & Cogs::ComponentModel::ComponentHandle::operator= ( const ComponentHandle rhs)
default

Defaulted assign operator.

◆ resolve()

Cogs::ComponentModel::Component * Cogs::ComponentModel::ComponentHandle::resolve ( ) const

◆ resolveComponent()

template<typename ComponentType >
ComponentType * Cogs::ComponentModel::ComponentHandle::resolveComponent ( ) const
inline

Utility method for returning a pointer to a type derived from Component. Might incur a performance penalty if type checking is enabled.

References resolve().


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