ezEngine  Milestone 7
ezResourceHandle< ResourceType > Class Template Reference

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

#include <ResourceHandle.h>

Public Member Functions

 ezResourceHandle ()
 A default constructed handle is invalid and does not reference any resource.
 
 ezResourceHandle (ResourceType *pResource)
 Increases the refcount of the given resource.
 
 ezResourceHandle (const ezResourceHandle< ResourceType > &rhs)
 Increases the refcount of the given resource.
 
 ezResourceHandle (ezResourceHandle< ResourceType > &&rhs)
 Move constructor, no refcount change is necessary.
 
void operator= (const ezResourceHandle< ResourceType > &rhs)
 Releases the current reference and increases the refcount of the given resource.
 
void operator= (ezResourceHandle< ResourceType > &&rhs)
 Move operator, no refcount change is necessary.
 
 ~ezResourceHandle ()
 Releases any referenced resource.
 
bool IsValid () const
 Returns whether the handle stores a valid pointer to a resource.
 
void Invalidate ()
 Clears any reference to a resource and reduces its refcount.
 
EZ_FORCE_INLINE bool operator== (const ezResourceHandle< ResourceType > &rhs) const
 Checks whether the two handles point to the same resource.
 
EZ_FORCE_INLINE bool operator!= (const ezResourceHandle< ResourceType > &rhs) const
 Checks whether the two handles point to the same resource.
 

Private Attributes

ResourceType * m_pResource
 

Friends

class ezResourceManager
 

Detailed Description

template<typename ResourceType>
class ezResourceHandle< ResourceType >

The ezResourceHandle controls access to an ezResource.

All resources must be referenced using ezResourceHandle 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.

ezResourceHandle 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: