Handle

template<IsSceneObject T>
class Handle

Strongly-typed handle for scene objects.

Handle provides safe, type-checked access to scene objects managed by shared pointers. It ensures that the referenced object is still valid and owned by the scene, and allows for type-safe downcasting to derived types. Handles are used throughout the scene graph and asset management system to avoid raw pointer usage and to enforce object lifetime.

Template Parameters:

TScene object type

Public Functions

inline Handle(std::weak_ptr<T> ptr)
bool valid() const

Checks if the handle points to a valid, scene-owned object.

Returns:

true if valid, false otherwise

template<typename U = T>
std::shared_ptr<U> get() const

Gets a shared_ptr to the referenced object, optionally downcasting to a derived type.

Template Parameters:

U – Type to cast to (default: T)

Throws:

std::runtime_error

Returns:

std::shared_ptr

Protected Functions

std::shared_ptr<T> get_() const

Gets a shared_ptr to the referenced object, enforcing validity.

Throws:

std::runtime_error – if the handle is invalid

Returns:

std::shared_ptr<T> Shared pointer to the object

Protected Attributes

std::weak_ptr<T> ptr_