Blender V5.3
blender::nodes::inverse_eval::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]

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

◆ 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.

Member Function Documentation

◆ allocate()

Definition at line 476 of file node_socket_value.cc.

◆ allocate_single()

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

◆ construct_in()

template<typename T>
SocketValueVariant & blender::bke::SocketValueVariant::construct_in ( void * ptr,
T && value )
inlinestatic

Construct a SocketValueVariant at the given pointer from the given value.

Definition at line 213 of file BKE_node_socket_value.hh.

◆ copy_as()

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

Equivalent to calling extract<T>() on a copy of this value.

Definition at line 287 of file BKE_node_socket_value.hh.

◆ count_memory()

Definition at line 591 of file node_socket_value.cc.

◆ emplace()

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

Replace the stored value by constructing the given type in the storage.

Definition at line 227 of file BKE_node_socket_value.hh.

◆ ensure_owns_direct_data()

Also see GeomtrySet::ensure_owns_direct_data.

Definition at line 547 of file node_socket_value.cc.

◆ 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.

◆ ensure_type() [2/2]

Definition at line 279 of file BKE_node_socket_value.hh.

◆ 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.

◆ from()

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

Create a new SocketValueVariant from the given value.

Definition at line 220 of file BKE_node_socket_value.hh.

◆ get() [1/2]

◆ get() [2/2]

Get the stored value as a GPointer.

Definition at line 340 of file BKE_node_socket_value.hh.

◆ 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.

◆ get_if() [2/4]

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

Return a pointer to the stored value if it is of the given type. Otherwise return null.

Definition at line 293 of file BKE_node_socket_value.hh.

◆ 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

Definition at line 320 of file BKE_node_socket_value.hh.

◆ init_default() [1/2]

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

Definition at line 431 of file node_socket_value.cc.

◆ init_default() [2/2]

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

Definition at line 373 of file node_socket_value.cc.

◆ is_context_dependent_field()

If true, the stored value cannot be converted to a single value without loss of information.

Definition at line 538 of file node_socket_value.cc.

◆ is_field()

If true, the value is stored as a GField.

Definition at line 520 of file node_socket_value.cc.

◆ is_list()

The stored value is a list.

Definition at line 525 of file node_socket_value.cc.

◆ is_single()

The stored value is a single value.

Definition at line 505 of file node_socket_value.cc.

◆ is_volume_grid()

The stored value is a volume grid.

Definition at line 529 of file node_socket_value.cc.

◆ owns_direct_data()

◆ try_convert() [1/2]

Try to convert the stored value to the given type, returning null if the implicit conversion does not exist.

Definition at line 235 of file BKE_node_socket_value.hh.

◆ try_convert() [2/2]

Definition at line 256 of file BKE_node_socket_value.hh.


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