Flutter Impeller
impeller::UniqueResourceVKT< ResourceType_ > Class Template Referencefinal

A unique handle to a resource which will be reclaimed by the specified resource manager. More...

#include <resource_manager_vk.h>

Public Types

using ResourceType = ResourceType_
 

Public Member Functions

 UniqueResourceVKT (std::weak_ptr< ResourceManagerVK > resource_manager)
 Construct a unique resource handle belonging to a manager. More...
 
 UniqueResourceVKT (std::weak_ptr< ResourceManagerVK > resource_manager, ResourceType &&resource)
 Construct a unique resource handle belonging to a manager. More...
 
 ~UniqueResourceVKT ()
 
const ResourceTypeoperator-> () const
 Returns a pointer to the resource. More...
 
void Swap (ResourceType &&other)
 Reclaims the existing resource, if any, and replaces it. More...
 
void Reset ()
 Reclaims the existing resource, if any. More...
 

Detailed Description

template<class ResourceType_>
class impeller::UniqueResourceVKT< ResourceType_ >

A unique handle to a resource which will be reclaimed by the specified resource manager.

Template Parameters
ResourceType_A move-constructible resource type.

Definition at line 143 of file resource_manager_vk.h.

Member Typedef Documentation

◆ ResourceType

template<class ResourceType_ >
using impeller::UniqueResourceVKT< ResourceType_ >::ResourceType = ResourceType_

Definition at line 145 of file resource_manager_vk.h.

Constructor & Destructor Documentation

◆ UniqueResourceVKT() [1/2]

template<class ResourceType_ >
impeller::UniqueResourceVKT< ResourceType_ >::UniqueResourceVKT ( std::weak_ptr< ResourceManagerVK resource_manager)
inlineexplicit

Construct a unique resource handle belonging to a manager.

Initially the handle is empty, and can be populated by calling Swap.

Parameters
[in]resource_managerThe resource manager.

Definition at line 152 of file resource_manager_vk.h.

153  : resource_manager_(std::move(resource_manager)) {}

◆ UniqueResourceVKT() [2/2]

template<class ResourceType_ >
impeller::UniqueResourceVKT< ResourceType_ >::UniqueResourceVKT ( std::weak_ptr< ResourceManagerVK resource_manager,
ResourceType &&  resource 
)
inlineexplicit

Construct a unique resource handle belonging to a manager.

Initially the handle is populated with the specified resource, but can be replaced (reclaiming the old resource) by calling Swap.

Parameters
[in]resource_managerThe resource manager.
[in]resourceThe resource to move.

Definition at line 162 of file resource_manager_vk.h.

164  : resource_manager_(std::move(resource_manager)),
165  resource_(
166  std::make_unique<ResourceVKT<ResourceType>>(std::move(resource))) {}

◆ ~UniqueResourceVKT()

template<class ResourceType_ >
impeller::UniqueResourceVKT< ResourceType_ >::~UniqueResourceVKT ( )
inline

Definition at line 168 of file resource_manager_vk.h.

168 { Reset(); }
void Reset()
Reclaims the existing resource, if any.

References impeller::UniqueResourceVKT< ResourceType_ >::Reset().

Member Function Documentation

◆ operator->()

template<class ResourceType_ >
const ResourceType* impeller::UniqueResourceVKT< ResourceType_ >::operator-> ( ) const
inline

Returns a pointer to the resource.

Definition at line 171 of file resource_manager_vk.h.

171  {
172  // If this would segfault, fail with a nicer error message.
173  FML_CHECK(resource_) << "UniqueResourceVKT was reclaimed.";
174 
175  return resource_.get()->Get();
176  }

◆ Reset()

template<class ResourceType_ >
void impeller::UniqueResourceVKT< ResourceType_ >::Reset ( )
inline

Reclaims the existing resource, if any.

Definition at line 187 of file resource_manager_vk.h.

187  {
188  if (!resource_) {
189  return;
190  }
191  // If there is a manager, ask it to reclaim the resource. If there isn't a
192  // manager (because the manager has been destroyed), just drop it on the
193  // floor here.
194  if (auto manager = resource_manager_.lock()) {
195  manager->Reclaim(std::move(resource_));
196  }
197  resource_.reset();
198  }

Referenced by impeller::UniqueResourceVKT< ResourceType_ >::Swap(), and impeller::UniqueResourceVKT< ResourceType_ >::~UniqueResourceVKT().

◆ Swap()

template<class ResourceType_ >
void impeller::UniqueResourceVKT< ResourceType_ >::Swap ( ResourceType &&  other)
inline

Reclaims the existing resource, if any, and replaces it.

Parameters
[in]otherThe (new) resource to move.

Definition at line 181 of file resource_manager_vk.h.

181  {
182  Reset();
183  resource_ = std::make_unique<ResourceVKT<ResourceType>>(std::move(other));
184  }

References impeller::UniqueResourceVKT< ResourceType_ >::Reset().


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