HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
expressionVariables.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 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_USD_PCP_EXPRESSION_VARIABLES_H
8 #define PXR_USD_PCP_EXPRESSION_VARIABLES_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/pcp/api.h"
14 
15 #include "pxr/base/vt/dictionary.h"
16 
17 #include <utility>
18 #include <unordered_map>
19 
21 
22 /// \class PcpExpressionVariables
23 ///
24 /// Object containing composed expression variables associated with a given
25 /// layer stack, identified by a PcpExpressionVariablesSource.
27 {
28 public:
29  /// Compute the composed expression variables for \p sourceLayerStackId,
30  /// recursively computing and composing the overrides specified by
31  /// its expressionVariableOverridesSource. If \p overrideExpressionVars is
32  /// provided, it will be used as the overrides instead of performing
33  /// the recursive computation.
34  PCP_API
36  Compute(
37  const PcpLayerStackIdentifier& sourceLayerStackId,
38  const PcpLayerStackIdentifier& rootLayerStackId,
39  const PcpExpressionVariables* overrideExpressionVars = nullptr);
40 
41  /// Create a new object with no expression variables and the source set
42  /// to the root layer stack.
43  PcpExpressionVariables() = default;
44 
45  /// Creates a new object for \p source with the given
46  /// \p expressionVariables.
49  const VtDictionary& expressionVariables)
52  VtDictionary(expressionVariables))
53  { }
54 
55  /// Creates a new object for \p source with the given
56  /// \p expressionVariables.
59  VtDictionary&& expressionVariables)
60  : _source(std::move(source))
61  , _expressionVariables(std::move(expressionVariables))
62  { }
63 
64  /// \name Comparison Operators
65  /// @{
66  bool operator==(const PcpExpressionVariables& rhs) const
67  {
68  return (this == &rhs) ||
69  (std::tie(_source, _expressionVariables) ==
70  std::tie(rhs._source, rhs._expressionVariables));
71  }
72 
73  bool operator!=(const PcpExpressionVariables& rhs) const
74  {
75  return !(*this == rhs);
76  }
77  /// @}
78 
79  /// Return the source of the composed expression variables.
81  { return _source; }
82 
83  /// Returns the composed expression variables dictionary.
84  const VtDictionary& GetVariables() const
85  { return _expressionVariables; }
86 
87  /// Set the composed expression variables to \p variables.
88  void SetVariables(const VtDictionary& variables)
89  { _expressionVariables = variables; }
90 
91 private:
93  VtDictionary _expressionVariables;
94 };
95 
96 // ------------------------------------------------------------
97 
98 /// \class PcpExpressionVariableCachingComposer
99 ///
100 /// Helper object for computing PcpExpressionVariable objects. This gives the
101 /// same results as PcpExpressionVariables::Compute, but caches the results
102 /// of the recursive override computations so they can be reused by
103 /// subsequent computations.
105 {
106 public:
107  PCP_API
109  const PcpLayerStackIdentifier& rootLayerStackIdentifier);
110 
111  /// Compute the composed expression variables for the layer stack with
112  /// the given \p id. This will recursively compute the overriding
113  /// expression variables specified in \p id.
114  PCP_API
117 
118 private:
119  PcpLayerStackIdentifier _rootLayerStackId;
120 
121  using _IdentifierToExpressionVarsMap = std::unordered_map<
123  _IdentifierToExpressionVarsMap _identifierToExpressionVars;
124 };
125 
127 
128 #endif
PcpExpressionVariables(const PcpExpressionVariablesSource &source, const VtDictionary &expressionVariables)
void SetVariables(const VtDictionary &variables)
Set the composed expression variables to variables.
const VtDictionary & GetVariables() const
Returns the composed expression variables dictionary.
const PcpExpressionVariablesSource & GetSource() const
Return the source of the composed expression variables.
bool operator!=(const PcpExpressionVariables &rhs) const
PCP_API PcpExpressionVariableCachingComposer(const PcpLayerStackIdentifier &rootLayerStackIdentifier)
static PCP_API PcpExpressionVariables Compute(const PcpLayerStackIdentifier &sourceLayerStackId, const PcpLayerStackIdentifier &rootLayerStackId, const PcpExpressionVariables *overrideExpressionVars=nullptr)
Definition: hash.h:472
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
PcpExpressionVariables()=default
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PCP_API const PcpExpressionVariables & ComputeExpressionVariables(const PcpLayerStackIdentifier &id)
bool operator==(const PcpExpressionVariables &rhs) const
#define PCP_API
Definition: api.h:23
PcpExpressionVariables(PcpExpressionVariablesSource &&source, VtDictionary &&expressionVariables)