EnTT 3.13.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
entt::resource< Type > Class Template Reference

Basic resource handle. More...

#include <resource.hpp>

Public Types

using element_type = Type
 Resource type.
 
using handle_type = std::shared_ptr< element_type >
 Handle type.
 

Public Member Functions

 resource () noexcept
 Default constructor.
 
 resource (handle_type res) noexcept
 Creates a handle from a weak pointer, namely a resource.
 
 resource (const resource &) noexcept=default
 Default copy constructor.
 
 resource (resource &&) noexcept=default
 Default move constructor.
 
template<typename Other >
 resource (const resource< Other > &other, element_type &res) noexcept
 Aliasing constructor.
 
template<typename Other , typename = std::enable_if_t<is_acceptable_v<Other>>>
 resource (const resource< Other > &other) noexcept
 Copy constructs a handle which shares ownership of the resource.
 
template<typename Other , typename = std::enable_if_t<is_acceptable_v<Other>>>
 resource (resource< Other > &&other) noexcept
 Move constructs a handle which takes ownership of the resource.
 
resourceoperator= (const resource &) noexcept=default
 Default copy assignment operator.
 
resourceoperator= (resource &&) noexcept=default
 Default move assignment operator.
 
template<typename Other >
std::enable_if_t< is_acceptable_v< Other >, resource & > operator= (const resource< Other > &other) noexcept
 Copy assignment operator from foreign handle.
 
template<typename Other >
std::enable_if_t< is_acceptable_v< Other >, resource & > operator= (resource< Other > &&other) noexcept
 Move assignment operator from foreign handle.
 
element_typeoperator* () const noexcept
 Returns a reference to the managed resource.
 
 operator element_type & () const noexcept
 Returns a reference to the managed resource.
 
element_typeoperator-> () const noexcept
 Returns a pointer to the managed resource.
 
 operator bool () const noexcept
 Returns true if a handle contains a resource, false otherwise.
 
const handle_typehandle () const noexcept
 Returns the underlying resource handle.
 

Detailed Description

template<typename Type>
class entt::resource< Type >

Basic resource handle.

A handle wraps a resource and extends its lifetime. It also shares the same resource with all other handles constructed from the same element.
As a rule of thumb, resources should never be copied nor moved. Handles are the way to go to push references around.

Template Parameters
TypeType of resource managed by a handle.

Definition at line 22 of file resource.hpp.

Member Typedef Documentation

◆ element_type

template<typename Type >
using entt::resource< Type >::element_type = Type

Resource type.

Definition at line 31 of file resource.hpp.

◆ handle_type

template<typename Type >
using entt::resource< Type >::handle_type = std::shared_ptr<element_type>

Handle type.

Definition at line 33 of file resource.hpp.

Constructor & Destructor Documentation

◆ resource() [1/5]

template<typename Type >
entt::resource< Type >::resource ( )
inlinenoexcept

Default constructor.

Definition at line 36 of file resource.hpp.

◆ resource() [2/5]

template<typename Type >
entt::resource< Type >::resource ( handle_type  res)
inlineexplicitnoexcept

Creates a handle from a weak pointer, namely a resource.

Parameters
resA weak pointer to a resource.

Definition at line 43 of file resource.hpp.

◆ resource() [3/5]

template<typename Type >
template<typename Other >
entt::resource< Type >::resource ( const resource< Other > &  other,
element_type res 
)
inlinenoexcept

Aliasing constructor.

Template Parameters
OtherType of resource managed by the received handle.
Parameters
otherThe handle with which to share ownership information.
resUnrelated and unmanaged resources.

Definition at line 59 of file resource.hpp.

◆ resource() [4/5]

template<typename Type >
template<typename Other , typename = std::enable_if_t<is_acceptable_v<Other>>>
entt::resource< Type >::resource ( const resource< Other > &  other)
inlinenoexcept

Copy constructs a handle which shares ownership of the resource.

Template Parameters
OtherType of resource managed by the received handle.
Parameters
otherThe handle to copy from.

Definition at line 68 of file resource.hpp.

◆ resource() [5/5]

template<typename Type >
template<typename Other , typename = std::enable_if_t<is_acceptable_v<Other>>>
entt::resource< Type >::resource ( resource< Other > &&  other)
inlinenoexcept

Move constructs a handle which takes ownership of the resource.

Template Parameters
OtherType of resource managed by the received handle.
Parameters
otherThe handle to move from.

Definition at line 77 of file resource.hpp.

Member Function Documentation

◆ handle()

template<typename Type >
const handle_type & entt::resource< Type >::handle ( ) const
inlinenoexcept

Returns the underlying resource handle.

Returns
The underlying resource handle.

Definition at line 155 of file resource.hpp.

◆ operator bool()

template<typename Type >
entt::resource< Type >::operator bool ( ) const
inlineexplicitnoexcept

Returns true if a handle contains a resource, false otherwise.

Returns
True if the handle contains a resource, false otherwise.

Definition at line 147 of file resource.hpp.

◆ operator element_type &()

template<typename Type >
entt::resource< Type >::operator element_type & ( ) const
inlinenoexcept

Returns a reference to the managed resource.

Warning
The behavior is undefined if the handle doesn't contain a resource.
Returns
A reference to the managed resource.

Definition at line 131 of file resource.hpp.

◆ operator*()

template<typename Type >
element_type & entt::resource< Type >::operator* ( ) const
inlinenoexcept

Returns a reference to the managed resource.

Warning
The behavior is undefined if the handle doesn't contain a resource.
Returns
A reference to the managed resource.

Definition at line 126 of file resource.hpp.

◆ operator->()

template<typename Type >
element_type * entt::resource< Type >::operator-> ( ) const
inlinenoexcept

Returns a pointer to the managed resource.

Returns
A pointer to the managed resource.

Definition at line 139 of file resource.hpp.

◆ operator=() [1/4]

template<typename Type >
resource & entt::resource< Type >::operator= ( const resource< Type > &  )
defaultnoexcept

Default copy assignment operator.

Returns
This resource handle.

◆ operator=() [2/4]

template<typename Type >
template<typename Other >
std::enable_if_t< is_acceptable_v< Other >, resource & > entt::resource< Type >::operator= ( const resource< Other > &  other)
inlinenoexcept

Copy assignment operator from foreign handle.

Template Parameters
OtherType of resource managed by the received handle.
Parameters
otherThe handle to copy from.
Returns
This resource handle.

Definition at line 100 of file resource.hpp.

◆ operator=() [3/4]

template<typename Type >
resource & entt::resource< Type >::operator= ( resource< Type > &&  )
defaultnoexcept

Default move assignment operator.

Returns
This resource handle.

◆ operator=() [4/4]

template<typename Type >
template<typename Other >
std::enable_if_t< is_acceptable_v< Other >, resource & > entt::resource< Type >::operator= ( resource< Other > &&  other)
inlinenoexcept

Move assignment operator from foreign handle.

Template Parameters
OtherType of resource managed by the received handle.
Parameters
otherThe handle to move from.
Returns
This resource handle.

Definition at line 113 of file resource.hpp.

Friends And Related Symbol Documentation

◆ resource

template<typename Type >
template<typename >
friend class resource
friend

Definition at line 24 of file resource.hpp.


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