Cogs.Core
Public Member Functions | Static Public Attributes | Friends | List of all members
Cogs::Core::ResourceHandle_t< ResourceType > Struct Template Reference

Opaque resource handle for holding references to resources. More...

#include <ResourceHandle.h>

Inheritance diagram for Cogs::Core::ResourceHandle_t< ResourceType >:
Cogs::Core::ResourceHandleBase

Public Member Functions

 ResourceHandle_t ()=default
 Default construct a resource handle.
 
 ResourceHandle_t (ResourceBase *resource)
 Constructs a handle from the given resource pointer.
 
 ResourceHandle_t (const ResourceHandle_t &other)
 Copy construct a handle.
 
 ResourceHandle_t (ResourceHandle_t &&other) noexcept
 Move construct a handle from the given r-value.
 
ResourceHandle_toperator= (const ResourceHandle_t &other)
 Copy assign the handle from the given other handle.
 
 ResourceHandle_t (const ResourceHandleBase &other)
 
ResourceType * resolve () const
 Resolve the handle, returning a pointer to the actual resource.
 
ResourceType * operator-> () const
 Pointer operator, returns the held resource.
 
- Public Member Functions inherited from Cogs::Core::ResourceHandleBase
 ResourceHandleBase ()=default
 Constructs an empty handle, holding no resource.
 
 ResourceHandleBase (ResourceBase *resource)
 Constructs a handle with the given integer handle and resource pointer pair.
 
 ResourceHandleBase (const ResourceHandleBase &other)
 Copy constructs a handle from the given other handle.
 
 ResourceHandleBase (ResourceHandleBase &&other) noexcept
 Move constructs a handle from the given other handle.
 
 ~ResourceHandleBase ()
 Destructs a handle, and if a resource is held, releases the reference to this resource.
 
ResourceHandleBaseoperator= (const ResourceHandleBase &other)
 Assign the handle from the given other handle.
 
bool operator== (const ResourceHandleBase &other) const
 Compares this instance against the contents of other.
 
bool operator!= (const ResourceHandleBase &other) const
 Compares this instance against other for inequality.
 
 operator bool () const
 Implicit bool conversion operator.
 
ResourceBaseoperator-> ()
 
const ResourceBaseoperator-> () const
 
ResourceBaseget ()
 
const ResourceBaseget () const
 
void reset (ResourceBase *otherResource)
 Reset the contents of this instance to the given handle and resource.
 
ResourceId getId () const
 Get the resource id of the held resource.
 
size_t hash (size_t hashValue=Cogs::hash()) const
 

Static Public Attributes

static const ResourceHandle_t NoHandle = ResourceHandle_t<T>(nullptr)
 Handle representing a default (or none if default not present) resource.
 
- Static Public Attributes inherited from Cogs::Core::ResourceHandleBase
static const ResourceHandleBase NoHandle = Cogs::Core::ResourceHandleBase(nullptr)
 Provided as shorthand for empty resource handles.
 

Friends

struct std::hash< ResourceHandle_t< ResourceType > >
 

Additional Inherited Members

- Protected Member Functions inherited from Cogs::Core::ResourceHandleBase
void resetInternal (ResourceBase *otherResource)
 Reset the contents of this instance to the given handle and resource.
 
- Protected Attributes inherited from Cogs::Core::ResourceHandleBase
ResourceBaseresource = nullptr
 Pointer to held resource.
 

Detailed Description

template<typename ResourceType>
struct Cogs::Core::ResourceHandle_t< ResourceType >

Opaque resource handle for holding references to resources.

Holding a handle to a resource ensures the resource will not be deleted while in use by keeping automatic reference count.

Template Parameters
ResourceTypeType of the resource to manage. Must inherit from ResourceBase.

Definition at line 154 of file ResourceHandle.h.

Constructor & Destructor Documentation

◆ ResourceHandle_t() [1/4]

template<typename ResourceType >
Cogs::Core::ResourceHandle_t< ResourceType >::ResourceHandle_t ( ResourceBase resource)
inlineexplicit

Constructs a handle from the given resource pointer.

Definition at line 160 of file ResourceHandle.h.

◆ ResourceHandle_t() [2/4]

template<typename ResourceType >
Cogs::Core::ResourceHandle_t< ResourceType >::ResourceHandle_t ( const ResourceHandle_t< ResourceType > &  other)
inline

Copy construct a handle.

Definition at line 163 of file ResourceHandle.h.

◆ ResourceHandle_t() [3/4]

template<typename ResourceType >
Cogs::Core::ResourceHandle_t< ResourceType >::ResourceHandle_t ( ResourceHandle_t< ResourceType > &&  other)
inlinenoexcept

Move construct a handle from the given r-value.

Definition at line 166 of file ResourceHandle.h.

◆ ResourceHandle_t() [4/4]

template<typename ResourceType >
Cogs::Core::ResourceHandle_t< ResourceType >::ResourceHandle_t ( const ResourceHandleBase other)
inline

Definition at line 171 of file ResourceHandle.h.

Member Function Documentation

◆ operator->()

template<typename ResourceType >
ResourceType * Cogs::Core::ResourceHandle_t< ResourceType >::operator-> ( ) const
inline

Pointer operator, returns the held resource.

Returns
Pointer to the held resource. Only valid if the handle tests as valid (either with HandleIsValid() or by using conversion to bool).

Definition at line 190 of file ResourceHandle.h.

References Cogs::Core::ResourceHandleBase::resource.

◆ operator=()

template<typename ResourceType >
ResourceHandle_t & Cogs::Core::ResourceHandle_t< ResourceType >::operator= ( const ResourceHandle_t< ResourceType > &  other)
inline

Copy assign the handle from the given other handle.

Definition at line 169 of file ResourceHandle.h.

References Cogs::Core::ResourceHandleBase::operator=().

◆ resolve()

template<typename ResourceType >
ResourceType * Cogs::Core::ResourceHandle_t< ResourceType >::resolve ( ) const
inline

Friends And Related Function Documentation

◆ std::hash< ResourceHandle_t< ResourceType > >

template<typename ResourceType >
friend struct std::hash< ResourceHandle_t< ResourceType > >
friend

Definition at line 193 of file ResourceHandle.h.

Member Data Documentation

◆ NoHandle

template<typename T >
const ResourceHandle_t< T > Cogs::Core::ResourceHandle_t< T >::NoHandle = ResourceHandle_t<T>(nullptr)
static

Handle representing a default (or none if default not present) resource.

Provided as shorthand for empty resource handles.

Definition at line 193 of file ResourceHandle.h.


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