class TResourceHandle

template<typename ResourceType, bool IsWeakHandle = false>
Inherits: std::conditional_t<IsWeakHandle, WeakResourceHandle, StrongResourceHandle>

Represents a handle to a resource.

Handles are similar to a smart pointers, but they have two advantages:

  • When loading a resource asynchronously you can be immediately returned the handle that you may use throughout the engine. The handle will be made valid as soon as the resource is loaded.
  • Handles can be serialized and deserialized, therefore saving/restoring references to their original resource.

Public

Constructors

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>() = default

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(std::nullptr_t)

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(const TResourceHandle<ResourceType, IsWeakHandle> &other)

Copy constructor.

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(TResourceHandle<ResourceType, IsWeakHandle> &&other) noexcept

Move constructor.

Methods

~TResourceHandle<ResourceType, IsWeakHandle>

~TResourceHandle<ResourceType, IsWeakHandle>()

Swap

void Swap(TResourceHandle<ResourceType, IsWeakHandle> &other)

Swaps the contents of this handle with another.

Get

ResourceType *Get() const

Returns internal resource pointer and dereferences it.

GetShared

SPtr<ResourceType> GetShared() const

Returns the internal shared pointer to the resource.

Operators

operator TResourceHandle<b3d::Resource, IsWeakHandle>

operator TResourceHandle<Resource, IsWeakHandle>()

Converts a specific handle to generic Resource handle.

operator->

ResourceType *operator->() const

Returns internal resource pointer.

operator*

ResourceType &operator*() const

Returns internal resource pointer and dereferences it.

operator=

TResourceHandle<ResourceType, IsWeakHandle> &operator=(std::nullptr_t rhs)

Clears the handle making it invalid and releases any references held to the resource.

operator=

TResourceHandle<ResourceType, IsWeakHandle> &operator=(const TResourceHandle<ResourceType, IsWeakHandle> &rhs)

Copy assignment.

operator=

TResourceHandle<ResourceType, IsWeakHandle> &operator=(TResourceHandle<ResourceType, IsWeakHandle> &&rhs) noexcept

Move assignment.

operator int Bool_struct::*

operator int Bool_struct<ResourceType>::*() const

Allows direct conversion of handle to bool.

Protected

Constructors

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(const UUID &resourceId)

Constructs an invalid handle with the specified Id.

You must call AssociateResourceWithHandle() with the actual resource pointer to make the handle valid.

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(const SPtr<ResourceType> object, const UUID &resourceId)

Constructs a new valid handle for the provided resource with the provided ID.

TResourceHandle<ResourceType, IsWeakHandle>

TResourceHandle<ResourceType, IsWeakHandle>(ResourceHandleData *handleData)

Constructs a new handle from existing handle data.