![]() |
ezEngine
Release 25.03
|
The ezTypedResourceHandle controls access to an ezResource. More...
#include <ResourceHandle.h>
Public Types | |
using | ResourceType = RESOURCE_TYPE |
Public Member Functions | |
ezTypedResourceHandle ()=default | |
A default constructed handle is invalid and does not reference any resource. | |
ezTypedResourceHandle (ResourceType *pResource) | |
Increases the refcount of the given resource. | |
ezTypedResourceHandle (const ezTypedResourceHandle< ResourceType > &rhs) | |
Increases the refcount of the given resource. | |
ezTypedResourceHandle (ezTypedResourceHandle< ResourceType > &&rhs) | |
Move constructor, no refcount change is necessary. | |
template<typename BaseOrDerivedType > | |
ezTypedResourceHandle (const ezTypedResourceHandle< BaseOrDerivedType > &rhs) | |
void | operator= (const ezTypedResourceHandle< ResourceType > &rhs) |
Releases the current reference and increases the refcount of the given resource. | |
void | operator= (ezTypedResourceHandle< ResourceType > &&rhs) |
Move operator, no refcount change is necessary. | |
EZ_ALWAYS_INLINE bool | operator== (const ezTypedResourceHandle< ResourceType > &rhs) const |
Checks whether the two handles point to the same resource. | |
EZ_ALWAYS_INLINE bool | operator!= (const ezTypedResourceHandle< ResourceType > &rhs) const |
Checks whether the two handles point to the same resource. | |
EZ_ALWAYS_INLINE bool | operator< (const ezTypedResourceHandle< ResourceType > &rhs) const |
For storing handles as keys in maps. | |
EZ_ALWAYS_INLINE bool | operator== (const ezResource *rhs) const |
Checks whether the handle points to the given resource. | |
EZ_ALWAYS_INLINE bool | operator!= (const ezResource *rhs) const |
Checks whether the handle points to the given resource. | |
EZ_ALWAYS_INLINE | operator const ezTypelessResourceHandle () const |
Returns the corresponding typeless resource handle. | |
EZ_ALWAYS_INLINE | operator ezTypelessResourceHandle () |
Returns the corresponding typeless resource handle. | |
EZ_ALWAYS_INLINE bool | IsValid () const |
Returns whether the handle stores a valid pointer to a resource. | |
EZ_ALWAYS_INLINE | operator bool () const |
Returns whether the handle stores a valid pointer to a resource. | |
EZ_ALWAYS_INLINE void | Invalidate () |
Clears any reference to a resource and reduces its refcount. | |
EZ_ALWAYS_INLINE ezUInt64 | GetResourceIDHash () const |
Returns the Resource ID hash of the exact resource that this handle points to, without acquiring the resource. The handle must be valid. | |
EZ_ALWAYS_INLINE ezStringView | GetResourceID () const |
Returns the Resource ID of the exact resource that this handle points to, without acquiring the resource. The handle must be valid. | |
EZ_ALWAYS_INLINE ezStringView | GetResourceIdOrDescription () const |
The returns the resource description, if available, otherwise the resource ID. This is mainly for logging, where you want the more user friendly description, but the ID, if no description is available. If the handle is not valid, an empty string is returned. | |
void | AssignFromTypelessHandle (const ezTypelessResourceHandle &hHandle) |
Attempts to copy the given typeless handle to this handle. More... | |
Friends | |
class | ezResourceManager |
class | ezResourceHandleWriteContext |
class | ezResourceHandleReadContext |
class | ezResourceHandleStreamOperations |
The ezTypedResourceHandle controls access to an ezResource.
All resources must be referenced using ezTypedResourceHandle instances (instantiated with the proper resource type as the template argument). You must not store a direct pointer to a resource anywhere. Instead always store resource handles. To actually access a resource, use ezResourceManager::BeginAcquireResource and ezResourceManager::EndAcquireResource after you have finished using it.
ezTypedResourceHandle implements reference counting on resources. It also allows to redirect resources to fallback resources when they are not yet loaded (if possible).
As long as there is one resource handle that references a resource, it is considered 'in use' and thus might not get unloaded. So be careful where you store resource handles. If necessary you can call Invalidate() to clear a resource handle and thus also remove the reference to the resource.
|
inline |
Attempts to copy the given typeless handle to this handle.
It is an error to assign a typeless handle that references a resource with a mismatching type.