Blender  V3.3
NOD_multi_function.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
5 #include "FN_multi_function.hh"
6 
7 #include "DNA_node_types.h"
8 
10 
11 namespace blender::nodes {
12 
13 using namespace fn::multi_function_types;
14 
15 class NodeMultiFunctions;
16 
21  private:
22  bNode &node_;
23  bNodeTree &tree_;
24  std::shared_ptr<MultiFunction> owned_built_fn_;
25  const MultiFunction *built_fn_ = nullptr;
26 
27  friend NodeMultiFunctions;
28 
29  public:
31 
36  void set_matching_fn(const MultiFunction *fn);
37  void set_matching_fn(const MultiFunction &fn);
38 
43  template<typename T, typename... Args> void construct_and_set_matching_fn(Args &&...args);
44 
45  bNode &node();
46  bNodeTree &tree();
47 };
48 
53  public:
54  struct Item {
55  const MultiFunction *fn = nullptr;
56  std::shared_ptr<MultiFunction> owned_fn;
57  };
58 
59  private:
61 
62  public:
64 
65  const Item &try_get(const DNode &node) const;
66 };
67 
68 /* -------------------------------------------------------------------- */
73  : node_(node), tree_(tree)
74 {
75 }
76 
78 {
79  return node_;
80 }
81 
83 {
84  return tree_;
85 }
86 
87 inline void NodeMultiFunctionBuilder::set_matching_fn(const MultiFunction *fn)
88 {
89  built_fn_ = fn;
90 }
91 
92 inline void NodeMultiFunctionBuilder::set_matching_fn(const MultiFunction &fn)
93 {
94  built_fn_ = &fn;
95 }
96 
97 template<typename T, typename... Args>
99 {
100  owned_built_fn_ = std::make_shared<T>(std::forward<Args>(args)...);
101  built_fn_ = &*owned_built_fn_;
102 }
103 
106 /* -------------------------------------------------------------------- */
111 {
112  static Item empty_item;
113  const Item *item = map_.lookup_ptr(node->bnode());
114  if (item == nullptr) {
115  return empty_item;
116  }
117  return *item;
118 }
119 
122 } // namespace blender::nodes
void set_matching_fn(const MultiFunction *fn)
NodeMultiFunctionBuilder(bNode &node, bNodeTree &tree)
const Item & try_get(const DNode &node) const
OperationNode * node
void * tree
#define T
std::shared_ptr< MultiFunction > owned_fn