ScopedSnapshot#
Fully qualified name: carb::assets::ScopedSnapshot
Defined in carb/assets/AssetsUtils.h
-
template<class Type>
class ScopedSnapshot# A scoped snapshot, this automatically releases the snapshot when it goes out of scope.
A RAII-style helper class to manage the result of IAssets::acquireSnapshot().
operator bool()
can be used to test if the asset successfully acquired.getReason()
can be used to check why an asset failed to load. If the asset successfully loaded, it can be obtained withget()
.Public Functions
-
ScopedSnapshot() = default#
Default Constructor; produces an empty object.
-
inline ScopedSnapshot(IAssets *assets, Id assetId)#
Constructs a
ScopedSnapshot
for the given asset ID.If snapshot acquisition fails,
*this
will befalse
; use getReason() to determine why.- Parameters:
assets – The IAssets interface
assetId – The asset ID to acquire a snapshot for.
-
inline ~ScopedSnapshot()#
Destructor.
-
inline ScopedSnapshot(ScopedSnapshot &&other)#
ScopedSnapshot is move-constructible.
- Parameters:
other – The other
ScopedSnapshot
to move from;other
will be empty.
-
inline ScopedSnapshot &operator=(ScopedSnapshot &&other)#
Move-assignment operator.
- Parameters:
other – The other
ScopedSnapshot
to move from;other
will be empty.- Returns:
*this
-
inline Type *get()#
Obtain the asset data from the snapshot.
- Returns:
The loaded asset if the asset load was successful;
nullptr
otherwise.
-
inline const Type *get() const#
Obtain the asset data from the snapshot.
- Returns:
The loaded asset if the asset load was successful;
nullptr
otherwise.
-
inline Type *operator->()#
Dereference-access operator.
- Returns:
The loaded asset; malformed if
*this == false
.
-
inline const Type *operator->() const#
Dereference-access operator.
- Returns:
The loaded asset; malformed if
*this == false
.
-
inline Type &operator*()#
Dereference operator.
- Returns:
A reference to the loaded asset; malformed if
*this == false
.
-
inline const Type &operator*() const#
Dereference operator.
- Returns:
A reference to the loaded asset; malformed if
*this == false
.
-
inline explicit constexpr operator bool() const noexcept#
Test if the asset snapshot successfully loaded.
- Returns:
true
if the asset snapshot successfully loaded and its value can be retrieved via get();false
otherwise.
-
inline Reason getReason() const#
Obtain the current asset status.
- Returns:
the Reason status code based on acquiring the snapshot. An empty
ScopedSnapshot
will return Reason::eFailed.
-
ScopedSnapshot() = default#