|
Blender V5.0
|
#include <BLI_resource_scope.hh>
Inherits blender::NonCopyable, and blender::NonMovable.
Public Member Functions | |
| ResourceScope () | |
| ~ResourceScope () | |
#ResourceScope Inline Methods | |
| template<typename T> | |
| T * | add (std::unique_ptr< T > resource) |
| template<typename T> | |
| T * | add (destruct_ptr< T > resource) |
| void | add (void *userdata, void(*free)(void *)) |
| template<typename T> | |
| T & | add_value (T &&value) |
| template<typename Func> | |
| void | add_destruct_call (Func func) |
| template<typename T, typename... Args> | |
| T & | construct (Args &&...args) |
| void * | allocate_owned (const CPPType &type) |
| LinearAllocator & | allocator () |
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.
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.
Definition at line 37 of file BLI_resource_scope.hh.
| blender::ResourceScope::~ResourceScope | ( | ) |
Definition at line 15 of file resource_scope.cc.
|
inline |
Pass ownership of the resource to the ResourceScope. It will be destructed when the ResourceScope is destructed.
Definition at line 115 of file BLI_resource_scope.hh.
Pass ownership of the resource to the ResourceScope. It will be destructed and freed when the ResourceScope is destructed.
Definition at line 102 of file BLI_resource_scope.hh.
References add(), data, ptr, resource, and T.
Referenced by add(), add(), add_destruct_call(), construct(), and blender::ed::spreadsheet::spreadsheet_main_region_draw().
|
inline |
Pass ownership of some resource to the ResourceScope. The given free function will be called when the ResourceScope is destructed.
Definition at line 133 of file BLI_resource_scope.hh.
|
inline |
The passed in function will be called when the scope is destructed.
Definition at line 146 of file BLI_resource_scope.hh.
Referenced by allocate_owned(), blender::bke::defer_free_node_type(), blender::bke::defer_free_socket_type(), blender::bke::defer_free_tree_type(), and blender::fn::evaluate_fields().
Construct an object with the same value in the ResourceScope and return a reference to the new value.
Definition at line 141 of file BLI_resource_scope.hh.
References construct(), and T.
Referenced by blender::ed::space_node::node_find_update_fn().
|
inline |
Allocate a buffer for the given type. The caller is responsible for initializing it before the ResourceScope is destructed. The value in the returned buffer is destructed automatically.
Definition at line 161 of file BLI_resource_scope.hh.
References add_destruct_call(), blender::CPPType::destruct(), and blender::CPPType::is_trivially_destructible.
Referenced by blender::fn::evaluate_fields(), and blender::nodes::socket_usage_inference::infer_group_interface_inputs_usage().
|
inline |
Returns a reference to a linear allocator that is owned by the ResourceScope. Memory allocated through this allocator will be freed when the collector is destructed.
Definition at line 170 of file BLI_resource_scope.hh.
Referenced by blender::nodes::evaluate_closure_eagerly(), blender::fn::evaluate_fields(), blender::nodes::execute_geometry_nodes_on_geometry(), blender::nodes::socket_usage_inference::infer_group_interface_inputs_usage(), blender::nodes::LazyFunctionForEvaluateClosureNode::initialize_execution_graph(), blender::nodes::LazyFunctionForEvaluateClosureNode::initialize_pass_through_graph(), menu_items_from_all_operators(), menu_items_from_ui_create(), and menu_items_from_ui_create_item_from_button().
|
inline |
Utility method to construct an instance of type T that will be owned by the ResourceScope.
Definition at line 153 of file BLI_resource_scope.hh.
Referenced by add_value(), blender::bke::attribute_storage_blend_write_prepare(), blender::nodes::build_closure_zone_lazy_function(), blender::nodes::build_evaluate_closure_node_lazy_function(), blender::nodes::build_foreach_geometry_element_zone_lazy_function(), blender::nodes::build_implicit_conversion_lazy_function(), blender::fn::build_multi_function_procedure_for_fields(), blender::nodes::build_repeat_zone_lazy_function(), CustomData_blend_write_prepare(), blender::nodes::evaluate_closure_eagerly(), blender::nodes::execute_geometry_nodes_on_geometry(), blender::nodes::LazyFunctionForJoinReferenceSets::get_cached(), blender::bke::node_field_inferencing::get_dummy_field_inferencing_interface(), blender::nodes::get_geometry_nodes_input_inference_values(), blender::bke::node_field_inferencing::get_node_field_inferencing_interface(), blender::fn::index_mask_from_selection(), menu_items_from_all_operators(), menu_items_from_ui_create(), menu_items_from_ui_create_item_from_button(), blender::ed::space_node::node_find_update_fn(), blender::bke::node_tree_reference_lifetimes::prepare_relations_by_node(), blender::ed::spreadsheet::spreadsheet_filter_rows(), and write_drawing_array().