Blender V5.3
blender::bke::SocketValueVariant Class Reference

#include <BKE_node_socket_value.hh>

Public Member Functions

 SocketValueVariant ()=default
template<typename T>
requires (std::is_trivial_v<std::decay_t<T>> || is_same_any_v<std::decay_t<T>, std::string>)
 SocketValueVariant (T &&value)
template<typename T, typename... Args>
T & emplace (Args &&...args)
template<typename T>
T * try_convert ()
void * try_convert (const CPPType &type)
template<typename T>
T & ensure_type ()
void * ensure_type (const CPPType &type)
template<typename T>
T copy_as () const
template<typename T>
T extract ()
template<typename T>
const T * get_if () const
template<typename T>
T * get_if ()
const void * get_if (const CPPType &type) const
void * get_if (const CPPType &type)
GPointer get () const
GMutablePointer get ()
bool is_context_dependent_field () const
bool is_field () const
bool is_volume_grid () const
bool is_single () const
bool is_list () const
void ensure_owns_direct_data ()
bool owns_direct_data () const
void * allocate_single (const CPPType &type)
void count_memory (MemoryCounter &memory) const

Static Public Member Functions

template<typename T>
static SocketValueVariant & construct_in (void *ptr, T &&value)
template<typename T>
static SocketValueVariant from (T &&value)
template<typename T>
static T & init_default (detail::SocketValueVariantAny &value)
static void * init_default (const CPPType &type, detail::SocketValueVariantAny &value)
static void * allocate (const CPPType &type, detail::SocketValueVariantAny &value)

Detailed Description

SocketValueVariant is used to pass data between nodes, e.g. by geometry nodes in the lazy function evaluator. 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.

This container is also able to do implicit conversions between the different types, with the ensure_type() methods.

Definition at line 83 of file BKE_node_socket_value.hh.

Constructor & Destructor Documentation

◆ SocketValueVariant() [1/2]

◆ SocketValueVariant() [2/2]

template<typename T>
requires (std::is_trivial_v<std::decay_t<T>> || is_same_any_v<std::decay_t<T>, std::string>)
blender::bke::SocketValueVariant::SocketValueVariant ( T && value)
inlineexplicit

Create a variant based on the given value. This works for primitive types. For more complex types, one can use the from or construct_in utilities.

Definition at line 206 of file BKE_node_socket_value.hh.

References emplace(), blender::is_same_any_v, and T.

Member Function Documentation

◆ allocate()

◆ allocate_single()

void * blender::bke::SocketValueVariant::allocate_single ( const CPPType & type)

◆ construct_in()

◆ copy_as()

◆ count_memory()

void blender::bke::SocketValueVariant::count_memory ( MemoryCounter & memory) const

◆ emplace()

template<typename T, typename... Args>
T & blender::bke::SocketValueVariant::emplace ( Args &&... args)
inline

◆ ensure_owns_direct_data()

◆ ensure_type() [1/2]

template<typename T>
T & blender::bke::SocketValueVariant::ensure_type ( )
inline

Try to convert the stored value to the given type, creating the type's default value if the conversion does not exist.

Definition at line 271 of file BKE_node_socket_value.hh.

References get_if(), T, and try_convert().

Referenced by blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_field(), 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::LazyFunctionMenuSwitchBooleanOutputs::execute_impl(), blender::nodes::node_geo_switch_cc::LazyFunctionForSwitchNode::execute_impl(), blender::nodes::execute_multi_function_on_value_variant__single(), extract(), blender::nodes::GeoNodeExecParams::extract_input(), blender::nodes::find_output_attributes_to_store(), blender::nodes::GeoNodeExecParams::get_input(), blender::nodes::inverse_eval::InverseEvalParams::get_input(), blender::nodes::inverse_eval::InverseEvalParams::get_output(), blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_main_items_and_geometry(), blender::nodes::LazyFunctionForRepeatZone::initialize_execution_graph(), blender::geometry::mix_socket_values(), blender::nodes::node_geo_set_grid_background::node_geo_exec(), SocketValueVariant(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), 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().

◆ ensure_type() [2/2]

void * blender::bke::SocketValueVariant::ensure_type ( const CPPType & type)
inline

Definition at line 279 of file BKE_node_socket_value.hh.

References try_convert().

◆ extract()

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

Get the stored value as a specific type. For convenience this allows accessing the stored type as a different type, using implicit conversions as possible.

This method may leave the variant empty, in a moved from state or unchanged. Therefore, this should only be called once.

Definition at line 368 of file BKE_node_socket_value.hh.

References ensure_type(), and T.

Referenced by blender::bke::socket_value_visitor::RecursiveVisitor::edit_SocketValueVariant(), blender::nodes::node_geo_warning_cc::LazyFunctionForWarningNode::execute_impl(), blender::nodes::node_geo_sort_list_cc::get_varray_or_evaluate(), blender::nodes::eval_log::NodeTreeLogger::log_value(), blender::geometry::mix_socket_values_same_type(), blender::nodes::node_geo_tag_filter_cc::node_geo_exec(), and SocketValueVariant().

