GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::execution::ResourceRegistry< KnownResourcesOrPointers > Class Template Reference

Dynamic container of singleton resource instances, available to tasks defined through a Scheduler. More...

#include <GREM/execution/ResourceRegistry.hpp>

Inheritance diagram for grem::execution::ResourceRegistry< KnownResourcesOrPointers >:

Public Member Functions

 ~ResourceRegistry ()=default
 Destructor.
 ResourceRegistry (ResourceRegistry &&) noexcept=default
 Move constructor.
 ResourceRegistry (const ResourceRegistry &other)
 Copy constructor.
ResourceRegistry & operator= (ResourceRegistry &&) noexcept=default
 Move assignment.
ResourceRegistry & operator= (const ResourceRegistry &other)
 Copy assignment.
void clear () noexcept
 Erase all resources from the registry.
template<resource T, typename... Args>
T & addResource (Args &&... args)
 Add an owned resource to the registry.
template<resource T, typename... Args>
T * addResourceIfMissing (Args &&... args)
 Add an owned resource to the registry if it doesn't already have it.
template<resource T>
T & addResourceOrAssign (T &&value)
 Add an owned resource to the registry, or assign a new value to the existing resource if the registry already has it.
template<resource T, typename... Args>
T & addSharedResource (Args &&... args)
 Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry.
template<resource T, typename... Args>
T * addSharedResourceIfMissing (Args &&... args)
 Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry, if it doesn't already have it.
template<resource T>
T & addSharedResourceOrAssign (T &&value)
 Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry, or assign a new value to the existing resource if the registry already has it.
template<resource T>
T & addExternalResource (T *resource)
 Add an unowned external resource reference to the registry.
template<resource T>
T * addExternalResourceIfMissing (T *resource)
 Add an unowned external resource reference to the registry if it doesn't already have it.
template<resource T>
bool removeResource () noexcept
 Erase a resource from the registry.
template<resource T>
bool hasResource () const noexcept
 Check if the registry contains a specific resource.
template<resource T>
T & getResource ()
 Get a specific resource in the registry.
template<resource T>
const T & getResource () const
 Get a specific resource in the registry.
template<resource T>
T * findResource () noexcept
 Try to get a specific resource in the registry.
template<resource T>
const T * findResource () const noexcept
 Try to get a specific resource in the registry.
constexpr Tuple (const Tuple &)=default
constexpr Tuple (Tuple &&) noexcept((std::is_nothrow_move_constructible_v< Ts > &&... &&true))=default

Detailed Description

template<typename... KnownResourcesOrPointers>
class grem::execution::ResourceRegistry< KnownResourcesOrPointers >

Dynamic container of singleton resource instances, available to tasks defined through a Scheduler.

This container supports extending the set of possible resource types dynamically at runtime.

Template Parameters
KnownResourcesOrPointerscompile-time-known set of possible resource types, or pointers to external resources, which are given dedicated slots in the resource registry to speed up access to them. Any unknown resource types that are not in this list will be stored in a dynamic associative container keyed by the resource's typeid, which is looked up at runtime, incurring some performance overhead.
See also
ResourceTable

Constructor & Destructor Documentation

◆ ~ResourceRegistry()

template<typename... KnownResourcesOrPointers>
grem::execution::ResourceRegistry< KnownResourcesOrPointers >::~ResourceRegistry ( )
default

Destructor.

◆ ResourceRegistry() [1/2]

template<typename... KnownResourcesOrPointers>
grem::execution::ResourceRegistry< KnownResourcesOrPointers >::ResourceRegistry ( ResourceRegistry< KnownResourcesOrPointers > && )
defaultnoexcept

Move constructor.

◆ ResourceRegistry() [2/2]

template<typename... KnownResourcesOrPointers>
grem::execution::ResourceRegistry< KnownResourcesOrPointers >::ResourceRegistry ( const ResourceRegistry< KnownResourcesOrPointers > & other)
inline

Copy constructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename... KnownResourcesOrPointers>
ResourceRegistry & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::operator= ( ResourceRegistry< KnownResourcesOrPointers > && )
defaultnoexcept

Move assignment.

◆ operator=() [2/2]

template<typename... KnownResourcesOrPointers>
ResourceRegistry & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::operator= ( const ResourceRegistry< KnownResourcesOrPointers > & other)
inline

Copy assignment.

◆ clear()

template<typename... KnownResourcesOrPointers>
void grem::execution::ResourceRegistry< KnownResourcesOrPointers >::clear ( )
inlinenoexcept

Erase all resources from the registry.

Note
Each removed resource object is destroyed if it is owned by the registry, or if it has shared ownership and removing it causes its reference count to hit 0. Otherwise, e.g. if the removed resource was added using addExternalResource(), the object is not destroyed.

◆ addResource()

template<typename... KnownResourcesOrPointers>
template<resource T, typename... Args>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addResource ( Args &&... args)
inline

Add an owned resource to the registry.

Template Parameters
Tresource type to add.
Parameters
argsarguments to forward to the resource constructor.
Returns
a reference to the newly created resource.
Exceptions
std::logic_errorif the registry already contained a resource of the specified type.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource constructor.

◆ addResourceIfMissing()

template<typename... KnownResourcesOrPointers>
template<resource T, typename... Args>
T * grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addResourceIfMissing ( Args &&... args)
inline

Add an owned resource to the registry if it doesn't already have it.

Template Parameters
Tresource type to add.
Parameters
argsarguments to forward to the resource constructor.
Returns
a pointer to the newly created resource, or nullptr if the registry already contains a resource of the specified type.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource constructor.

