EnTT: entt::resource< Type > Class Template Reference

EnTT 3.16.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 new resource handle.
| 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<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<Other>>>
| resource (resource< Other > &&other) noexcept
| Move constructs a handle which takes ownership of the resource.
| ~resource ()=default
| Default destructor.
resource & | operator= (const resource &) noexcept=default
| Default copy assignment operator.
resource & | operator= (resource &&) noexcept=default
| Default move assignment operator.
template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
resource & | operator= (const resource< Other > &other) noexcept
| Copy assignment operator from foreign handle.
template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
resource & | operator= (resource< Other > &&other) noexcept
| Move assignment operator from foreign handle.
void | swap (resource &other) noexcept
| Exchanges the content with that of a given resource.
element_type & | operator* () const noexcept
| Returns a reference to the managed resource.
| operator element_type & () const noexcept
| Returns a reference to the managed resource.
element_type * | operator-> () const noexcept
| Returns a pointer to the managed resource.
| operator bool () const noexcept
| Returns true if a handle contains a resource, false otherwise.
void | reset ()
| Releases the ownership of the managed resource.
void | reset (handle_type other)
| Replaces the managed resource.
handle_type | handle () 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

  Type | Type 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 new resource handle.

Parameters

  res | A handle 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

  Other | Type of resource managed by the received handle.

Parameters

  other | The handle with which to share ownership information.
  res | Unrelated 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<Other>>>

entt::resource< Type >::resource | ( | const resource< Other > & | other | ) |
| inlinenoexcept

Copy constructs a handle which shares ownership of the resource.

Template Parameters

  Other | Type of resource managed by the received handle.

Parameters

  other | The 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<Other>>>

entt::resource< Type >::resource | ( | resource< Other > && | other | ) |
| inlinenoexcept

Move constructs a handle which takes ownership of the resource.

Template Parameters

  Other | Type of resource managed by the received handle.

Parameters

  other | The handle to move from.

Definition at line 77 of file resource.hpp.

## Member Function Documentation

## ◆ handle()

template<typename Type>

handle_type entt::resource< Type >::handle | ( |  | ) | const
| inlinenodiscardnoexcept

Returns the underlying resource handle.

Returns
  The underlying resource handle.

Definition at line 178 of file resource.hpp.

## ◆ operator bool()

template<typename Type>

entt::resource< Type >::operator bool | ( |  | ) | const
| inlineexplicitnodiscardnoexcept

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

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

Definition at line 157 of file resource.hpp.

## ◆ operator element_type &()

template<typename Type>

entt::resource< Type >::operator element_type & | ( |  | ) | const
| inlinenodiscardnoexcept

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 141 of file resource.hpp.

## ◆ operator*()

template<typename Type>

element_type & entt::resource< Type >::operator* | ( |  | ) | const
| inlinenodiscardnoexcept

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 136 of file resource.hpp.

## ◆ operator->()

template<typename Type>

element_type * entt::resource< Type >::operator-> | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a pointer to the managed resource.

Returns
  A pointer to the managed resource.

Definition at line 149 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, typename = std::enable_if_t<is_acceptable<Other>>>

resource & entt::resource< Type >::operator= | ( | const resource< Other > & | other | ) |
| inlinenoexcept

Copy assignment operator from foreign handle.

Template Parameters

  Other | Type of resource managed by the received handle.

Parameters

  other | The handle to copy from.

Returns
  This resource handle.

Definition at line 102 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, typename = std::enable_if_t<is_acceptable<Other>>>

resource & entt::resource< Type >::operator= | ( | resource< Other > && | other | ) |
| inlinenoexcept

Move assignment operator from foreign handle.

Template Parameters

  Other | Type of resource managed by the received handle.

Parameters

  other | The handle to move from.

Returns
  This resource handle.

Definition at line 114 of file resource.hpp.

## ◆ reset() [1/2]

template<typename Type>

void entt::resource< Type >::reset | ( |  | ) |
| inline

Releases the ownership of the managed resource.

Definition at line 162 of file resource.hpp.

## ◆ reset() [2/2]

template<typename Type>

void entt::resource< Type >::reset | ( | handle_type | other | ) |
| inline

Replaces the managed resource.

Parameters

  other | A handle to a resource.

Definition at line 170 of file resource.hpp.

## ◆ swap()

template<typename Type>

void entt::resource< Type >::swap | ( | resource< Type > & | other | ) |
| inlinenoexcept

Exchanges the content with that of a given resource.

Parameters

  other | Resource to exchange the content with.

Definition at line 123 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:

- src/entt/resource/fwd.hpp
- src/entt/resource/resource.hpp