◆ from()

◆ get() [1/2]

GMutablePointer blender::bke::SocketValueVariant::get ( )
inline

◆ get() [2/2]

GPointer blender::bke::SocketValueVariant::get ( ) const
inline

Get the stored value as a GPointer.

Definition at line 340 of file BKE_node_socket_value.hh.

References blender::CPPType::get(), and blender::bke::detail::SocketValueVariantTypeInfo::type.

Referenced by blender::nodes::BundleItemValue::as(), blender::nodes::BundleItemValue::as_pointer(), blender::ed::spreadsheet::GeometryDataSetTreeView::build_socket_value(), blender::ed::spreadsheet::ViewerDataTreeView::build_value(), blender::bke::socket_value_visitor::RecursiveVisitor::check_SocketValueVariant(), count_memory(), blender::ed::spreadsheet::data_source_from_geometry(), blender::ed::spreadsheet::data_source_from_socket_value(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::draw_content_cell_value(), blender::nodes::node_geo_viewer_cc::draw_from_viewer_log_value(), blender::bke::socket_value_visitor::RecursiveVisitor::edit_SocketValueVariant(), ensure_owns_direct_data(), blender::nodes::execute_multi_function_on_value_variant__list(), blender::nodes::get_geometry_nodes_input_inference_values(), is_field(), is_list(), is_single(), is_volume_grid(), blender::nodes::eval_log::NodeTreeLogger::log_value(), blender::nodes::node_geo_viewer_cc::log_viewer_attribute(), blender::geometry::mix_socket_values(), blender::geometry::mix_socket_values_same_type(), owns_direct_data(), blender::ed::spreadsheet::root_display_data_get(), blender::ed::spreadsheet::root_geometry_set_get(), blender::bke::bake::serialize_socket_value_variant(), blender::nodes::socket_type_for_value_variant(), SocketValueVariant(), and blender::bke::bake::value_variant_valid_for_socket().

◆ get_if() [1/4]

template<typename T>
T * blender::bke::SocketValueVariant::get_if ( )
inline

Definition at line 315 of file BKE_node_socket_value.hh.

References T.

◆ get_if() [2/4]

◆ get_if() [3/4]

void * blender::bke::SocketValueVariant::get_if ( const CPPType & type)
inline

Definition at line 335 of file BKE_node_socket_value.hh.

◆ get_if() [4/4]

const void * blender::bke::SocketValueVariant::get_if ( const CPPType & type) const
inline

◆ init_default() [1/2]

SOCKET_VALUE_FIELD_AND_LIST_TYPES void * blender::bke::SocketValueVariant::init_default ( const CPPType & type,
detail::SocketValueVariantAny & value )
static

◆ init_default() [2/2]

template<typename T>
T & blender::bke::SocketValueVariant::init_default ( detail::SocketValueVariantAny & value)
inlinestatic

◆ is_context_dependent_field()

◆ is_field()

◆ is_list()

◆ is_single()

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

The stored value is a single value.

Definition at line 505 of file node_socket_value.cc.

References get(), SOCKET_VALUE_SINGLE_TYPES, and blender::GPointer::type().

Referenced by blender::ed::spreadsheet::GeometryDataSetTreeView::build_socket_value(), blender::ed::spreadsheet::ViewerDataTreeView::build_value(), blender::bke::socket_value_visitor::RecursiveVisitor::check_SocketValueVariant(), blender::ed::spreadsheet::data_source_from_geometry(), blender::ed::spreadsheet::data_source_from_socket_value(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::draw_content_cell_value(), blender::nodes::node_geo_viewer_cc::draw_from_viewer_log_value(), blender::bke::socket_value_visitor::RecursiveVisitor::edit_SocketValueVariant(), blender::nodes::LazyFunctionForEnableOutputSocketUsage::execute_impl(), blender::nodes::node_geo_enable_output_cc::LazyFunctionForEnableOutputNode::execute_impl(), blender::nodes::node_geo_menu_switch_cc::LazyFunctionMenuSwitchBooleanOutputs::execute_impl(), blender::nodes::execute_multi_function_on_value_variant__list(), blender::nodes::execute_multi_function_on_value_variant__list_individual(), blender::nodes::get_geometry_nodes_input_inference_values(), blender::nodes::node_geo_viewer_cc::log_viewer_attribute(), blender::geometry::mix_socket_values_same_type(), blender::ed::spreadsheet::root_display_data_get(), blender::ed::spreadsheet::root_geometry_set_get(), blender::bke::bake::serialize_socket_value_variant(), SocketValueVariant(), and blender::bke::bake::value_variant_valid_for_socket().

◆ is_volume_grid()

◆ owns_direct_data()

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

◆ try_convert() [1/2]

template<typename T>
T * blender::bke::SocketValueVariant::try_convert ( )

◆ try_convert() [2/2]

void * blender::bke::SocketValueVariant::try_convert ( const CPPType & type)
inline

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