Cogs.Core
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Cogs::Core::ResourceHandleBase Struct Reference

Resource handle base class handling reference counting of resources derived from ResourceBase. More...

#include <ResourceHandle.h>

Inheritance diagram for Cogs::Core::ResourceHandleBase:
Cogs::Core::ResourceHandle_t< Animation > Cogs::Core::ResourceHandle_t< Asset > Cogs::Core::ResourceHandle_t< BlueNoise > Cogs::Core::ResourceHandle_t< BufferResource > Cogs::Core::ResourceHandle_t< Effect > Cogs::Core::ResourceHandle_t< Font > Cogs::Core::ResourceHandle_t< GuiDocument > Cogs::Core::ResourceHandle_t< MaterialInstance > Cogs::Core::ResourceHandle_t< Material > Cogs::Core::ResourceHandle_t< Mesh > Cogs::Core::ResourceHandle_t< Model > Cogs::Core::ResourceHandle_t< Sound > Cogs::Core::ResourceHandle_t< Texture > Cogs::Core::ResourceHandle_t< ResourceType >

Public Member Functions

 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 ResourceHandleBase NoHandle = Cogs::Core::ResourceHandleBase(nullptr)
 Provided as shorthand for empty resource handles.
 

Protected Member Functions

void resetInternal (ResourceBase *otherResource)
 Reset the contents of this instance to the given handle and resource.
 

Protected Attributes

ResourceBaseresource = nullptr
 Pointer to held resource.
 

Detailed Description

Resource handle base class handling reference counting of resources derived from ResourceBase.

Definition at line 18 of file ResourceHandle.h.

Constructor & Destructor Documentation

◆ ResourceHandleBase() [1/3]

Cogs::Core::ResourceHandleBase::ResourceHandleBase ( ResourceBase resource)
inline

Constructs a handle with the given integer handle and resource pointer pair.

Parameters
resourcePointer to the resource itself.

Definition at line 28 of file ResourceHandle.h.

◆ ResourceHandleBase() [2/3]

Cogs::Core::ResourceHandleBase::ResourceHandleBase ( const ResourceHandleBase other)
inline

Copy constructs a handle from the given other handle.

Parameters
otherA handle to copy contents from.

Definition at line 38 of file ResourceHandle.h.

References resource.

◆ ResourceHandleBase() [3/3]

Cogs::Core::ResourceHandleBase::ResourceHandleBase ( ResourceHandleBase &&  other)
inlinenoexcept

Move constructs a handle from the given other handle.

The other handle is left empty after construction.

Parameters
otherA handle to move contents from.

Definition at line 48 of file ResourceHandle.h.

◆ ~ResourceHandleBase()

Cogs::Core::ResourceHandleBase::~ResourceHandleBase ( )

Destructs a handle, and if a resource is held, releases the reference to this resource.

Definition at line 7 of file ResourceHandle.cpp.

References Cogs::Core::ResourceBase::decrement(), and resource.

Member Function Documentation

◆ get() [1/2]

ResourceBase * Cogs::Core::ResourceHandleBase::get ( )
inline

Definition at line 108 of file ResourceHandle.h.

◆ get() [2/2]

const ResourceBase * Cogs::Core::ResourceHandleBase::get ( ) const
inline

Definition at line 110 of file ResourceHandle.h.

◆ getId()

ResourceId Cogs::Core::ResourceHandleBase::getId ( ) const

Get the resource id of the held resource.

Definition at line 19 of file ResourceHandle.cpp.

◆ hash()

size_t Cogs::Core::ResourceHandleBase::hash ( size_t  hashValue = Cogs::hash()) const
inline

Definition at line 128 of file ResourceHandle.h.

◆ operator bool()

Cogs::Core::ResourceHandleBase::operator bool ( ) const
inline

Implicit bool conversion operator.

Used to simplify checking for the validity of a handle.

Using the operator, checking a handles validity is similar to checking a pointer:

auto handle = getSomeResourceHandle();
if (handle) { // Performs the conversion to bool, checking if the resource is valid.
handle->methodOnResource(); // Dereference the handle, returning pointer to the managed resource.
}
Returns
A boolean indicating if the handle holds a valid resource or not.

Definition at line 102 of file ResourceHandle.h.

◆ operator!=()

bool Cogs::Core::ResourceHandleBase::operator!= ( const ResourceHandleBase other) const
inline

Compares this instance against other for inequality.

Parameters
otherA handle to compare against.
Returns
A boolean indicating if the handles are considered not equal. True if the integers held by the handles differ. False if they are equal.

Definition at line 85 of file ResourceHandle.h.

◆ operator->() [1/2]

ResourceBase * Cogs::Core::ResourceHandleBase::operator-> ( )
inline

Definition at line 105 of file ResourceHandle.h.

◆ operator->() [2/2]

const ResourceBase * Cogs::Core::ResourceHandleBase::operator-> ( ) const
inline

Definition at line 106 of file ResourceHandle.h.

◆ operator=()

ResourceHandleBase & Cogs::Core::ResourceHandleBase::operator= ( const ResourceHandleBase other)
inline

Assign the handle from the given other handle.

Parameters
otherA handle to copy contents from.
Returns
A reference to this handle instance.

Definition at line 65 of file ResourceHandle.h.

References resource.

Referenced by Cogs::Core::ResourceHandle_t< ResourceType >::operator=().

◆ operator==()

bool Cogs::Core::ResourceHandleBase::operator== ( const ResourceHandleBase other) const
inline

Compares this instance against the contents of other.

Parameters
otherA handle to compare contents with.
Returns
A boolean indicating if the handles are considered equal. True if the integers held by both handles are equal. False if not.

Definition at line 75 of file ResourceHandle.h.

References resource.

◆ reset()

void Cogs::Core::ResourceHandleBase::reset ( ResourceBase otherResource)

Reset the contents of this instance to the given handle and resource.

This will release reference to a held resource if present, and take up ownership of the newly assigned resource.

Parameters
otherResourcePointer to a resource which this handle will assume shared ownership over.

Definition at line 12 of file ResourceHandle.cpp.

References Cogs::Core::ResourceBase::increment().

◆ resetInternal()

void Cogs::Core::ResourceHandleBase::resetInternal ( ResourceBase otherResource)
protected

Reset the contents of this instance to the given handle and resource.

This will release reference to a held resource if present, and take up ownership of the newly assigned resource.

Parameters
otherResourcePointer to a resource which this handle will assume shared ownership over.

Definition at line 21 of file ResourceHandle.cpp.

Member Data Documentation

◆ NoHandle

const Cogs::Core::ResourceHandleBase Cogs::Core::ResourceHandleBase::NoHandle = Cogs::Core::ResourceHandleBase(nullptr)
static

Provided as shorthand for empty resource handles.

Definition at line 123 of file ResourceHandle.h.

Referenced by Cogs::Core::ResourceManagerBase::getResourceHandle(), and Cogs::Core::ResourceManagerBase::releaseInternal().

◆ resource

ResourceBase* Cogs::Core::ResourceHandleBase::resource = nullptr
protected

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