Loading...
Searching...
No Matches
extComputationContext.h
1//
2// Copyright 2017 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_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
8#define PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/base/vt/value.h"
13
14PXR_NAMESPACE_OPEN_SCOPE
15
21public:
22 HdExtComputationContext() = default;
24
31 virtual const VtValue &GetInputValue(const TfToken &name) const = 0;
32
39 template <typename T>
40 T GetTypedInputValue(const TfToken &name) const;
41
48 const TfToken &name) const = 0;
49
57 template <typename T>
58 const T *GetOptionalTypedInputValuePtr(const TfToken &name) const;
59
63 virtual void SetOutputValue(const TfToken &name, const VtValue &output) = 0;
64
68 template <typename T>
69 void SetTypedOutputValue(const TfToken &name, const T &output);
70
75 virtual void RaiseComputationError() = 0;
76
77private:
80 = delete;
81};
82
83template <typename T>
84T
86{
87 const VtValue &v = GetInputValue(name);
88 if (!v.IsHolding<T>()) {
90 "HdExtComputationContext::GetTypedInputValue<T> called with type T"
91 "not matching the type of the input value for '%s'.",
92 name.GetText());
93 return {};
94 }
95
96 return v.UncheckedGet<T>();
97}
98
99template <typename T>
100const T *
102{
103 const VtValue * const v = GetOptionalInputValuePtr(name);
104 if (!v) {
105 return nullptr;
106 }
107
108 if (!v->IsHolding<T>()) {
110 "HdExtComputationContext::GetOptionalTypedInputValue<T> called with "
111 "type T not matching the type of the input value for '%s'.",
112 name.GetText());
113 return nullptr;
114 }
115
116 return &(v->UncheckedGet<T>());
117}
118
119template <typename T>
120void
122SetTypedOutputValue(const TfToken &name, const T &output)
123{
124 SetOutputValue(name, VtValue(output));
125}
126
127PXR_NAMESPACE_CLOSE_SCOPE
128
129#endif // PXR_IMAGING_HD_EXT_COMPUTATION_CONTEXT_H
Interface class that defines the execution environment for the client to run a computation.
virtual const VtValue & GetInputValue(const TfToken &name) const =0
Obtains the value of an named input to the computation.
T GetTypedInputValue(const TfToken &name) const
Obtains the value of an named input to the computation.
const T * GetOptionalTypedInputValuePtr(const TfToken &name) const
Obtains the value of an named input to the computation.
void SetTypedOutputValue(const TfToken &name, const T &output)
Set the value of the specified output.
virtual void SetOutputValue(const TfToken &name, const VtValue &output)=0
Set the value of the specified output.
virtual void RaiseComputationError()=0
Called to indicate an error occurred while executing a computation so that its output are invalid.
virtual const VtValue * GetOptionalInputValuePtr(const TfToken &name) const =0
Obtains the value of an named input to the computation.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
char const * GetText() const
Return the text that this token represents.
Definition: token.h:179
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1002
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1046
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68