ezEngine  Milestone 9
ezTypedResourceHandle< RESOURCE_TYPE > Class Template Reference

The ezTypedResourceHandle controls access to an ezResource. More...

#include <ResourceHandle.h>

Public Types

typedef RESOURCE_TYPE ResourceType
 

Public Member Functions

 ezTypedResourceHandle ()
 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 ezUInt32 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 const ezStringGetResourceID () const
 Returns the Resource ID of the exact resource that this handle points to, without acquiring the resource. The handle must be valid.
 

Friends

template<typename T >
class ezTypedResourceHandle
 
class ezResourceManager
 
class ezResourceHandleWriteContext
 
class ezResourceHandleReadContext
 

Detailed Description

template<typename RESOURCE_TYPE>
class ezTypedResourceHandle< RESOURCE_TYPE >

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.


The documentation for this class was generated from the following files: