Clementine
Public Member Functions | Friends | List of all members
entt::resource_handle< Resource > Class Template Reference

Shared resource handle. More...

#include <entt.hpp>

Public Member Functions

 resource_handle () ENTT_NOEXCEPT=default
 Default constructor.
 
const Resource & get () const ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
Resource & get () ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
 operator const Resource & () const ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
 operator Resource & () ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
const Resource & operator* () const ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
Resource & operator* () ENTT_NOEXCEPT
 Gets a reference to the managed resource. More...
 
const Resource * operator-> () const ENTT_NOEXCEPT
 Gets a pointer to the managed resource. More...
 
Resource * operator-> () ENTT_NOEXCEPT
 Gets a pointer to the managed resource. More...
 
 operator bool () const ENTT_NOEXCEPT
 Returns true if a handle contains a resource, false otherwise. More...
 

Friends

struct resource_cache< Resource >
 Resource handles are friends of their caches.
 

Detailed Description

template<typename Resource>
class entt::resource_handle< Resource >

Shared resource handle.

A shared resource handle is a small class that wraps a resource and keeps it alive even if it's deleted from the cache. It can be either copied or moved. A handle shares a reference to the same resource with all the other handles constructed for the same identifier.
As a rule of thumb, resources should never be copied nor moved. Handles are the way to go to keep references to them.

Template Parameters
ResourceType of resource managed by a handle.

Member Function Documentation

◆ get() [1/2]

template<typename Resource >
const Resource& entt::resource_handle< Resource >::get ( ) const
inline

Gets 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.

◆ get() [2/2]

template<typename Resource >
Resource& entt::resource_handle< Resource >::get ( )
inline

Gets 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.

◆ operator bool()

template<typename Resource >
entt::resource_handle< Resource >::operator bool ( ) const
inlineexplicit

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

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

◆ operator const Resource &()

template<typename Resource >
entt::resource_handle< Resource >::operator const Resource & ( ) const
inline

Gets 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.

◆ operator Resource &()

template<typename Resource >
entt::resource_handle< Resource >::operator Resource & ( )
inline

Gets 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.

◆ operator*() [1/2]

template<typename Resource >
const Resource& entt::resource_handle< Resource >::operator* ( ) const
inline

Gets 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.

◆ operator*() [2/2]

template<typename Resource >
Resource& entt::resource_handle< Resource >::operator* ( )
inline

Gets 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.

◆ operator->() [1/2]

template<typename Resource >
const Resource* entt::resource_handle< Resource >::operator-> ( ) const
inline

Gets a pointer to the managed resource.

Warning
The behavior is undefined if the handle doesn't contain a resource.
Returns
A pointer to the managed resource or nullptr if the handle contains no resource at all.

◆ operator->() [2/2]

template<typename Resource >
Resource* entt::resource_handle< Resource >::operator-> ( )
inline

Gets a pointer to the managed resource.

Warning
The behavior is undefined if the handle doesn't contain a resource.
Returns
A pointer to the managed resource or nullptr if the handle contains no resource at all.

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