HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
resolver.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_USD_RESOLVER_H
25 #define PXR_USD_USD_RESOLVER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/common.h"
30 
31 #include "pxr/usd/pcp/node.h"
32 #include "pxr/usd/pcp/iterator.h"
33 
34 #include "pxr/usd/sdf/path.h"
36 
38 
39 class PcpPrimIndex;
40 class UsdResolveTarget;
41 
42 /// \class Usd_Resolver
43 ///
44 /// Given a PcpPrimIndex, this class facilitates value resolution by providing
45 /// a mechanism for walking the composition structure in strong-to-weak order.
46 ///
47 class Usd_Resolver {
48 public:
49 
50  /// Constructs a resolver with the given \p index. The index is
51  /// held for the duration of the resolver's lifetime. If \p skipEmptyNodes
52  /// is \c true, the resolver will skip over nodes that provide no opinions
53  /// about the prim represented by \p index. Otherwise, the resolver will
54  /// visit all non-inert nodes in the index.
55  USD_API
56  explicit Usd_Resolver(
57  const PcpPrimIndex* index,
58  bool skipEmptyNodes = true);
59 
60  /// Constructs a resolver with the given \p resolveTarget. The resolve
61  /// target provides the prim index as well as the range of nodes and layers
62  /// this resolver will iterate over. If \p skipEmptyNodes is \c true, the
63  /// resolver will skip over nodes that provide no opinions about the prim
64  /// represented by \p index. Otherwise, the resolver will visit all
65  /// non-inert nodes in the index.
66  USD_API
67  explicit Usd_Resolver(
68  const UsdResolveTarget *resolveTarget,
69  bool skipEmptyNodes = true);
70 
71  /// Returns true when there is a current Node and Layer.
72  ///
73  /// The resolver must be known to be valid before calling any of the
74  /// accessor or iteration functions, otherwise the behavior will be
75  /// undefined.
76  bool IsValid() const {
77  return _curNode != _endNode;
78  }
79 
80  /// Advances the resolver to the next weaker Layer in the layer
81  /// stack, if the current LayerStack has no more layers, the resolver will
82  /// be advanced to the next weaker PcpNode. If no layers are available, the
83  /// resolver will be marked as invalid. Returns \c true iff the resolver
84  /// advanced to another node or became invalid.
85  ///
86  /// If the resolver is already invalid, the behavior of this function is
87  /// undefined.
88  USD_API
89  bool NextLayer();
90 
91  /// Skips all pending layers in the current LayerStack and jumps to
92  /// the next weaker PcpNode. When no more nodes are available, the resolver
93  /// will be marked as invalid.
94  ///
95  /// If the resolver is already invalid, the behavior of this function is
96  /// undefined.
97  USD_API
98  void NextNode();
99 
100  /// Returns the current PCP node for a valid resolver.
101  ///
102  /// This is useful for coarse grained resolution tasks, however
103  /// individual layers must be inspected in the common case.
104  ///
105  /// The behavior is undefined if the resolver is not valid.
106  PcpNodeRef GetNode() const {
107  return *_curNode;
108  }
109 
110  /// Returns the current layer for the current PcpNode for a valid resolver.
111  ///
112  /// The behavior is undefined if the resolver is not valid.
113  ///
114  /// PERFORMANCE: This returns a const-ref to avoid ref-count bumps during
115  /// resolution. This is safe under the assumption that no changes will occur
116  /// during resolution and that the lifetime of this object will be short.
117  const SdfLayerRefPtr& GetLayer() const {
118  return *_curLayer;
119  }
120 
121  /// Returns a translated path for the current PcpNode and Layer for a valid
122  /// resolver.
123  ///
124  /// The behavior is undefined if the resolver is not valid.
125  const SdfPath& GetLocalPath() const {
126  return _curNode->GetPath();
127  }
128 
129  /// Returns a translated path of the property with the given \p propName for
130  /// the current PcpNode and Layer for a valid resolver.
131  ///
132  /// The behavior is undefined if the resolver is not valid.
133  SdfPath GetLocalPath(TfToken const &propName) const {
134  return propName.IsEmpty() ? GetLocalPath() :
135  GetLocalPath().AppendProperty(propName);
136  }
137 
138  /// Returns the PcpPrimIndex.
139  ///
140  /// This value is initialized when the resolver is constructed and does not
141  /// change as a result of calling NextLayer() or NextNode().
142  const PcpPrimIndex* GetPrimIndex() const {
143  return _index;
144  }
145 
146 private:
147  void _SkipEmptyNodes();
148 
149  const PcpPrimIndex* _index;
150  bool _skipEmptyNodes;
151 
152  PcpNodeIterator _curNode;
153  PcpNodeIterator _endNode;
154  SdfLayerRefPtrVector::const_iterator _curLayer;
155  SdfLayerRefPtrVector::const_iterator _endLayer;
156  const UsdResolveTarget *_resolveTarget;
157 };
158 
160 
161 #endif // PXR_USD_USD_RESOLVER_H
USD_API Usd_Resolver(const PcpPrimIndex *index, bool skipEmptyNodes=true)
#define USD_API
Definition: api.h:40
USD_API void NextNode()
Definition: token.h:87
const PcpPrimIndex * GetPrimIndex() const
Definition: resolver.h:142
USD_API bool NextLayer()
const SdfPath & GetLocalPath() const
Definition: resolver.h:125
Definition: path.h:291
SDF_API SdfPath AppendProperty(TfToken const &propName) const
const SdfLayerRefPtr & GetLayer() const
Definition: resolver.h:117
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SdfPath GetLocalPath(TfToken const &propName) const
Definition: resolver.h:133
PcpNodeRef GetNode() const
Definition: resolver.h:106
bool IsValid() const
Definition: resolver.h:76
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:302