Plasma Engine  2.0
Loading...
Searching...
No Matches
plTypedResourceHandle< RESOURCE_TYPE > Class Template Reference

The plTypedResourceHandle controls access to an plResource. More...

#include <ResourceHandle.h>

Public Types

using ResourceType = RESOURCE_TYPE
 

Public Member Functions

 plTypedResourceHandle ()=default
 A default constructed handle is invalid and does not reference any resource.
 
 plTypedResourceHandle (ResourceType *pResource)
 Increases the refcount of the given resource.
 
 plTypedResourceHandle (const plTypedResourceHandle< ResourceType > &rhs)
 Increases the refcount of the given resource.
 
 plTypedResourceHandle (plTypedResourceHandle< ResourceType > &&rhs)
 Move constructor, no refcount change is necessary.
 
template<typename BaseOrDerivedType >
 plTypedResourceHandle (const plTypedResourceHandle< BaseOrDerivedType > &rhs)
 
void operator= (const plTypedResourceHandle< ResourceType > &rhs)
 Releases the current reference and increases the refcount of the given resource.
 
void operator= (plTypedResourceHandle< ResourceType > &&rhs)
 Move operator, no refcount change is necessary.
 
PL_ALWAYS_INLINE bool operator== (const plTypedResourceHandle< ResourceType > &rhs) const
 Checks whether the two handles point to the same resource.
 
PL_ALWAYS_INLINE bool operator!= (const plTypedResourceHandle< ResourceType > &rhs) const
 Checks whether the two handles point to the same resource.
 
PL_ALWAYS_INLINE bool operator< (const plTypedResourceHandle< ResourceType > &rhs) const
 For storing handles as keys in maps.
 
PL_ALWAYS_INLINE bool operator== (const plResource *rhs) const
 Checks whether the handle points to the given resource.
 
PL_ALWAYS_INLINE bool operator!= (const plResource *rhs) const
 Checks whether the handle points to the given resource.
 
PL_ALWAYS_INLINE operator const plTypelessResourceHandle () const
 Returns the corresponding typeless resource handle.
 
PL_ALWAYS_INLINE operator plTypelessResourceHandle ()
 Returns the corresponding typeless resource handle.
 
PL_ALWAYS_INLINE bool IsValid () const
 Returns whether the handle stores a valid pointer to a resource.
 
PL_ALWAYS_INLINE operator bool () const
 Returns whether the handle stores a valid pointer to a resource.
 
PL_ALWAYS_INLINE void Invalidate ()
 Clears any reference to a resource and reduces its refcount.
 
PL_ALWAYS_INLINE plUInt64 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.
 
PL_ALWAYS_INLINE const plStringGetResourceID () const
 Returns the Resource ID of the exact resource that this handle points to, without acquiring the resource. The handle must be valid.
 
void AssignFromTypelessHandle (const plTypelessResourceHandle &hHandle)
 Attempts to copy the given typeless handle to this handle.
 

Friends

class plResourceManager
 
class plResourceHandleWriteContext
 
class plResourceHandleReadContext
 
class plResourceHandleStreamOperations
 

Detailed Description

template<typename RESOURCE_TYPE>
class plTypedResourceHandle< RESOURCE_TYPE >

The plTypedResourceHandle controls access to an plResource.

All resources must be referenced using plTypedResourceHandle 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 plResourceManager::BeginAcquireResource and plResourceManager::EndAcquireResource after you have finished using it.

plTypedResourceHandle 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.

Member Function Documentation

◆ AssignFromTypelessHandle()

template<typename RESOURCE_TYPE >
void plTypedResourceHandle< RESOURCE_TYPE >::AssignFromTypelessHandle ( const plTypelessResourceHandle & hHandle)
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.


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