Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_handle< T > Struct Template Reference

Thread-safe handle to an asset. More...

#include <asset_handle.h>

Public Types

using asset_link_t = asset_link<T>
 
using state_t = typename asset_link_t::state_t
 
using state_ptr = std::shared_ptr<state_t>
 
using task_future_t = typename asset_link_t::task_future_t
 

Public Member Functions

auto operator== (const asset_handle &rhs) const -> bool
 Equality operator for asset handles.
 
auto version () const -> uintptr_t
 
 operator bool () const
 Conversion operator to bool.
 
auto id () const -> std::string
 Gets the string identifier of the asset.
 
auto uid () const -> hpp::uuid
 Gets the unique identifier of the asset.
 
auto name () const -> std::string
 Gets the name of the asset derived from its path.
 
auto extension () const -> std::string
 
auto get (bool wait=true) const -> std::shared_ptr< T >
 Gets the shared pointer to the asset.
 
auto is_valid () const -> bool
 Checks if the handle references a task.
 
auto is_ready () const -> bool
 Checks if the task is ready.
 
auto is_deferred () const -> bool
 Checks if the handle has a deferred job not yet submitted to workers.
 
auto is_loading () const -> bool
 Checks if the asset is currently loading.
 
void submit ()
 Submits a deferred task to the thread pool for execution. Does nothing if the task is already submitted or invalid.
 
void demote_to_deferred ()
 Demotes a fully loaded asset back to deferred state.
 
auto last_access () const -> std::chrono::steady_clock::time_point
 Gets the last access timestamp.
 
