24 #ifndef PXR_USD_SDF_PATH_NODE_H
25 #define PXR_USD_SDF_PATH_NODE_H
28 #include "pxr/usd/sdf/api.h"
32 #include <boost/noncopyable.hpp>
33 #include <boost/intrusive_ptr.hpp>
35 #include <tbb/atomic.h>
37 PXR_NAMESPACE_OPEN_SCOPE
62 Sdf_PathNode(Sdf_PathNode
const &) =
delete;
63 Sdf_PathNode &operator=(Sdf_PathNode
const &) =
delete;
85 PrimVariantSelectionNode,
109 RelationalAttributeNode,
126 static Sdf_PathPrimNodeHandle
127 FindOrCreatePrim(Sdf_PathNode
const *parent,
const TfToken &name);
129 static Sdf_PathPropNodeHandle
130 FindOrCreatePrimProperty(Sdf_PathNode
const *parent,
const TfToken &name);
132 static Sdf_PathPrimNodeHandle
133 FindOrCreatePrimVariantSelection(Sdf_PathNode
const *parent,
137 static Sdf_PathPropNodeHandle
138 FindOrCreateTarget(Sdf_PathNode
const *parent,
141 static Sdf_PathPropNodeHandle
142 FindOrCreateRelationalAttribute(Sdf_PathNode
const *parent,
145 static Sdf_PathPropNodeHandle
146 FindOrCreateMapper(Sdf_PathNode
const *parent,
SdfPath const &targetPath);
148 static Sdf_PathPropNodeHandle
149 FindOrCreateMapperArg(Sdf_PathNode
const *parent,
const TfToken &name);
151 static Sdf_PathPropNodeHandle
152 FindOrCreateExpression(Sdf_PathNode
const *parent);
154 static Sdf_PathNode
const *GetAbsoluteRootNode();
155 static Sdf_PathNode
const *GetRelativeRootNode();
157 NodeType GetNodeType()
const {
return NodeType(_nodeType); }
159 static std::pair<Sdf_PathNode const *, Sdf_PathNode const *>
160 RemoveCommonSuffix(Sdf_PathNode
const *a,
161 Sdf_PathNode
const *b,
162 bool stopAtRootPrim);
165 Sdf_PathNode
const *GetParentNode()
const {
return _parent.get(); }
167 size_t GetElementCount()
const {
return size_t(_elementCount); }
168 bool IsAbsolutePath()
const {
return _isAbsolute; }
169 bool IsAbsoluteRoot()
const {
return (_isAbsolute) & (!_elementCount); }
170 bool ContainsTargetPath()
const {
return _containsTargetPath; }
171 bool IsNamespaced()
const {
172 return (_nodeType == PrimPropertyNode ||
173 _nodeType == RelationalAttributeNode) && _IsNamespacedImpl();
176 bool ContainsPrimVariantSelection()
const {
177 return _containsPrimVariantSelection;
184 inline const TfToken &GetName()
const;
188 inline const SdfPath &GetTargetPath()
const;
190 typedef std::pair<TfToken, TfToken> VariantSelectionType;
191 inline const VariantSelectionType& GetVariantSelection()
const;
195 inline TfToken GetElement()
const;
198 void AppendText(std::string *str)
const;
202 GetPathToken(Sdf_PathNode
const *primPart, Sdf_PathNode
const *propPart);
206 GetPathAsToken(Sdf_PathNode
const *primPart, Sdf_PathNode
const *propPart);
211 inline bool operator()(T
const &a, T
const &b)
const {
218 template <
class Less>
219 inline bool Compare(
const Sdf_PathNode &rhs)
const;
223 unsigned int GetCurrentRefCount()
const {
return _refCount; }
226 Sdf_PathNode(Sdf_PathNode
const *parent, NodeType nodeType)
229 , _elementCount(parent ? parent->_elementCount + 1 : 1)
230 , _nodeType(nodeType)
231 , _isAbsolute(parent && parent->IsAbsolutePath())
232 , _containsPrimVariantSelection(
233 nodeType == PrimVariantSelectionNode ||
234 (parent && parent->_containsPrimVariantSelection))
235 , _containsTargetPath(nodeType == TargetNode ||
236 nodeType == MapperNode ||
237 (parent && parent->_containsTargetPath))
242 explicit Sdf_PathNode(
bool isAbsolute);
246 _RemovePathTokenFromTable();
252 inline void _Destroy()
const;
255 static TfToken _CreatePathToken(Sdf_PathNode
const *primPart,
256 Sdf_PathNode
const *propPart);
259 SDF_API
void _RemovePathTokenFromTable()
const;
261 struct _EqualElement {
263 inline bool operator()(T
const &a, T
const &b)
const {
268 friend struct Sdf_PathNodePrivateAccess;
271 friend void intrusive_ptr_add_ref(
const Sdf_PathNode*);
272 friend void intrusive_ptr_release(
const Sdf_PathNode*);
276 template <
class Derived>
277 Derived
const *_Downcast()
const {
278 return static_cast<Derived
const *
>(
this);
282 bool _IsNamespacedImpl()
const;
285 VariantSelectionType
const &_GetEmptyVariantSelection()
const;
289 const Sdf_PathNodeConstRefPtr _parent;
290 mutable tbb::atomic<unsigned int> _refCount;
292 const short _elementCount;
293 const unsigned char _nodeType;
294 const bool _isAbsolute:1;
295 const bool _containsPrimVariantSelection:1;
296 const bool _containsTargetPath:1;
306 mutable bool _hasToken:1;
309 class Sdf_PrimPartPathNode :
public Sdf_PathNode {
311 using Sdf_PathNode::Sdf_PathNode;
312 SDF_API
void operator delete (
void *p);
315 class Sdf_PropPartPathNode :
public Sdf_PathNode {
317 using Sdf_PathNode::Sdf_PathNode;
318 SDF_API
void operator delete (
void *p);
321 class Sdf_RootPathNode :
public Sdf_PrimPartPathNode {
323 typedef bool ComparisonType;
324 static const NodeType nodeType = Sdf_PathNode::RootNode;
326 static SDF_API Sdf_PathNode
const *New(
bool isAbsolute);
330 Sdf_RootPathNode(
bool isAbsolute) : Sdf_PrimPartPathNode(isAbsolute) {}
332 ComparisonType _GetComparisonValue()
const {
335 return !IsAbsolutePath();
338 friend class Sdf_PathNode;
339 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
342 class Sdf_PrimPathNode :
public Sdf_PrimPartPathNode {
344 typedef TfToken ComparisonType;
345 static const NodeType nodeType = Sdf_PathNode::PrimNode;
348 Sdf_PrimPathNode(Sdf_PathNode
const *parent,
350 : Sdf_PrimPartPathNode(parent, nodeType)
353 SDF_API ~Sdf_PrimPathNode();
355 const ComparisonType &_GetComparisonValue()
const {
return _name; }
357 friend class Sdf_PathNode;
358 friend struct Sdf_PathNodePrivateAccess;
359 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
365 class Sdf_PrimPropertyPathNode :
public Sdf_PropPartPathNode {
367 typedef TfToken ComparisonType;
368 static const NodeType nodeType = Sdf_PathNode::PrimPropertyNode;
371 Sdf_PrimPropertyPathNode(Sdf_PathNode
const *parent,
373 : Sdf_PropPartPathNode(parent, nodeType)
376 SDF_API ~Sdf_PrimPropertyPathNode();
378 friend class Sdf_PathNode;
379 friend struct Sdf_PathNodePrivateAccess;
380 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
382 const ComparisonType &_GetComparisonValue()
const {
return _name; }
388 class Sdf_PrimVariantSelectionNode :
public Sdf_PrimPartPathNode {
390 typedef VariantSelectionType ComparisonType;
391 static const NodeType nodeType = Sdf_PathNode::PrimVariantSelectionNode;
393 const TfToken &_GetNameImpl()
const;
394 void _AppendText(std::string *str)
const;
397 Sdf_PrimVariantSelectionNode(Sdf_PathNode
const *parent,
398 const VariantSelectionType &variantSelection)
399 : Sdf_PrimPartPathNode(parent, nodeType)
400 , _variantSelection(new VariantSelectionType(variantSelection)) {}
402 SDF_API ~Sdf_PrimVariantSelectionNode();
404 const ComparisonType &_GetComparisonValue()
const {
405 return *_variantSelection;
408 friend class Sdf_PathNode;
409 friend struct Sdf_PathNodePrivateAccess;
410 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
413 std::unique_ptr<VariantSelectionType> _variantSelection;
416 class Sdf_TargetPathNode :
public Sdf_PropPartPathNode {
418 typedef SdfPath ComparisonType;
419 static const NodeType nodeType = Sdf_PathNode::TargetNode;
421 void _AppendText(std::string *str)
const;
424 Sdf_TargetPathNode(Sdf_PathNode
const *parent,
426 : Sdf_PropPartPathNode(parent, nodeType)
427 , _targetPath(targetPath) {}
429 SDF_API ~Sdf_TargetPathNode();
431 const ComparisonType& _GetComparisonValue()
const {
return _targetPath; }
433 friend class Sdf_PathNode;
434 friend struct Sdf_PathNodePrivateAccess;
435 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
441 class Sdf_RelationalAttributePathNode :
public Sdf_PropPartPathNode {
443 typedef TfToken ComparisonType;
444 static const NodeType nodeType = Sdf_PathNode::RelationalAttributeNode;
447 Sdf_RelationalAttributePathNode(Sdf_PathNode
const *parent,
449 : Sdf_PropPartPathNode(parent, nodeType)
452 SDF_API ~Sdf_RelationalAttributePathNode();
454 const ComparisonType& _GetComparisonValue()
const {
return _name; }
456 friend class Sdf_PathNode;
457 friend struct Sdf_PathNodePrivateAccess;
458 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
464 class Sdf_MapperPathNode :
public Sdf_PropPartPathNode {
466 typedef SdfPath ComparisonType;
467 static const NodeType nodeType = Sdf_PathNode::MapperNode;
469 void _AppendText(std::string *str)
const;
472 Sdf_MapperPathNode(Sdf_PathNode
const *parent,
474 : Sdf_PropPartPathNode(parent, nodeType)
475 , _targetPath(targetPath) {}
477 SDF_API ~Sdf_MapperPathNode();
479 const ComparisonType& _GetComparisonValue()
const {
return _targetPath; }
481 friend class Sdf_PathNode;
482 friend struct Sdf_PathNodePrivateAccess;
483 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
489 class Sdf_MapperArgPathNode :
public Sdf_PropPartPathNode {
491 typedef TfToken ComparisonType;
492 static const NodeType nodeType = Sdf_PathNode::MapperArgNode;
494 void _AppendText(std::string *str)
const;
497 Sdf_MapperArgPathNode(Sdf_PathNode
const *parent,
499 : Sdf_PropPartPathNode(parent, nodeType)
502 SDF_API ~Sdf_MapperArgPathNode();
504 const ComparisonType& _GetComparisonValue()
const {
return _name; }
506 friend class Sdf_PathNode;
507 friend struct Sdf_PathNodePrivateAccess;
508 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
514 class Sdf_ExpressionPathNode :
public Sdf_PropPartPathNode {
516 typedef void *ComparisonType;
517 static const NodeType nodeType = Sdf_PathNode::ExpressionNode;
519 void _AppendText(std::string *str)
const;
522 Sdf_ExpressionPathNode(Sdf_PathNode
const *parent)
523 : Sdf_PropPartPathNode(parent, nodeType) {}
525 SDF_API ~Sdf_ExpressionPathNode();
527 ComparisonType _GetComparisonValue()
const {
return nullptr; }
529 friend class Sdf_PathNode;
530 friend struct Sdf_PathNodePrivateAccess;
531 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
537 template <
int nodeType>
538 struct Sdf_PathNodeTypeToType {
540 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimNode> {
541 typedef Sdf_PrimPathNode Type;
543 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimPropertyNode> {
544 typedef Sdf_PrimPropertyPathNode Type;
546 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::RelationalAttributeNode> {
547 typedef Sdf_RelationalAttributePathNode Type;
549 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperArgNode> {
550 typedef Sdf_MapperArgPathNode Type;
552 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::TargetNode> {
553 typedef Sdf_TargetPathNode Type;
555 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperNode> {
556 typedef Sdf_MapperPathNode Type;
558 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimVariantSelectionNode> {
559 typedef Sdf_PrimVariantSelectionNode Type;
561 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::ExpressionNode> {
562 typedef Sdf_ExpressionPathNode Type;
564 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::RootNode> {
565 typedef Sdf_RootPathNode Type;
568 template <
int nodeType,
class Comp>
569 struct Sdf_PathNodeCompare {
570 inline bool operator()(
const Sdf_PathNode &lhs,
571 const Sdf_PathNode &rhs)
const {
572 typedef typename Sdf_PathNodeTypeToType<nodeType>::Type Type;
573 return Comp()(
static_cast<const Type&
>(lhs)._GetComparisonValue(),
574 static_cast<const Type&
>(rhs)._GetComparisonValue());
578 template <
class Comp>
580 Sdf_PathNode::Compare(
const Sdf_PathNode &rhs)
const
590 NodeType nodeType = GetNodeType(), rhsNodeType = rhs.GetNodeType();
591 if (nodeType != rhsNodeType) {
592 return Comp()(nodeType, rhsNodeType);
597 case Sdf_PathNode::PrimNode:
598 return Sdf_PathNodeCompare<Sdf_PathNode::PrimNode,
600 case Sdf_PathNode::PrimPropertyNode:
601 return Sdf_PathNodeCompare<Sdf_PathNode::PrimPropertyNode,
603 case Sdf_PathNode::RelationalAttributeNode:
604 return Sdf_PathNodeCompare<Sdf_PathNode::RelationalAttributeNode,
606 case Sdf_PathNode::MapperArgNode:
607 return Sdf_PathNodeCompare<Sdf_PathNode::MapperArgNode,
609 case Sdf_PathNode::TargetNode:
610 return Sdf_PathNodeCompare<Sdf_PathNode::TargetNode,
612 case Sdf_PathNode::MapperNode:
613 return Sdf_PathNodeCompare<Sdf_PathNode::MapperNode,
615 case Sdf_PathNode::PrimVariantSelectionNode:
616 return Sdf_PathNodeCompare<Sdf_PathNode::PrimVariantSelectionNode,
618 case Sdf_PathNode::ExpressionNode:
619 return Sdf_PathNodeCompare<Sdf_PathNode::ExpressionNode,
621 case Sdf_PathNode::RootNode:
622 return Sdf_PathNodeCompare<Sdf_PathNode::RootNode,
631 Sdf_PathNode::_Destroy()
const
636 return delete _Downcast<Sdf_RootPathNode>();
638 return delete _Downcast<Sdf_PrimPathNode>();
639 case PrimPropertyNode:
640 return delete _Downcast<Sdf_PrimPropertyPathNode>();
641 case PrimVariantSelectionNode:
642 return delete _Downcast<Sdf_PrimVariantSelectionNode>();
644 return delete _Downcast<Sdf_TargetPathNode>();
645 case RelationalAttributeNode:
646 return delete _Downcast<Sdf_RelationalAttributePathNode>();
648 return delete _Downcast<Sdf_MapperPathNode>();
650 return delete _Downcast<Sdf_MapperArgPathNode>();
652 return delete _Downcast<Sdf_ExpressionPathNode>();
659 Sdf_PathNode::GetName()
const
663 return SdfPathTokens->empty;
665 return IsAbsolutePath() ?
666 SdfPathTokens->absoluteIndicator : SdfPathTokens->relativeRoot;
668 return _Downcast<Sdf_PrimPathNode>()->_name;
669 case PrimPropertyNode:
670 return _Downcast<Sdf_PrimPropertyPathNode>()->_name;
671 case PrimVariantSelectionNode:
672 return _Downcast<Sdf_PrimVariantSelectionNode>()->_GetNameImpl();
673 case RelationalAttributeNode:
674 return _Downcast<Sdf_RelationalAttributePathNode>()->_name;
676 return _Downcast<Sdf_MapperArgPathNode>()->_name;
678 return SdfPathTokens->expressionIndicator;
683 Sdf_PathNode::GetTargetPath()
const
689 return _Downcast<Sdf_TargetPathNode>()->_targetPath;
691 return _Downcast<Sdf_MapperPathNode>()->_targetPath;
695 inline const Sdf_PathNode::VariantSelectionType &
696 Sdf_PathNode::GetVariantSelection()
const
698 if (ARCH_LIKELY(_nodeType == PrimVariantSelectionNode)) {
699 return *_Downcast<Sdf_PrimVariantSelectionNode>()->_variantSelection;
701 return _GetEmptyVariantSelection();
705 Sdf_PathNode::GetElement()
const
711 return _Downcast<Sdf_PrimPathNode>()->_name;
720 SDF_API
void Sdf_DumpPathStats();
722 inline void intrusive_ptr_add_ref(
const PXR_NS::Sdf_PathNode* p) {
725 inline void intrusive_ptr_release(
const PXR_NS::Sdf_PathNode* p) {
726 if (p->_refCount.fetch_and_decrement() == 1)
730 PXR_NAMESPACE_CLOSE_SCOPE
732 #endif // PXR_USD_SDF_PATH_NODE_H
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Token for efficient comparison, assignment, and hashing of known strings.
A path value used to locate objects in layers or scenegraphs.
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...