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