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

Member Typedef Documentation

◆ ResourceType

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

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

155  : 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 164 of file resource_manager_vk.h.

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

◆ ~UniqueResourceVKT()

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

Definition at line 170 of file resource_manager_vk.h.

170 { 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 173 of file resource_manager_vk.h.

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

◆ Reset()

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

Reclaims the existing resource, if any.

Definition at line 189 of file resource_manager_vk.h.

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

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

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

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:189