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 
41 /// \class Usd_Resolver
42 ///
43 /// Given a PcpPrimIndex, this class facilitates value resolution by providing
44 /// a mechanism for walking the composition structure in strong-to-weak order.
45 ///
46 class Usd_Resolver {
47 public:
48 
49  /// Constructs a resolver with the given \p index. The index is
50  /// held for the duration of the resolver's lifetime. If \p skipEmptyNodes
51  /// is \c true, the resolver will skip over nodes that provide no opinions
52  /// about the prim represented by \p index. Otherwise, the resolver will
53  /// visit all non-inert nodes in the index.
54  USD_API
55  explicit Usd_Resolver(const PcpPrimIndex* index, bool skipEmptyNodes = true);
56 
57  /// Returns true when there is a current Node and Layer.
58  bool IsValid() const {
59  return _curNode != _lastNode;
60  }
61 
62  /// Advances the resolver to the next weaker Layer in the layer
63  /// stack, if the current LayerStack has no more layers, the resolver will
64  /// be advanced to the next weaker PcpNode. If no layers are available, the
65  /// resolver will be marked as invalid. Returns \c true iff the resolver
66  /// advanced to another node or was or became invalid.
67  USD_API
68  bool NextLayer();
69 
70  /// Skips all pending layers in the current LayerStack and jumps to
71  /// the next weaker PcpNode. When no more nodes are available, the resolver
72  /// will be marked as invalid.
73  USD_API
74  void NextNode();
75 
76  /// Returns the current PCP node.
77  ///
78  /// This is useful for coarse grained resolution tasks, however
79  /// individual layers must be inspected in the common case.
80  USD_API
81  PcpNodeRef GetNode() const;
82 
83  /// Returns the current layer for the current PcpNode.
84  ///
85  /// PERFORMANCE: This returns a const-ref to avoid ref-count bumps during
86  /// resolution. This is safe under the assumption that no changes will occur
87  /// during resolution and that the lifetime of this object will be short.
88  USD_API
89  const SdfLayerRefPtr& GetLayer() const;
90 
91  /// Returns a translated path for the current PcpNode and Layer.
92  USD_API
93  const SdfPath& GetLocalPath() const;
94 
95  SdfPath GetLocalPath(TfToken const &propName) const {
96  return propName.IsEmpty() ? GetLocalPath() :
97  GetLocalPath().AppendProperty(propName);
98  }
99 
100  /// Returns the PcpPrimIndex.
101  ///
102  /// This value is initialized when the resolver is constructed and does not
103  /// change as a result of calling NextLayer() or NextNode().
104  USD_API
105  const PcpPrimIndex* GetPrimIndex() const;
106 
107  /// \struct Position
108  /// Represents a position in the prim index for value resolution.
109  /// For performance, this object stores pointers and iterators to avoid
110  /// unnecessary copies and ref-count bumps.
111  struct Position
112  {
113  Position() { }
114 
115  PcpNodeRef GetNode() const { return *_curNode; }
116  const SdfLayerRefPtr& GetLayer() const { return *_curLayer; }
117  const SdfPath& GetLocalPath() const { return _curNode->GetPath(); }
118  SdfPath GetLocalPath(TfToken const &propName) const {
119  return propName.IsEmpty() ? GetLocalPath() :
120  GetLocalPath().AppendProperty(propName);
121  }
122 
123  private:
124  friend class Usd_Resolver;
125 
126  Position(const PcpNodeIterator& curNode,
127  const SdfLayerRefPtrVector::const_iterator& curLayer)
128  : _curNode(curNode), _curLayer(curLayer) { }
129 
130  PcpNodeIterator _curNode;
131  SdfLayerRefPtrVector::const_iterator _curLayer;
132  };
133 
134  /// Returns a Position object representing the current node and layer in
135  /// the prim index.
136  USD_API
137  Position GetPosition() const;
138 
139 private:
140  void _Init();
141  void _SkipEmptyNodes();
142 
143  const PcpPrimIndex* _index;
144  bool _skipEmptyNodes;
145 
146  PcpNodeIterator _curNode;
147  PcpNodeIterator _lastNode;
148  SdfLayerRefPtrVector::const_iterator _curLayer;
149  SdfLayerRefPtrVector::const_iterator _lastLayer;
150 };
151 
153 
154 #endif // PXR_USD_USD_RESOLVER_H
USD_API Usd_Resolver(const PcpPrimIndex *index, bool skipEmptyNodes=true)
#define USD_API
Definition: api.h:40
PcpNodeRef GetNode() const
Definition: resolver.h:115
USD_API const PcpPrimIndex * GetPrimIndex() const
const SdfPath & GetLocalPath() const
Definition: resolver.h:117
USD_API void NextNode()
Definition: token.h:87
USD_API bool NextLayer()
SdfPath GetLocalPath(TfToken const &propName) const
Definition: resolver.h:118
USD_API PcpNodeRef GetNode() const
const SdfLayerRefPtr & GetLayer() const
Definition: resolver.h:116
Definition: path.h:288
SDF_API SdfPath AppendProperty(TfToken const &propName) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
USD_API const SdfPath & GetLocalPath() const
Returns a translated path for the current PcpNode and Layer.
GLuint index
Definition: glcorearb.h:785
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SdfPath GetLocalPath(TfToken const &propName) const
Definition: resolver.h:95
USD_API const SdfLayerRefPtr & GetLayer() const
USD_API Position GetPosition() const
bool IsValid() const
Returns true when there is a current Node and Layer.
Definition: resolver.h:58
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:302