◆ addResourceOrAssign()

template<typename... KnownResourcesOrPointers>
template<resource T>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addResourceOrAssign ( T && value)
inline

Add an owned resource to the registry, or assign a new value to the existing resource if the registry already has it.

Template Parameters
Tresource type to add.
Parameters
valuevalue of the resource to add or assign.
Returns
a reference to the newly created resource, or to the existing resource if it was already in place.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource's copy/move constructor or copy/move assignment operator.

◆ addSharedResource()

template<typename... KnownResourcesOrPointers>
template<resource T, typename... Args>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addSharedResource ( Args &&... args)
inline

Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry.

Template Parameters
Tresource type to add.
Parameters
argsarguments to forward to the resource constructor.
Returns
a reference to the newly created resource.
Exceptions
std::logic_errorif the registry already contained a resource of the specified type.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource constructor.

◆ addSharedResourceIfMissing()

template<typename... KnownResourcesOrPointers>
template<resource T, typename... Args>
T * grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addSharedResourceIfMissing ( Args &&... args)
inline

Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry, if it doesn't already have it.

Template Parameters
Tresource type to add.
Parameters
argsarguments to forward to the resource constructor.
Returns
a pointer to the newly created resource, or nullptr if the registry already contains a resource of the specified type.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource constructor.

◆ addSharedResourceOrAssign()

template<typename... KnownResourcesOrPointers>
template<resource T>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addSharedResourceOrAssign ( T && value)
inline

Add a reference-counted resource to the registry, whose ownership is shared between copies of the registry, or assign a new value to the existing resource if the registry already has it.

Template Parameters
Tresource type to add.
Parameters
valuevalue of the resource to add or assign.
Returns
a reference to the newly created resource, or to the existing resource if it was already in place.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the resource's copy/move constructor or copy/move assignment operator.

◆ addExternalResource()

template<typename... KnownResourcesOrPointers>
template<resource T>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addExternalResource ( T * resource)
inline

Add an unowned external resource reference to the registry.

Template Parameters
Tresource type to add.
Parameters
resourcenon-owning pointer to the resource to add to the registry. Must not be nullptr.
Returns
*resource.
Exceptions
std::logic_errorif the registry already contained a resource of the specified type.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ addExternalResourceIfMissing()

template<typename... KnownResourcesOrPointers>
template<resource T>
T * grem::execution::ResourceRegistry< KnownResourcesOrPointers >::addExternalResourceIfMissing ( T * resource)
inline

Add an unowned external resource reference to the registry if it doesn't already have it.

Template Parameters
Tresource type to add.
Parameters
resourcenon-owning pointer to the resource to add to the registry. Must not be nullptr.
Returns
resource, or nullptr if the registry already contains a resource of the specified type.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ removeResource()

template<typename... KnownResourcesOrPointers>
template<resource T>
bool grem::execution::ResourceRegistry< KnownResourcesOrPointers >::removeResource ( )
inlinenoexcept

Erase a resource from the registry.

Template Parameters
Tresource type to remove.
Returns
true if the registry contained a resource of the specified type, false otherwise.
Note
The removed resource object is destroyed if it is owned by the registry, or if it has shared ownership and removing it causes its reference count to hit 0. Otherwise, e.g. if the removed resource was added using addExternalResource(), the object is not destroyed.

◆ hasResource()

template<typename... KnownResourcesOrPointers>
template<resource T>
bool grem::execution::ResourceRegistry< KnownResourcesOrPointers >::hasResource ( ) const
inlinenodiscardnoexcept

Check if the registry contains a specific resource.

Template Parameters
Tresource type to check for.
Returns
true if the registry contains a resource of the specified type, false otherwise.

◆ getResource() [1/2]

template<typename... KnownResourcesOrPointers>
template<resource T>
T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::getResource ( )
inlinenodiscard

Get a specific resource in the registry.

Template Parameters
Tresource type to get.
Returns
a reference to the specified resource.
Exceptions
std::out_of_rangeif the registry does not contain a resource of the specified type.

◆ getResource() [2/2]

template<typename... KnownResourcesOrPointers>
template<resource T>
const T & grem::execution::ResourceRegistry< KnownResourcesOrPointers >::getResource ( ) const
inlinenodiscard

Get a specific resource in the registry.

Template Parameters
Tresource type to get.
Returns
a read-only reference to the specified resource.
Exceptions
std::out_of_rangeif the registry does not contain a resource of the specified type.

◆ findResource() [1/2]

template<typename... KnownResourcesOrPointers>
template<resource T>
T * grem::execution::ResourceRegistry< KnownResourcesOrPointers >::findResource ( )
inlinenodiscardnoexcept

Try to get a specific resource in the registry.

Template Parameters
Tresource type to get.
Returns
a pointer to the specified resource, or nullptr if the registry does not contain a resource of the specified type.

◆ findResource() [2/2]

template<typename... KnownResourcesOrPointers>
template<resource T>
const T * grem::execution::ResourceRegistry< KnownResourcesOrPointers >::findResource ( ) const
inlinenodiscardnoexcept

Try to get a specific resource in the registry.

Template Parameters
Tresource type to get.
Returns
a read-only pointer to the specified resource, or nullptr if the registry does not contain a resource of the specified type.

◆ Tuple() [1/2]

template<typename... KnownResourcesOrPointers>
grem::Tuple< Ts >::Tuple ( const Tuple & )
constexprdefault

◆ Tuple() [2/2]

template<typename... KnownResourcesOrPointers>
grem::Tuple< Ts >::Tuple ( Tuple && )
constexprdefaultnoexcept

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