API Documentation
Public Member Functions | List of all members
nkGraphics::Manager< T > Class Template Reference

Base class for resource managers. More...

Public Member Functions

T * createOrRetrieve (nkMemory::StringView name)
 
T * record (nkMemory::StringView name, nkMemory::UniquePtr< T > resource)
 
T * get (nkMemory::StringView name) const
 
T * getByIndex (unsigned int index) const
 
void rename (nkMemory::StringView currentName, nkMemory::StringView newName)
 
void erase (nkMemory::StringView name)
 
nkMemory::UniquePtr< T > relinquish (nkMemory::StringView name)
 

Detailed Description

template<typename T>
class nkGraphics::Manager< T >

Base class for resource managers.

Member Function Documentation

◆ createOrRetrieve()

template<typename T >
T* nkGraphics::Manager< T >::createOrRetrieve ( nkMemory::StringView  name)

Creates (if unavailable) or retrieves (if available) a resource attached to passed name.

Parameters
nameThe name, aka identifier, of the resource to create or retrieve.
Returns
The resource attached to passed name. The Manager is the owner of the memory returned.

◆ record()

template<typename T >
T* nkGraphics::Manager< T >::record ( nkMemory::StringView  name,
nkMemory::UniquePtr< T >  resource 
)

Records an already existing resource in the manager, passing its ownership around.

Parameters
nameThe name under which the resource should be recorded.
resourceThe resource to record.
Returns
A raw pointer over the resource, now recorded in the manager.

◆ get()

template<typename T >
T* nkGraphics::Manager< T >::get ( nkMemory::StringView  name) const

Returns a resource attached to a name, if available.

Parameters
nameThe name of the resource that should be retrieved.
Returns
The resource if existing, nullptr else.

◆ getByIndex()

template<typename T >
T* nkGraphics::Manager< T >::getByIndex ( unsigned int  index) const

Returns the resource at given index, if available.

Parameters
indexThe index of the resource to retrieve.
Returns
The resource attached to given index.
Remarks
An index refers to the index in the manager's container, so one index can be attached through different resources depending on allocations. This method is meant to loop on all resources in one go, because of this.

◆ rename()

template<typename T >
void nkGraphics::Manager< T >::rename ( nkMemory::StringView  currentName,
nkMemory::StringView  newName 
)

Renames a resource.

Parameters
currentNameThe name of the resource to rename.
newNameThe name to reassign to the resource.

◆ erase()

template<typename T >
void nkGraphics::Manager< T >::erase ( nkMemory::StringView  name)

Erases a resource. Memory attached to it will be freed.

Parameters
nameThe name identifying the resource to erase.

◆ relinquish()

template<typename T >
nkMemory::UniquePtr<T> nkGraphics::Manager< T >::relinquish ( nkMemory::StringView  name)

Requests the manager to relinquish the ownership of a resource and pass it around.

Parameters
nameThe name of the recorded resource to relinquish.
Returns
The ownership over the resource requested if available, nullptr otherwise.

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