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 
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
15 
17 #include "pxr/exec/vdf/node.h"
19 
20 PXR_NAMESPACE_OPEN_SCOPE
21 
22 #define EF_LEAF_TOKENS \
23  (in)
24 
25 TF_DECLARE_PUBLIC_TOKENS(EfLeafTokens, EF_API, EF_LEAF_TOKENS);
26 
37 class EF_API_TYPE EfLeafNode final : public VdfNode
38 {
39 public:
43  static bool IsALeafNode(const VdfNode &node) {
44  return node.GetNumOutputs() == 0 && node.IsA<EfLeafNode>();
45  }
46 
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 
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 
70  static const VdfOutput *GetSourceOutput(const VdfNode &node);
71 
75  static VdfMaskedOutput GetSourceMaskedOutput(const VdfNode &node);
76 
77  EF_API
78  EfLeafNode(VdfNetwork *network, TfType inputType);
79 
80 private:
81 
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 
109 PXR_NAMESPACE_CLOSE_SCOPE
110 
111 #endif
A VdfNetwork is a collection of VdfNodes and their connections.
Definition: network.h:59
bool IsA() const
Returns true, if this node is of type TYPE.
Definition: node.h:147
static const EfLeafNode * AsALeafNode(const VdfNode *const node)
If node is an EfLeafNode, returns a pointer to it as a const EfLeafNode*.
Definition: leafNode.h:60
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:52
A terminal node, which is never executed.
Definition: leafNode.h:37
A VdfInput is used to connect a VdfNode to one or more VdfNodes' outputs.
Definition: input.h:35
static bool IsALeafNode(const VdfNode &node)
Returns true if the given node is an EfLeafNode.
Definition: leafNode.h:43
virtual void Compute(const VdfContext &context) const =0
This is the method called to perform computation.
size_t GetNumConnections() const
Returns the number of connections for this input.
Definition: input.h:58
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92
static VdfMaskedOutput GetSourceMaskedOutput(const VdfNode &node)
Returns the single masked output the leaf node sources its value from.
Definition: leafNode.h:100
size_t GetNumOutputs() const
Returns the number of outputs that this node currently has.
Definition: node.h:283
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
A VdfOutput represents an output on a node.
Definition: output.h:31
This file defines some macros that are useful for declaring and using static TfTokens.
const InputMapIterator GetInputsIterator() const
Returns an iterator class that can be used with TF_FOR_ALL to iterate through the inputs.
Definition: node.h:177
TfType represents a dynamic runtime type.
Definition: type.h:47
A context is the parameter bundle passed to callbacks of computations.
Definition: context.h:39
static EfLeafNode * AsALeafNode(VdfNode *const node)
If node is an EfLeafNode, returns a pointer to it as an EfLeafNode*.
Definition: leafNode.h:50
static const VdfOutput * GetSourceOutput(const VdfNode &node)
Returns the single output the leaf node sources its value from.
Definition: leafNode.h:90