HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
firstValidInputValue.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_FIRST_VALID_INPUT_VALUE_H
8 #define PXR_EXEC_EF_FIRST_VALID_INPUT_VALUE_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/context.h"
16 #include "pxr/exec/vdf/iterator.h"
17 #include "pxr/exec/vdf/node.h"
18 
20 
21 ////////////////////////////////////////////////////////////////////////////////
22 ///
23 /// A function that may be used as a callback (or in a callback) to return the
24 /// first valid input value.
25 ///
26 /// This will iterate over the inputs in the order they have been registered
27 /// and return the value of the first valid input, i.e. the first input that
28 /// provides a value. If no valid input value exists, return the fallback value
29 /// for TYPE.
30 ///
31 template <typename Type>
32 Type
34 {
35  struct ContextAccess final : public VdfIterator {
36  const VdfNode &GetNode(const VdfContext &context) {
37  return _GetNode(context);
38  }
39  };
40 
41  // Iterate over all inputs, and return the first valid input value.
42  const VdfNode &node = ContextAccess().GetNode(context);
43  for (const std::pair<TfToken, VdfInput *> &in : node.GetInputsIterator()) {
44  if (const Type *value = context.GetInputValuePtr<Type>(in.first)) {
45  return *value;
46  }
47  }
48 
49  // Ask the type registry for the fallback value to use.
51 }
52 
54 
55 #endif
const InputMapIterator GetInputsIterator() const
Definition: node.h:177
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
Definition: node.h:52
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
const T * GetInputValuePtr(const TfToken &name) const
Definition: context.h:319
PXR_NAMESPACE_OPEN_SCOPE Type EfGetFirstValidInputValue(const VdfContext &context)
static VDF_API VdfExecutionTypeRegistry & GetInstance()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const VdfNode & _GetNode(const VdfContext &context) const
Definition: iterator.h:45