cubos::engine::AnyAsset class

Handle to an asset of any type. May either be weak or strong. Weak handles do not guarantee the asset is loaded, while strong handles do.

Assets are identified by their UUID. This is a unique 128-bit number which is assigned to each asset when it is imported or created. Default constructed handles are null handles, which are not associated with any asset.

Derived classes

template<typename T>
class Asset
Handle to an asset of a specific type.
template<typename T>
class Asset
Handle to an asset of a specific type.
template<typename T>
class Asset
Handle to an asset of a specific type.
template<typename T>
class Asset
Handle to an asset of a specific type.

Constructors, destructors, conversion operators

AnyAsset(std::nullptr_t ptr = nullptr)
Constructs a null handle.
AnyAsset(uuids::uuid id)
Constructs a weak handle.
AnyAsset(std::string_view str)
Constructs a weak handle. If the string is not a valid UUID, the handle will be null.
AnyAsset(const AnyAsset& other)
Constructs a copy of the given handle.
AnyAsset(AnyAsset&& other) noexcept
Constructs a handle from the given handle.
template<typename T>
operator Asset<T>() const
Converts this handle to a handle of a specific type.

Public functions

auto operator=(const AnyAsset& other) -> AnyAsset&
Overwrites this handle with a copy of the given handle.
auto operator=(AnyAsset&& other) -> AnyAsset& noexcept
Overwrites this handle with the given handle.
auto operator==(const AnyAsset& other) const -> bool
Equality operator for comparing two AnyAsset objects.
auto getVersion() const -> int
Gets the version of the asset last seen by this handle.
auto getId() const -> uuids::uuid
Gets the UUID of the asset.
auto isNull() const -> bool
Checks if the handle is null.
auto isStrong() const -> bool
Checks if the handle is strong.
void makeWeak()
Makes this handle a weak handle, decreasing the asset's reference count if it was strong.

Public variables

uuids::uuid reflectedId
Avoid using this field, use getId() instead.

Protected static functions

static auto makeType(std::string name) -> core::reflection::Type&
Constructs a type with the given name, constructible trait and UUID field.

Function documentation

cubos::engine::AnyAsset::AnyAsset(uuids::uuid id)

Constructs a weak handle.

Parameters
id UUID of the asset.

cubos::engine::AnyAsset::AnyAsset(std::string_view str)

Constructs a weak handle. If the string is not a valid UUID, the handle will be null.

Parameters
str String representation of the UUID.

cubos::engine::AnyAsset::AnyAsset(const AnyAsset& other)

Constructs a copy of the given handle.

Parameters
other Handle to copy.

cubos::engine::AnyAsset::AnyAsset(AnyAsset&& other) noexcept

Constructs a handle from the given handle.

Parameters
other Handle to move.

template<typename T>
cubos::engine::AnyAsset::operator Asset<T>() const

Converts this handle to a handle of a specific type.

Template parameters
T Type of the asset.
Returns Handle to the same asset, but of the specified type.

AnyAsset& cubos::engine::AnyAsset::operator=(const AnyAsset& other)

Overwrites this handle with a copy of the given handle.

Parameters
other Handle to copy.

AnyAsset& cubos::engine::AnyAsset::operator=(AnyAsset&& other) noexcept

Overwrites this handle with the given handle.

Parameters
other Handle to move.

bool cubos::engine::AnyAsset::operator==(const AnyAsset& other) const

Equality operator for comparing two AnyAsset objects.

Parameters
other The other AnyAsset to compare.
Returns True if the two AnyAsset objects have the same UUID , otherwise false.

int cubos::engine::AnyAsset::getVersion() const

Gets the version of the asset last seen by this handle.

Returns Asset version.

uuids::uuid cubos::engine::AnyAsset::getId() const

Gets the UUID of the asset.

Returns Asset UUID.

bool cubos::engine::AnyAsset::isNull() const

Checks if the handle is null.

Returns Whether the handle is null.

bool cubos::engine::AnyAsset::isStrong() const

Checks if the handle is strong.

Returns Whether the handle is strong.

static core::reflection::Type& cubos::engine::AnyAsset::makeType(std::string name) protected

Constructs a type with the given name, constructible trait and UUID field.

Parameters
name Type name.

Added so that typed asset handles don't duplicate the existing reflection code of the base class.