XII Release 0.1.0
Loading...
Searching...
No Matches
xiiTypedResourceHandle< RESOURCE_TYPE > Class Template Reference

The xiiTypedResourceHandle controls access to a xiiResource. More...

#include <ResourceHandle.h>

Public Types

using ResourceType = RESOURCE_TYPE
 

Public Member Functions

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

Friends

class xiiResourceManager
 
class xiiResourceHandleWriteContext
 
class xiiResourceHandleReadContext
 
class xiiResourceHandleStreamOperations
 

Detailed Description

template<typename RESOURCE_TYPE>
class xiiTypedResourceHandle< RESOURCE_TYPE >

The xiiTypedResourceHandle controls access to a xiiResource.

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

xiiTypedResourceHandle 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 xiiTypedResourceHandle< RESOURCE_TYPE >::AssignFromTypelessHandle ( const xiiTypelessResourceHandle & 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: