2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #include "NOD_node_tree_multi_function.hh"
18 #include "NOD_type_callbacks.hh"
20 namespace blender::nodes {
22 const CPPType *socket_cpp_type_get(const bNodeSocketType &stype)
24 if (stype.get_cpp_type != nullptr) {
25 return stype.get_cpp_type();
30 std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype)
32 const CPPType *cpp_type = socket_cpp_type_get(stype);
33 if (cpp_type != nullptr) {
34 return MFDataType::ForSingle(*cpp_type);
39 bool socket_is_mf_data_socket(const bNodeSocketType &stype)
41 if (!socket_mf_type_get(stype).has_value()) {
44 if (stype.expand_in_mf_network == nullptr && stype.get_cpp_value == nullptr) {
50 bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value)
52 if (socket.typeinfo->get_cpp_value != nullptr) {
53 socket.typeinfo->get_cpp_value(socket, r_value);
59 void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder)
61 bNodeSocket &socket = builder.bsocket();
62 if (socket.typeinfo->expand_in_mf_network != nullptr) {
63 socket.typeinfo->expand_in_mf_network(builder);
65 else if (socket.typeinfo->get_cpp_value != nullptr) {
66 const CPPType &type = *socket_cpp_type_get(*socket.typeinfo);
67 void *buffer = builder.resources().linear_allocator().allocate(type.size(), type.alignment());
68 socket.typeinfo->get_cpp_value(socket, buffer);
69 builder.set_constant_value(type, buffer);
76 } // namespace blender::nodes