Blender V5.0
SocketValueVariant Class Reference

#include <BKE_node_socket_value.hh>

Public Member Functions

 SocketValueVariant ()=default
 SocketValueVariant (const SocketValueVariant &other)=default
 SocketValueVariant (SocketValueVariant &&other)=default
template<typename T, BLI_ENABLE_IF((std::is_trivial_v< std::decay_t< T > >|| is_same_any_v< std::decay_t< T >, std::string >))>
 SocketValueVariant (T &&value)
SocketValueVariantoperator= (const SocketValueVariant &other)=default
SocketValueVariantoperator= (SocketValueVariant &&other)=default
 ~SocketValueVariant ()=default
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
bool is_list () 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)

Static Public Member Functions

template<typename T>
static SocketValueVariantConstructIn (void *ptr, T &&value)
template<typename T>
static SocketValueVariant From (T &&value)

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

Constructor & Destructor Documentation

◆ SocketValueVariant() [1/4]

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

◆ SocketValueVariant() [2/4]

◆ SocketValueVariant() [3/4]

◆ SocketValueVariant() [4/4]

template<typename T, BLI_ENABLE_IF((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 use set explicitly. Alternatively, one can use the From or ConstructIn utilities.

Definition at line 102 of file BKE_node_socket_value.hh.

◆ ~SocketValueVariant()

Member Function Documentation

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

◆ ConstructIn()

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

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

Definition at line 205 of file BKE_node_socket_value.hh.

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

◆ extract()

Get the stored value as a specific type. For convenience this allows accessing the stored type as a different type. For example, a stored single int can also be accessed as GField or Field<int> (but not float or Field<float>).

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

Definition at line 147 of file node_socket_value.cc.

◆ From()

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

◆ get_single_ptr() [1/2]

◆ get_single_ptr() [2/2]

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

◆ get_single_ptr_raw()

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

◆ is_context_dependent_field()

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

Definition at line 359 of file node_socket_value.cc.

◆ is_list()

The stored value is a list.

Definition at line 381 of file node_socket_value.cc.

◆ is_single()

The stored value is a single value.

Definition at line 376 of file node_socket_value.cc.

◆ is_volume_grid()

The stored value is a volume grid.

Definition at line 371 of file node_socket_value.cc.

◆ operator=() [1/2]

SocketValueVariant & blender::bke::SocketValueVariant::operator= ( const SocketValueVariant & other)
default

◆ operator=() [2/2]

SocketValueVariant & blender::bke::SocketValueVariant::operator= ( SocketValueVariant && other)
default

◆ set()

template<typename T>
void blender::bke::SocketValueVariant::set ( T && value)
inline

Replaces the stored value with a new value of potentially a different type.

Definition at line 219 of file BKE_node_socket_value.hh.

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

◆ valid_for_socket()

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

◆ operator<<

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

Definition at line 475 of file node_socket_value.cc.


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