Blender V4.3
BKE_node_socket_value.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "DNA_node_types.h"
12
13#include "BLI_any.hh"
14#include "BLI_cpp_type.hh"
16
17namespace blender::bke {
18
34 private:
43 enum class Kind {
47 None,
51 Single,
55 Field,
59 Grid,
60 };
61
65 Kind kind_ = Kind::None;
70 eNodeSocketDatatype socket_type_;
78 Any<void, 24> value_;
79
80 public:
84 SocketValueVariant() = default;
85
90 template<typename T> explicit SocketValueVariant(T &&value);
91
96 bool valid_for_socket(eNodeSocketDatatype socket_type) const;
97
106 template<typename T> T extract();
107
112 template<typename T> T get() const;
113
117 template<typename T> void set(T &&value);
118
122 bool is_context_dependent_field() const;
123
127 bool is_volume_grid() const;
128
136 void convert_to_single();
137
142 GPointer get_single_ptr() const;
144
150 const void *get_single_ptr_raw() const;
151
155 void store_single(eNodeSocketDatatype socket_type, const void *value);
156
161 void *allocate_single(eNodeSocketDatatype socket_type);
162
163 friend std::ostream &operator<<(std::ostream &stream, const SocketValueVariant &value_variant);
164
165 private:
170 template<typename T> void store_impl(T value);
171};
172
173template<typename T> inline SocketValueVariant::SocketValueVariant(T &&value)
174{
175 this->set(std::forward<T>(value));
176}
177
178template<typename T> inline void SocketValueVariant::set(T &&value)
179{
180 this->store_impl<std::decay_t<T>>(std::forward<T>(value));
181}
182
184{
185 BLI_assert(kind_ == Kind::Single);
186 return value_.get();
187}
188
189} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:50
eNodeSocketDatatype
void * get()
Definition BLI_any.hh:324
bool valid_for_socket(eNodeSocketDatatype socket_type) const
friend std::ostream & operator<<(std::ostream &stream, const SocketValueVariant &value_variant)
void store_single(eNodeSocketDatatype socket_type, const void *value)
void * allocate_single(eNodeSocketDatatype socket_type)