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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_PCP_EXPRESSION_VARIABLES_H
25 #define PXR_USD_PCP_EXPRESSION_VARIABLES_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/pcp/api.h"
31 
32 #include "pxr/base/vt/dictionary.h"
33 
34 #include <utility>
35 #include <unordered_map>
36 
38 
39 /// \class PcpExpressionVariables
40 ///
41 /// Object containing composed expression variables associated with a given
42 /// layer stack, identified by a PcpExpressionVariablesSource.
44 {
45 public:
46  /// Compute the composed expression variables for \p sourceLayerStackId,
47  /// recursively computing and composing the overrides specified by
48  /// its expressionVariableOverridesSource. If \p overrideExpressionVars is
49  /// provided, it will be used as the overrides instead of performing
50  /// the recursive computation.
51  PCP_API
53  Compute(
54  const PcpLayerStackIdentifier& sourceLayerStackId,
55  const PcpLayerStackIdentifier& rootLayerStackId,
56  const PcpExpressionVariables* overrideExpressionVars = nullptr);
57 
58  /// Create a new object with no expression variables and the source set
59  /// to the root layer stack.
60  PcpExpressionVariables() = default;
61 
62  /// Creates a new object for \p source with the given
63  /// \p expressionVariables.
66  const VtDictionary& expressionVariables)
69  VtDictionary(expressionVariables))
70  { }
71 
72  /// Creates a new object for \p source with the given
73  /// \p expressionVariables.
76  VtDictionary&& expressionVariables)
77  : _source(std::move(source))
78  , _expressionVariables(std::move(expressionVariables))
79  { }
80 
81  /// \name Comparison Operators
82  /// @{
83  bool operator==(const PcpExpressionVariables& rhs) const
84  {
85  return (this == &rhs) ||
86  (std::tie(_source, _expressionVariables) ==
87  std::tie(rhs._source, rhs._expressionVariables));
88  }
89 
90  bool operator!=(const PcpExpressionVariables& rhs) const
91  {
92  return !(*this == rhs);
93  }
94  /// @}
95 
96  /// Return the source of the composed expression variables.
98  { return _source; }
99 
100  /// Returns the composed expression variables dictionary.
101  const VtDictionary& GetVariables() const
102  { return _expressionVariables; }
103 
104  /// Set the composed expression variables to \p variables.
105  void SetVariables(const VtDictionary& variables)
106  { _expressionVariables = variables; }
107 
108 private:
110  VtDictionary _expressionVariables;
111 };
112 
113 // ------------------------------------------------------------
114 
115 /// \class PcpExpressionVariableCachingComposer
116 ///
117 /// Helper object for computing PcpExpressionVariable objects. This gives the
118 /// same results as PcpExpressionVariables::Compute, but caches the results
119 /// of the recursive override computations so they can be reused by
120 /// subsequent computations.
122 {
123 public:
124  PCP_API
126  const PcpLayerStackIdentifier& rootLayerStackIdentifier);
127 
128  /// Compute the composed expression variables for the layer stack with
129  /// the given \p id. This will recursively compute the overriding
130  /// expression variables specified in \p id.
131  PCP_API
134 
135 private:
136  PcpLayerStackIdentifier _rootLayerStackId;
137 
138  using _IdentifierToExpressionVarsMap = std::unordered_map<
140  _IdentifierToExpressionVarsMap _identifierToExpressionVars;
141 };
142 
144 
145 #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:477
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
PcpExpressionVariables()=default
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
PCP_API const PcpExpressionVariables & ComputeExpressionVariables(const PcpLayerStackIdentifier &id)
bool operator==(const PcpExpressionVariables &rhs) const
#define PCP_API
Definition: api.h:40
PcpExpressionVariables(PcpExpressionVariablesSource &&source, VtDictionary &&expressionVariables)