[Bf-blender-cvs] [b5c2c3aba88] master: BLI: rename resource collector to resource scope
Jacques Lucke
noreply at git.blender.org
Thu Apr 1 15:55:35 CEST 2021
Commit: b5c2c3aba886f521a0cade5b8450683c20843d3a
Author: Jacques Lucke
Date: Thu Apr 1 15:55:08 2021 +0200
Branches: master
https://developer.blender.org/rBb5c2c3aba886f521a0cade5b8450683c20843d3a
BLI: rename resource collector to resource scope
Differential Revision: https://developer.blender.org/D10857
===================================================================
R066 source/blender/blenlib/BLI_resource_collector.hh source/blender/blenlib/BLI_resource_scope.hh
M source/blender/blenlib/CMakeLists.txt
M source/blender/editors/space_spreadsheet/space_spreadsheet.cc
M source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
M source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.hh
M source/blender/functions/FN_multi_function_network_optimization.hh
M source/blender/functions/FN_multi_function_params.hh
M source/blender/functions/intern/multi_function_network_evaluation.cc
M source/blender/functions/intern/multi_function_network_optimization.cc
M source/blender/modifiers/intern/MOD_nodes.cc
M source/blender/nodes/NOD_node_tree_multi_function.hh
M source/blender/nodes/intern/node_tree_multi_function.cc
M source/blender/nodes/intern/type_callbacks.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_resource_collector.hh b/source/blender/blenlib/BLI_resource_scope.hh
similarity index 66%
rename from source/blender/blenlib/BLI_resource_collector.hh
rename to source/blender/blenlib/BLI_resource_scope.hh
index 70804ceb1f1..f606dc0c0a1 100644
--- a/source/blender/blenlib/BLI_resource_collector.hh
+++ b/source/blender/blenlib/BLI_resource_scope.hh
@@ -19,12 +19,24 @@
/** \file
* \ingroup bli
*
- * A ResourceCollector holds an arbitrary set of resources, that will be destructed and/or freed
- * when the ResourceCollector is destructed. This is useful when some object has to take ownership
- * of other objects, but it does not know the type of those other objects.
+ * A `ResourceScope` takes ownership of arbitrary data/resources. Those resources will be
+ * destructed and/or freed when the `ResourceScope` is destructed. Destruction happens in reverse
+ * order. That allows resources do depend on other resources that have been added before.
*
- * Resources owned by the ResourceCollector will be freed in reverse order. That allows resources
- * that are added later to depend on resources that have been added before.
+ * A `ResourceScope` can also be thought of as a dynamic/runtime version of normal scopes in C++
+ * that are surrounded by braces.
+ *
+ * The main purpose of a `ResourceScope` is to allow functions to inject data into the scope of the
+ * caller. Traditionally, that can only be done by returning a value that owns everything it needs.
+ * This is fine until one has to deal with optional ownership. There are many ways to have a type
+ * optionally own something else, all of which are fairly annoying. A `ResourceScope` can be used
+ * to avoid having to deal with optional ownership. If some value would be owned, it can just be
+ * added to the resource scope, otherwise not.
+ *
+ * When a function takes a `ResourceScope` as parameter, it usually means that its return value
+ * will live at least as long as the passed in resources scope. However, it might also live longer.
+ * That can happen when the function returns a reference to statically allocated data or
+ * dynamically allocated data depending on some condition.
*/
#include "BLI_linear_allocator.hh"
@@ -33,7 +45,7 @@
namespace blender {
-class ResourceCollector : NonCopyable, NonMovable {
+class ResourceScope : NonCopyable, NonMovable {
private:
struct ResourceData {
void *data;
@@ -45,9 +57,9 @@ class ResourceCollector : NonCopyable, NonMovable {
Vector<ResourceData> m_resources;
public:
- ResourceCollector() = default;
+ ResourceScope() = default;
- ~ResourceCollector()
+ ~ResourceScope()
{
/* Free in reversed order. */
for (int64_t i = m_resources.size(); i--;) {
@@ -57,7 +69,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Pass ownership of the resource to the ResourceCollector. It will be destructed and freed when
+ * 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)
@@ -73,7 +85,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Pass ownership of the resource to the ResourceCollector. It will be destructed when the
+ * 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)
@@ -95,7 +107,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Pass ownership of some resource to the ResourceCollector. The given free function will be
+ * Pass ownership of some resource to the ResourceScope. The given free function will be
* called when the collector is destructed.
*/
void add(void *userdata, void (*free)(void *), const char *name)
@@ -108,7 +120,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Construct an object with the same value in the ResourceCollector and return a reference to the
+ * Construct an object with the same value in the ResourceScope and return a reference to the
* new value.
*/
template<typename T> T &add_value(T &&value, const char *name)
@@ -126,7 +138,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Utility method to construct an instance of type T that will be owned by the ResourceCollector.
+ * Utility method to construct an instance of type T that will be owned by the ResourceScope.
*/
template<typename T, typename... Args> T &construct(const char *name, Args &&... args)
{
@@ -137,7 +149,7 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
- * Print the names of all the resources that are owned by this ResourceCollector. This can be
+ * Print the names of all the resources that are owned by this ResourceScope. This can be
* useful for debugging.
*/
void print(StringRef name) const
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index d7a27cc4531..e66049c9bd6 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -258,7 +258,7 @@ set(SRC
BLI_rand.h
BLI_rand.hh
BLI_rect.h
- BLI_resource_collector.hh
+ BLI_resource_scope.hh
BLI_scanfill.h
BLI_session_uuid.h
BLI_set.hh
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 0f7709b464e..403e6cd6206 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -17,7 +17,7 @@
#include <cstring>
#include "BLI_listbase.h"
-#include "BLI_resource_collector.hh"
+#include "BLI_resource_scope.hh"
#include "BKE_screen.h"
@@ -138,7 +138,7 @@ class FallbackSpreadsheetDrawer : public SpreadsheetDrawer {
static void gather_spreadsheet_columns(const bContext *C,
SpreadsheetColumnLayout &column_layout,
- blender::ResourceCollector &resources)
+ blender::ResourceScope &scope)
{
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
ID *used_id = get_used_id(C);
@@ -158,16 +158,16 @@ static void gather_spreadsheet_columns(const bContext *C,
return;
}
- return spreadsheet_columns_from_geometry(C, object_eval, column_layout, resources);
+ return spreadsheet_columns_from_geometry(C, object_eval, column_layout, scope);
}
static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
{
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
- blender::ResourceCollector resources;
+ blender::ResourceScope scope;
SpreadsheetColumnLayout column_layout;
- gather_spreadsheet_columns(C, column_layout, resources);
+ gather_spreadsheet_columns(C, column_layout, scope);
sspreadsheet->runtime->visible_rows = column_layout.row_indices.size();
sspreadsheet->runtime->tot_columns = column_layout.columns.size();
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
index 910bc0a34ec..7eea6c48676 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
@@ -41,13 +41,13 @@ using blender::bke::ReadAttributePtr;
static void add_columns_for_instances(const InstancesComponent &instances_component,
SpreadsheetColumnLayout &column_layout,
- ResourceCollector &resources)
+ ResourceScope &scope)
{
Span<InstancedData> instance_data = instances_component.instanced_data();
Span<float4x4> transforms = instances_component.transforms();
Vector<std::unique_ptr<SpreadsheetColumn>> &columns =
- resources.construct<Vector<std::unique_ptr<SpreadsheetColumn>>>("columns");
+ scope.construct<Vector<std::unique_ptr<SpreadsheetColumn>>>("columns");
columns.append(spreadsheet_column_from_function(
"Name", [instance_data](int index, CellValue &r_cell_value) {
@@ -330,13 +330,13 @@ static Span<int64_t> filter_mesh_elements_by_selection(const bContext *C,
Object *object_eval,
const MeshComponent *component,
const AttributeDomain domain,
- ResourceCollector &resources)
+ ResourceScope &scope)
{
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
const bool show_only_selected = sspreadsheet->filter_flag & SPREADSHEET_FILTER_SELECTED_ONLY;
if (object_eval->mode == OB_MODE_EDIT && show_only_selected) {
Object *object_orig = DEG_get_original_object(object_eval);
- Vector<int64_t> &visible_rows = resources.construct<Vector<int64_t>>("visible rows");
+ Vector<int64_t> &visible_rows = scope.construct<Vector<int64_t>>("visible rows");
const Mesh *mesh_eval = component->get_for_read();
Mesh *mesh_orig = (Mesh *)object_orig->data;
BMesh *bm = mesh_orig->edit_mesh->bm;
@@ -389,14 +389,14 @@ static GeometryComponentType get_display_component_type(const bContext *C, Objec
void spreadsheet_columns_from_geometry(const bContext *C,
Object *object_eval,
SpreadsheetColumnLayout &column_layout,
- ResourceCollector &resources)
+ ResourceScope &scope)
{
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
const AttributeDomain domain = (AttributeDomain)sspreadsheet->attribute_domain;
const GeometryComponentType component_type = get_display_component_type(C, object_eval);
/* Create a resource collector
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list