Blender V4.5
blender::bke::SocketValueVariant Class Reference

#include <BKE_node_socket_value.hh>

Public Member Functions

 SocketValueVariant ()=default
template<typename T>
 SocketValueVariant (T &&value)
bool valid_for_socket (eNodeSocketDatatype socket_type) const
template<typename T>
T extract ()
template<typename T>
T get () const
template<typename T>
void set (T &&value)
bool is_context_dependent_field () const
bool is_volume_grid () const
bool is_single () const
GPointer get_single_ptr () const
GMutablePointer get_single_ptr ()
const void * get_single_ptr_raw () const
void store_single (eNodeSocketDatatype socket_type, const void *value)
void * allocate_single (eNodeSocketDatatype socket_type)

Friends

std::ostream & operator<< (std::ostream &stream, const SocketValueVariant &value_variant)

Detailed Description

SocketValueVariant is used by geometry nodes in the lazy-function evaluator to pass data between nodes. Specifically, it is the container type for the following socket types: bool, float, integer, vector, rotation, color and string.

The data passed through e.g. an integer socket can be a single value, a field or a grid (and in the lists and images). Each of those is stored differently, but this container can store them all.

A key requirement for this container is that it is type-erased, i.e. not all code that uses it has to include all the headers required to process the other storage types. This is achieved by using the Any type and by providing templated accessors that are implemented outside of a header.

Definition at line 32 of file BKE_node_socket_value.hh.

Constructor & Destructor Documentation

◆ SocketValueVariant() [1/2]

blender::bke::SocketValueVariant::SocketValueVariant ( )
default

Create an empty variant. This is not valid for any socket type yet.

References SocketValueVariant(), and T.

Referenced by get(), get_single_ptr(), operator<<, and SocketValueVariant().

◆ SocketValueVariant() [2/2]

template<typename T>
blender::bke::SocketValueVariant::SocketValueVariant ( T && value)
inlineexplicit

Create a variant based on the given value. This works for primitive types, #GField and #Field<T>.

Definition at line 177 of file BKE_node_socket_value.hh.

References set(), and T.

Member Function Documentation

◆ allocate_single()

void * blender::bke::SocketValueVariant::allocate_single ( eNodeSocketDatatype socket_type)

Replaces the stored value with a new uninitialized single value for the given socket type. The caller is responsible to construct the value in the returned memory before it is used.

Definition at line 347 of file node_socket_value.cc.

References BLI_assert_unreachable, SOCK_BOOLEAN, SOCK_BUNDLE, SOCK_CLOSURE, SOCK_FLOAT, SOCK_INT, SOCK_MATRIX, SOCK_MENU, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, and SOCK_VECTOR.

Referenced by blender::nodes::inverse_eval::convert_single_socket_value(), blender::nodes::execute_multi_function_on_value_variant__single(), and blender::nodes::LazyFunctionForForeachGeometryElementZone::prepare_components().

◆ extract()

template<typename T>
T blender::bke::SocketValueVariant::extract ( )

◆ get()

template<typename T>
T blender::bke::SocketValueVariant::get ( ) const

Same as extract, but always leaves the variant unchanged. So this method can be called multiple times.

Definition at line 182 of file node_socket_value.cc.

References extract(), SocketValueVariant(), and T.

Referenced by blender::nodes::LazyFunctionForExtractingReferenceSet::execute_impl(), blender::nodes::LazyFunctionForIndexSwitchSocketUsage::execute_impl(), blender::nodes::LazyFunctionForSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_index_switch_cc::LazyFunctionForIndexSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionForMenuSwitchSocketUsage::execute_impl(), blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_impl(), blender::nodes::node_geo_warning_cc::LazyFunctionForWarningNode::execute_impl(), blender::nodes::find_output_attributes_to_store(), blender::nodes::LazyFunctionForRepeatZone::initialize_execution_graph(), blender::nodes::inverse_eval::set_modifier_value(), blender::nodes::inverse_eval::set_socket_value(), blender::nodes::inverse_eval::set_value_node_value(), blender::nodes::node_geo_simulation_cc::sim_output_node::LazyFunctionForSimulationOutputNode::store_new_state(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_rotate_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_scale_transform_and_target_property(), blender::ed::view3d::geometry_nodes_gizmos::DialGizmo::update_target_property(), blender::ed::view3d::geometry_nodes_gizmos::LinearGizmo::update_target_property(), and blender::ed::view3d::geometry_nodes_gizmos::TransformGizmos::update_translate_transform_and_target_property().

◆ get_single_ptr() [1/2]

GMutablePointer blender::bke::SocketValueVariant::get_single_ptr ( )

Definition at line 341 of file node_socket_value.cc.

References get_single_ptr(), ptr, and SocketValueVariant().

◆ get_single_ptr() [2/2]

GPointer blender::bke::SocketValueVariant::get_single_ptr ( ) const

Convert the stored value into a single value. For simple value access, this is not necessary, because get` does the conversion implicitly. However, it is necessary if one wants to use get_single_ptr. Context-dependent fields or grids will just result in a fallback value.

The caller has to make sure that the stored value is a single value, field or grid. */ void convert_to_single();

/** Get a pointer to the embedded single value. The caller has to make sure that there actually is a single value stored, e.g. by calling #convert_to_single.

Definition at line 332 of file node_socket_value.cc.

References BLI_assert, data, and blender::bke::socket_type_to_geo_nodes_base_cpp_type().

Referenced by extract(), blender::nodes::get_geometry_nodes_input_base_values(), get_single_ptr(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::nodes::mix_baked_data_item(), and operator<<.

◆ get_single_ptr_raw()

const void * blender::bke::SocketValueVariant::get_single_ptr_raw ( ) const
inline

Similar to get_single_ptr, but returns an untyped pointer. This can only be used if the caller knows for sure which type is contained. In that case, it can be a bit faster though, because the corresponding CPPType does not have to be looked up based on the socket type.

Definition at line 187 of file BKE_node_socket_value.hh.

References BLI_assert.

Referenced by blender::nodes::inverse_eval::convert_single_socket_value(), blender::nodes::execute_multi_function_on_value_variant__single(), and blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_main_items_and_geometry().

◆ is_context_dependent_field()

◆ is_single()

bool blender::bke::SocketValueVariant::is_single ( ) const

The stored value is a single value.

Definition at line 298 of file node_socket_value.cc.

Referenced by blender::nodes::get_geometry_nodes_input_base_values().

◆ is_volume_grid()

bool blender::bke::SocketValueVariant::is_volume_grid ( ) const

◆ set()

◆ store_single()

void blender::bke::SocketValueVariant::store_single ( eNodeSocketDatatype socket_type,
const void * value )

Replace the stored value with the given single value.

Definition at line 229 of file node_socket_value.cc.

References BLI_assert_unreachable, SOCK_BOOLEAN, SOCK_BUNDLE, SOCK_CLOSURE, SOCK_FLOAT, SOCK_INT, SOCK_MATRIX, SOCK_RGBA, SOCK_ROTATION, SOCK_STRING, and SOCK_VECTOR.

Referenced by blender::bke::bake::copy_bake_item_to_socket_value().

◆ valid_for_socket()

bool blender::bke::SocketValueVariant::valid_for_socket ( eNodeSocketDatatype socket_type) const
Returns
True if the stored value is valid for a specific socket type. This is mainly meant to be used by asserts.

Definition at line 399 of file node_socket_value.cc.

Referenced by blender::nodes::geo_eval_log::GeoTreeLogger::log_value().

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const SocketValueVariant & value_variant )
friend

The documentation for this class was generated from the following files: