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

Definition at line 66 of file Component.h.

Constructor & Destructor Documentation

◆ ComponentHandle()

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

Explicit full initialization.

Definition at line 78 of file Component.h.

Member Function Documentation

◆ Empty()

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

◆ 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();
}

Definition at line 116 of file Component.h.

References resolve().

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

Definition at line 90 of file Component.h.

References resolve().

Referenced by Cogs::Core::CurtainView::CurtainViewSystem::createComponent(), Cogs::Core::EchoSounder::UniformGridSystem::createComponent(), Cogs::Core::FixedConstraintSystem::destroyComponent(), Cogs::Core::HingeConstraintSystem::destroyComponent(), Cogs::Core::SpringConstraintSystem::destroyComponent(), Cogs::Core::GenericConstraintSystem::destroyComponent(), Cogs::Core::GhostSystem::destroyComponent(), Cogs::Core::RigidBodySystem::destroyComponent(), Cogs::Core::TriggerSystem::destroyComponent(), Cogs::Core::EchoSounder::UniformGridSystem::destroyComponent(), Cogs::Core::OceanSystem::destroyComponent(), Cogs::Core::TerrainSystem::destroyComponent(), Cogs::Core::VectorField::VectorFieldSystem::destroyComponent(), Cogs::Core::VideoCaptureSystem::destroyComponent(), Cogs::Core::CaptureSystem::destroyComponent(), Cogs::Core::AudioSystem::destroyComponent(), Cogs::Core::VideoPlaybackSystem::destroyComponent(), Cogs::Core::VectorField::VectorFieldBounds::getBounds(), Cogs::Core::EnvironmentSystem::getGlobalEnvironment(), Cogs::Core::FogSystem::getGlobalFog(), Cogs::Core::CameraSystem::getMainCamera(), Cogs::Core::InstancedMeshPicker::pickImpl(), Cogs::Core::MeshRenderPicker::pickImpl(), Cogs::Core::SubMeshPicker::pickImpl(), Cogs::Core::Scene::setup(), and Cogs::Core::InstancedModelSystem::update().


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