HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
leafNode.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_EF_LEAF_NODE_H
8 #define PXR_EXEC_EF_LEAF_NODE_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
15 
17 #include "pxr/exec/vdf/node.h"
19 
21 
22 #define EF_LEAF_TOKENS \
23  (in)
24 
26 
27 ///////////////////////////////////////////////////////////////////////////////
28 ///
29 /// \class EfLeafNode
30 ///
31 /// \brief A terminal node, which is never executed.
32 ///
33 /// Leaf nodes are used for creating terminal nodes that are visited during
34 /// invalidation. Invalidation callbacks on these leaf nodes causes
35 /// downstream invalidation notification to be sent.
36 ///
37 class EF_API_TYPE EfLeafNode final : public VdfNode
38 {
39 public:
40  /// Returns \c true if the given node is an EfLeafNode. This method is
41  /// an accelerated alternative to IsA<EfLeafNode>() or dynamic_cast.
42  ///
43  static bool IsALeafNode(const VdfNode &node) {
44  return node.GetNumOutputs() == 0 && node.IsA<EfLeafNode>();
45  }
46 
47  /// If \p node is an EfLeafNode, returns a pointer to it as an EfLeafNode*.
48  /// Otherwise, return nullptr.
49  ///
50  static EfLeafNode* AsALeafNode(VdfNode *const node) {
51  if (node && node->GetNumOutputs() == 0) {
52  return dynamic_cast<EfLeafNode *>(node);
53  }
54  return nullptr;
55  }
56 
57  /// If \p node is an EfLeafNode, returns a pointer to it as a const
58  /// EfLeafNode*. Otherwise, return nullptr.
59  ///
60  static const EfLeafNode* AsALeafNode(const VdfNode *const node) {
61  if (node && node->GetNumOutputs() == 0) {
62  return dynamic_cast<const EfLeafNode *>(node);
63  }
64  return nullptr;
65  }
66 
67  /// Returns the single output the leaf node sources its value from. Returns
68  /// \c nullptr if the leaf node is not connected.
69  ///
70  static const VdfOutput *GetSourceOutput(const VdfNode &node);
71 
72  /// Returns the single masked output the leaf node sources its value from.
73  /// Returns an invalid masked output if the leaf node is not connected.
74  ///
75  static VdfMaskedOutput GetSourceMaskedOutput(const VdfNode &node);
76 
77  EF_API
78  EfLeafNode(VdfNetwork *network, TfType inputType);
79 
80 private:
81 
82  /// Should never be called.
83  virtual void Compute(const VdfContext &context) const override;
84 
85  // Only a network is allowed to delete nodes.
86  virtual ~EfLeafNode();
87 };
88 
89 inline const VdfOutput *
91 {
92  const VdfInput *const input = node.GetInputsIterator().begin()->second;
93  if (input && input->GetNumConnections() > 0) {
94  return &(*input)[0].GetSourceOutput();
95  }
96  return nullptr;
97 }
98 
99 inline VdfMaskedOutput
101 {
102  const VdfInput *const input = node.GetInputsIterator().begin()->second;
103  if (input && input->GetNumConnections() > 0) {
104  return (*input)[0].GetSourceMaskedOutput();
105  }
106  return VdfMaskedOutput();
107 }
108 
110 
111 #endif
const InputMapIterator GetInputsIterator() const
Definition: node.h:177
TF_DECLARE_PUBLIC_TOKENS(EfLeafTokens, EF_API, EF_LEAF_TOKENS)
static const VdfOutput * GetSourceOutput(const VdfNode &node)
Definition: leafNode.h:90
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
const_iterator begin() const
Definition: node.h:77
size_t GetNumConnections() const
Definition: input.h:58
bool IsA() const
Definition: node.h:147
Definition: node.h:52
virtual void Compute(const VdfContext &context) const =0
#define EF_API_TYPE
Definition: api.h:26
A terminal node, which is never executed.
Definition: leafNode.h:37
Definition: input.h:35
static EfLeafNode * AsALeafNode(VdfNode *const node)
Definition: leafNode.h:50
static bool IsALeafNode(const VdfNode &node)
Definition: leafNode.h:43
static const EfLeafNode * AsALeafNode(const VdfNode *const node)
Definition: leafNode.h:60
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
static VdfMaskedOutput GetSourceMaskedOutput(const VdfNode &node)
Definition: leafNode.h:100
#define EF_LEAF_TOKENS
Definition: leafNode.h:22
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
size_t GetNumOutputs() const
Definition: node.h:283
#define EF_API
Definition: api.h:25