auto task_id () const
 Gets the task ID (may be empty if there's no task).
 
void set_internal_job (const task_future_t &future)
 Sets the internal job future.
 
void set_internal_ids (const hpp::uuid &internal_uid, const std::string &internal_id=get_empty_id())
 Sets the internal IDs (uid + string identifier).
 
void set_internal_id (const std::string &internal_id=get_empty_id())
 Sets the internal string identifier.
 
void invalidate ()
 Invalidates the handle, resetting its state.
 
auto peek () const -> std::shared_ptr< T >
 Returns the loaded asset if it is currently in memory, or nullptr otherwise.
 
void ensure ()
 Ensures the asset link is initialized.
 

Static Public Member Functions

static auto get_empty () -> const asset_handle &
 Gets an empty asset handle.
 
static auto get_empty_id () -> const std::string &
 Gets the conventional empty string identifier ("None").
 

Detailed Description

template<typename T>
struct asset_handle< T >

Thread-safe handle to an asset.

The handle is a cheap value (shared_ptr to the link). All accessors are safe to call concurrently from any thread; mutators publish their changes atomically so other threads always observe a consistent state.

Definition at line 144 of file asset_handle.h.

Member Typedef Documentation

◆ asset_link_t

template<typename T >
using asset_handle< T >::asset_link_t = asset_link<T>

Definition at line 146 of file asset_handle.h.

◆ state_ptr

template<typename T >
using asset_handle< T >::state_ptr = std::shared_ptr<state_t>

Definition at line 148 of file asset_handle.h.

◆ state_t

template<typename T >
using asset_handle< T >::state_t = typename asset_link_t::state_t

Definition at line 147 of file asset_handle.h.

◆ task_future_t

template<typename T >
using asset_handle< T >::task_future_t = typename asset_link_t::task_future_t

Definition at line 149 of file asset_handle.h.

Member Function Documentation

◆ demote_to_deferred()

template<typename T >
void asset_handle< T >::demote_to_deferred ( )
inline

Demotes a fully loaded asset back to deferred state.

Publishes a new snapshot that preserves uid / id but drops the task; also clears the weak-asset cache. Caller should follow with a load_from_file(deferred) to set up a new deferred task.

Definition at line 330 of file asset_handle.h.

◆ ensure()

template<typename T >
void asset_handle< T >::ensure ( )
inline

Ensures the asset link is initialized.

Definition at line 498 of file asset_handle.h.

◆ extension()

template<typename T >
auto asset_handle< T >::extension ( ) const -> std::string
inline

Definition at line 214 of file asset_handle.h.

◆ get()

template<typename T >
auto asset_handle< T >::get ( bool wait = true) const -> std::shared_ptr<T>
inline

Gets the shared pointer to the asset.

Parameters
waitIf true, waits for the task to complete if not ready.

If the handle was registered with deferred loading, the first call to get() triggers the actual load on the thread pool. Subsequent calls behave as before (wait or poll).

Definition at line 227 of file asset_handle.h.

◆ get_empty()

template<typename T >
static auto asset_handle< T >::get_empty ( ) -> const asset_handle&
inlinestatic

Gets an empty asset handle.

Definition at line 455 of file asset_handle.h.

◆ get_empty_id()

template<typename T >
static auto asset_handle< T >::get_empty_id ( ) -> const std::string&
inlinestatic

Gets the conventional empty string identifier ("None").

Definition at line 469 of file asset_handle.h.

◆ id()

template<typename T >
auto asset_handle< T >::id ( ) const -> std::string
inline

Gets the string identifier of the asset.

Returns by value — the caller receives a snapshot of the current id. Binding to const auto& is still safe (the temporary's lifetime is extended to the binding's scope).

Definition at line 181 of file asset_handle.h.

◆ invalidate()

template<typename T >
void asset_handle< T >::invalidate ( )
inline

Invalidates the handle, resetting its state.

Publishes an empty snapshot so any concurrent reader observing the link after this call sees a fully-cleared state.

Definition at line 431 of file asset_handle.h.

◆ is_deferred()

template<typename T >
auto asset_handle< T >::is_deferred ( ) const -> bool
inline

Checks if the handle has a deferred job not yet submitted to workers.

Definition at line 295 of file asset_handle.h.

◆ is_loading()

template<typename T >
auto asset_handle< T >::is_loading ( ) const -> bool
inline

Checks if the asset is currently loading.

Definition at line 304 of file asset_handle.h.

◆ is_ready()

template<typename T >
auto asset_handle< T >::is_ready ( ) const -> bool
inline

Checks if the task is ready.

Definition at line 286 of file asset_handle.h.

◆ is_valid()

template<typename T >
auto asset_handle< T >::is_valid ( ) const -> bool
inline

Checks if the handle references a task.

Definition at line 277 of file asset_handle.h.

◆ last_access()

template<typename T >
auto asset_handle< T >::last_access ( ) const -> std::chrono::steady_clock::time_point
inline

Gets the last access timestamp.

Definition at line 353 of file asset_handle.h.

◆ name()

template<typename T >
auto asset_handle< T >::name ( ) const -> std::string
inline

Gets the name of the asset derived from its path.

Definition at line 209 of file asset_handle.h.

◆ operator bool()

template<typename T >
asset_handle< T >::operator bool ( ) const
inline

Conversion operator to bool.

Returns
True if the handle references an asset (loaded or deferred).

Definition at line 169 of file asset_handle.h.

◆ operator==()

template<typename T >
auto asset_handle< T >::operator== ( const asset_handle< T > & rhs) const -> bool
inline

Equality operator for asset handles.

Definition at line 154 of file asset_handle.h.

◆ peek()

template<typename T >
auto asset_handle< T >::peek ( ) const -> std::shared_ptr<T>
inline

Returns the loaded asset if it is currently in memory, or nullptr otherwise.

Unlike get(), this does NOT force-load, does NOT submit deferred tasks, does NOT wait, and does NOT update last-access. Intended for iteration use cases — e.g. walking the asset manager's loaded set to build a dependency graph — where we only care about what is already resident and must not have side effects.

Definition at line 485 of file asset_handle.h.

◆ set_internal_id()

template<typename T >
void asset_handle< T >::set_internal_id ( const std::string & internal_id = get_empty_id())
inline

Sets the internal string identifier.

Publishes a new snapshot; preserves uid and task.

Definition at line 415 of file asset_handle.h.

◆ set_internal_ids()

template<typename T >
void asset_handle< T >::set_internal_ids ( const hpp::uuid & internal_uid,
const std::string & internal_id = get_empty_id() )
inline

Sets the internal IDs (uid + string identifier).

Publishes a new snapshot; preserves the current task.

Definition at line 399 of file asset_handle.h.

◆ set_internal_job()

template<typename T >
void asset_handle< T >::set_internal_job ( const task_future_t & future)
inline

Sets the internal job future.

Publishes a new snapshot with the given task; preserves uid + id. Also clears the weak-asset cache so the next get() resolves the new task.

Definition at line 381 of file asset_handle.h.

◆ submit()

template<typename T >
void asset_handle< T >::submit ( )
inline

Submits a deferred task to the thread pool for execution. Does nothing if the task is already submitted or invalid.

Definition at line 314 of file asset_handle.h.

◆ task_id()

template<typename T >
auto asset_handle< T >::task_id ( ) const
inline

Gets the task ID (may be empty if there's no task).

Definition at line 366 of file asset_handle.h.

◆ uid()

template<typename T >
auto asset_handle< T >::uid ( ) const -> hpp::uuid
inline

Gets the unique identifier of the asset.

Returns by value — the caller receives a snapshot of the current uid. Binding to const auto& is still safe (the temporary's lifetime is extended to the binding's scope).

Definition at line 197 of file asset_handle.h.

◆ version()

template<typename T >
auto asset_handle< T >::version ( ) const -> uintptr_t
inline

Definition at line 159 of file asset_handle.h.


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