Blender V4.3
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
 
void convert_to_single ()
 
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 33 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.

◆ 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 173 of file BKE_node_socket_value.hh.

References set().

Member Function Documentation

◆ allocate_single()

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

◆ convert_to_single()

void blender::bke::SocketValueVariant::convert_to_single ( )

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.

Definition at line 279 of file node_socket_value.cc.

References allocate_single(), BLI_assert_unreachable, blender::CPPType::default_value(), blender::fn::evaluate_constant_field(), blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), blender::bke::socket_type_to_geo_nodes_base_cpp_type(), and store_single().

Referenced by blender::nodes::execute_multi_function_on_value_variant__single(), blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_main_items_and_geometry(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), and blender::nodes::mix_baked_data_item().

◆ 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 171 of file node_socket_value.cc.

References extract().

Referenced by blender::nodes::LazyFunctionForAnonymousAttributeSetExtract::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::geo_eval_log::GeoTreeLogger::log_value(), 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 317 of file node_socket_value.cc.

References get_single_ptr(), ptr, and PointerRNA::type.

◆ get_single_ptr() [2/2]

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

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 308 of file node_socket_value.cc.

References BLI_assert, blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get(), and blender::bke::socket_type_to_geo_nodes_base_cpp_type().

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

◆ 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 183 of file BKE_node_socket_value.hh.

References BLI_assert, and blender::Any< ExtraInfo, InlineBufferCapacity, Alignment >::get().

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_volume_grid()

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

The stored value is a volume grid.

Definition at line 274 of file node_socket_value.cc.

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

◆ set()

◆ store_single()

void blender::bke::SocketValueVariant::store_single ( eNodeSocketDatatype socket_type,
const void * 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 371 of file node_socket_value.cc.

Friends And Related Symbol Documentation

◆ operator<<

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

Definition at line 353 of file node_socket_value.cc.


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