Blender V4.3
NOD_multi_function.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
5#pragma once
6
8
9#include "DNA_node_types.h"
10
11namespace blender::nodes {
12
13class NodeMultiFunctions;
14
19 private:
20 const bNode &node_;
21 const bNodeTree &tree_;
22 std::shared_ptr<mf::MultiFunction> owned_built_fn_;
23 const mf::MultiFunction *built_fn_ = nullptr;
24
25 friend NodeMultiFunctions;
26
27 public:
28 NodeMultiFunctionBuilder(const bNode &node, const bNodeTree &tree);
29
34 void set_matching_fn(const mf::MultiFunction *fn);
35 void set_matching_fn(const mf::MultiFunction &fn);
36
41 template<typename T, typename... Args> void construct_and_set_matching_fn(Args &&...args);
42
43 const bNode &node();
44 const bNodeTree &tree();
45};
46
51 public:
52 struct Item {
53 const mf::MultiFunction *fn = nullptr;
54 std::shared_ptr<mf::MultiFunction> owned_fn;
55 };
56
57 private:
59
60 public:
62
63 const Item &try_get(const bNode &node) const;
64};
65
66/* -------------------------------------------------------------------- */
71 : node_(node), tree_(tree)
72{
73}
74
76{
77 return node_;
78}
79
81{
82 return tree_;
83}
84
86{
87 built_fn_ = fn;
88}
89
91{
92 built_fn_ = &fn;
93}
94
95template<typename T, typename... Args>
97{
98 owned_built_fn_ = std::make_shared<T>(std::forward<Args>(args)...);
99 built_fn_ = &*owned_built_fn_;
100}
101
104/* -------------------------------------------------------------------- */
109{
110 static Item empty_item;
111 const Item *item = map_.lookup_ptr(&node);
112 if (item == nullptr) {
113 return empty_item;
114 }
115 return *item;
116}
117
120} // namespace blender::nodes
void set_matching_fn(const mf::MultiFunction *fn)
NodeMultiFunctionBuilder(const bNode &node, const bNodeTree &tree)
const Item & try_get(const bNode &node) const
KDTree_3d * tree
#define T
std::shared_ptr< mf::MultiFunction > owned_fn