[Bf-blender-cvs] [b93c4458092] master: BLI: return pointer to added resource
Jacques Lucke
noreply at git.blender.org
Tue Apr 6 15:50:03 CEST 2021
Commit: b93c4458092357dd913477a41e201b425c35a898
Author: Jacques Lucke
Date: Tue Apr 6 15:49:38 2021 +0200
Branches: master
https://developer.blender.org/rBb93c4458092357dd913477a41e201b425c35a898
BLI: return pointer to added resource
Without this, the caller often has to get the pointer to the
resource before adding it to the resource scope.
===================================================================
M source/blender/blenlib/BLI_resource_scope.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_resource_scope.hh b/source/blender/blenlib/BLI_resource_scope.hh
index f606dc0c0a1..e5a698f25f1 100644
--- a/source/blender/blenlib/BLI_resource_scope.hh
+++ b/source/blender/blenlib/BLI_resource_scope.hh
@@ -72,38 +72,46 @@ class ResourceScope : NonCopyable, NonMovable {
* Pass ownership of the resource to the ResourceScope. It will be destructed and freed when
* the collector is destructed.
*/
- template<typename T> void add(std::unique_ptr<T> resource, const char *name)
+ template<typename T> T *add(std::unique_ptr<T> resource, const char *name)
{
BLI_assert(resource.get() != nullptr);
+ T *ptr = resource.release();
+ if (ptr == nullptr) {
+ return nullptr;
+ }
this->add(
- resource.release(),
+ ptr,
[](void *data) {
T *typed_data = reinterpret_cast<T *>(data);
delete typed_data;
},
name);
+ return ptr;
}
/**
* Pass ownership of the resource to the ResourceScope. It will be destructed when the
* collector is destructed.
*/
- template<typename T> void add(destruct_ptr<T> resource, const char *name)
+ template<typename T> T *add(destruct_ptr<T> resource, const char *name)
{
+ T *ptr = resource.release();
+ if (ptr == nullptr) {
+ return nullptr;
+ }
/* There is no need to keep track of such types. */
if (std::is_trivially_destructible_v<T>) {
- resource.release();
- return;
+ return ptr;
}
- BLI_assert(resource.get() != nullptr);
this->add(
- resource.release(),
+ ptr,
[](void *data) {
T *typed_data = reinterpret_cast<T *>(data);
typed_data->~T();
},
name);
+ return ptr;
}
/**
More information about the Bf-blender-cvs
mailing list