class
#include <engine/assets/asset.hpp>
AnyAsset 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
Public types
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 getIdType() const -> IdType
- Gets the type of the asset identifier.
- auto getIdString() const -> std::string
- Gets the Path or UUID of the asset.
- auto getId() const -> std::optional<uuids::uuid>
- Gets the UUID of the asset if it has one.
- 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
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. |
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. |
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. |
---|
std::string cubos:: engine:: AnyAsset:: getIdString() const
Gets the Path or UUID of the asset.
Returns | Asset Path or UUID. |
---|
std::optional<uuids::uuid> cubos:: engine:: AnyAsset:: getId() const
Gets the UUID of the asset if it has one.
Returns | Asset UUID. |
---|
There are two possible reasons for an asset handle to have no UUID:
- it being an invalid or null handle;
- it being created from an asset path.
To ensure an asset handle gets a UUID, you can use Assets::
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.