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 140 of file resource_manager_vk.h.

Member Typedef Documentation

◆ ResourceType

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

Definition at line 142 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 149 of file resource_manager_vk.h.

150  : 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 159 of file resource_manager_vk.h.

161  : resource_manager_(std::move(resource_manager)),
162  resource_(
163  std::make_unique<ResourceVKT<ResourceType>>(std::move(resource))) {}

◆ ~UniqueResourceVKT()

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

Definition at line 165 of file resource_manager_vk.h.

165 { 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 168 of file resource_manager_vk.h.

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

◆ Reset()

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

Reclaims the existing resource, if any.

Definition at line 184 of file resource_manager_vk.h.

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

Referenced by impeller::UniqueResourceVKT< ImageResource >::Swap(), and impeller::UniqueResourceVKT< ImageResource >::~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 178 of file resource_manager_vk.h.

178  {
179  Reset();
180  resource_ = std::make_unique<ResourceVKT<ResourceType>>(std::move(other));
181  }

The documentation for this class was generated from the following file:
impeller::UniqueResourceVKT::Reset
void Reset()
Reclaims the existing resource, if any.
Definition: resource_manager_vk.h:184