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