Blender V4.5
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
8
9#pragma once
10
11#include "DNA_node_types.h"
12
13#include "BLI_any.hh"
15
16namespace blender::bke {
17
33 private:
42 enum class Kind {
46 None,
50 Single,
54 Field,
58 Grid,
59 };
60
64 Kind kind_ = Kind::None;
69 eNodeSocketDatatype socket_type_;
77 Any<void, 24> value_;
78
79 public:
83 SocketValueVariant() = default;
84
89 template<typename T> explicit SocketValueVariant(T &&value);
90
95 bool valid_for_socket(eNodeSocketDatatype socket_type) const;
96
105 template<typename T> T extract();
106
111 template<typename T> T get() const;
112
116 template<typename T> void set(T &&value);
117
121 bool is_context_dependent_field() const;
122
126 bool is_volume_grid() const;
127
131 bool is_single() const;
132
140 void convert_to_single();
141
146 GPointer get_single_ptr() const;
148
154 const void *get_single_ptr_raw() const;
155
159 void store_single(eNodeSocketDatatype socket_type, const void *value);
160
165 void *allocate_single(eNodeSocketDatatype socket_type);
166
167 friend std::ostream &operator<<(std::ostream &stream, const SocketValueVariant &value_variant);
168
169 private:
174 template<typename T> void store_impl(T value);
175};
176
177template<typename T> inline SocketValueVariant::SocketValueVariant(T &&value)
178{
179 this->set(std::forward<T>(value));
180}
181
182template<typename T> inline void SocketValueVariant::set(T &&value)
183{
184 this->store_impl<std::decay_t<T>>(std::forward<T>(value));
185}
186
188{
189 BLI_assert(kind_ == Kind::Single);
190 return value_.get();
191}
192
193} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:46
eNodeSocketDatatype
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)
#define T