24 #ifndef PXR_USD_SDF_PATH_NODE_H 25 #define PXR_USD_SDF_PATH_NODE_H 28 #include "pxr/usd/sdf/api.h" 29 #include "pxr/base/tf/functionRef.h" 33 #include <boost/noncopyable.hpp> 34 #include <boost/intrusive_ptr.hpp> 36 #include <tbb/atomic.h> 38 PXR_NAMESPACE_OPEN_SCOPE
63 Sdf_PathNode(Sdf_PathNode
const &) =
delete;
64 Sdf_PathNode &operator=(Sdf_PathNode
const &) =
delete;
86 PrimVariantSelectionNode,
110 RelationalAttributeNode,
127 static Sdf_PathPrimNodeHandle
128 FindOrCreatePrim(Sdf_PathNode
const *parent,
const TfToken &name,
131 static Sdf_PathPropNodeHandle
132 FindOrCreatePrimProperty(
133 Sdf_PathNode
const *parent,
const TfToken &name,
136 static Sdf_PathPrimNodeHandle
137 FindOrCreatePrimVariantSelection(Sdf_PathNode
const *parent,
142 static Sdf_PathPropNodeHandle
143 FindOrCreateTarget(Sdf_PathNode
const *parent,
147 static Sdf_PathPropNodeHandle
148 FindOrCreateRelationalAttribute(Sdf_PathNode
const *parent,
152 static Sdf_PathPropNodeHandle
153 FindOrCreateMapper(Sdf_PathNode
const *parent,
SdfPath const &targetPath,
156 static Sdf_PathPropNodeHandle
157 FindOrCreateMapperArg(Sdf_PathNode
const *parent,
const TfToken &name,
160 static Sdf_PathPropNodeHandle
161 FindOrCreateExpression(Sdf_PathNode
const *parent,
164 static Sdf_PathNode
const *GetAbsoluteRootNode();
165 static Sdf_PathNode
const *GetRelativeRootNode();
167 NodeType GetNodeType()
const {
return NodeType(_nodeType); }
169 static std::pair<Sdf_PathNode const *, Sdf_PathNode const *>
170 RemoveCommonSuffix(Sdf_PathNode
const *a,
171 Sdf_PathNode
const *b,
172 bool stopAtRootPrim);
175 Sdf_PathNode
const *GetParentNode()
const {
return _parent.get(); }
177 size_t GetElementCount()
const {
return size_t(_elementCount); }
178 bool IsAbsolutePath()
const {
return _isAbsolute; }
179 bool IsAbsoluteRoot()
const {
return (_isAbsolute) & (!_elementCount); }
180 bool ContainsTargetPath()
const {
return _containsTargetPath; }
181 bool IsNamespaced()
const {
182 return (_nodeType == PrimPropertyNode ||
183 _nodeType == RelationalAttributeNode) && _IsNamespacedImpl();
186 bool ContainsPrimVariantSelection()
const {
187 return _containsPrimVariantSelection;
194 inline const TfToken &GetName()
const;
198 inline const SdfPath &GetTargetPath()
const;
200 typedef std::pair<TfToken, TfToken> VariantSelectionType;
201 inline const VariantSelectionType& GetVariantSelection()
const;
205 inline TfToken GetElement()
const;
209 GetPathToken(Sdf_PathNode
const *primPart, Sdf_PathNode
const *propPart);
213 GetPathAsToken(Sdf_PathNode
const *primPart, Sdf_PathNode
const *propPart);
216 GetDebugText(Sdf_PathNode
const *primPart, Sdf_PathNode
const *propPart);
221 inline bool operator()(T
const &a, T
const &b)
const {
228 template <
class Less>
229 inline bool Compare(
const Sdf_PathNode &rhs)
const;
233 unsigned int GetCurrentRefCount()
const {
return _refCount; }
236 Sdf_PathNode(Sdf_PathNode
const *parent, NodeType nodeType)
239 , _elementCount(parent ? parent->_elementCount + 1 : 1)
240 , _nodeType(nodeType)
241 , _isAbsolute(parent && parent->IsAbsolutePath())
242 , _containsPrimVariantSelection(
243 nodeType == PrimVariantSelectionNode ||
244 (parent && parent->_containsPrimVariantSelection))
245 , _containsTargetPath(nodeType == TargetNode ||
246 nodeType == MapperNode ||
247 (parent && parent->_containsTargetPath))
252 explicit Sdf_PathNode(
bool isAbsolute);
256 _RemovePathTokenFromTable();
262 inline void _Destroy()
const;
264 TfToken _GetElementImpl()
const;
267 static TfToken _CreatePathToken(Sdf_PathNode
const *primPart,
268 Sdf_PathNode
const *propPart);
270 template <
class Buffer>
271 static void _WriteTextToBuffer(Sdf_PathNode
const *primPart,
272 Sdf_PathNode
const *propPart,
275 template <
class Buffer>
276 static void _WriteTextToBuffer(
SdfPath const &path, Buffer &out);
279 template <
class Buffer>
280 void _WriteText(Buffer &out)
const;
283 SDF_API
void _RemovePathTokenFromTable()
const;
285 struct _EqualElement {
287 inline bool operator()(T
const &a, T
const &b)
const {
292 friend struct Sdf_PathNodePrivateAccess;
295 friend void intrusive_ptr_add_ref(
const Sdf_PathNode*);
296 friend void intrusive_ptr_release(
const Sdf_PathNode*);
300 template <
class Derived>
301 Derived
const *_Downcast()
const {
302 return static_cast<Derived const *>(
this);
306 bool _IsNamespacedImpl()
const;
309 VariantSelectionType
const &_GetEmptyVariantSelection()
const;
313 const Sdf_PathNodeConstRefPtr _parent;
314 mutable tbb::atomic<unsigned int> _refCount;
316 const short _elementCount;
317 const unsigned char _nodeType;
318 const bool _isAbsolute:1;
319 const bool _containsPrimVariantSelection:1;
320 const bool _containsTargetPath:1;
330 mutable bool _hasToken:1;
333 class Sdf_PrimPartPathNode :
public Sdf_PathNode {
335 using Sdf_PathNode::Sdf_PathNode;
336 SDF_API
void operator delete (
void *p);
339 class Sdf_PropPartPathNode :
public Sdf_PathNode {
341 using Sdf_PathNode::Sdf_PathNode;
342 SDF_API
void operator delete (
void *p);
345 class Sdf_RootPathNode :
public Sdf_PrimPartPathNode {
347 typedef bool ComparisonType;
348 static const NodeType nodeType = Sdf_PathNode::RootNode;
350 static SDF_API Sdf_PathNode
const *New(
bool isAbsolute);
354 Sdf_RootPathNode(
bool isAbsolute) : Sdf_PrimPartPathNode(isAbsolute) {}
356 ComparisonType _GetComparisonValue()
const {
359 return !IsAbsolutePath();
362 friend class Sdf_PathNode;
363 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
366 class Sdf_PrimPathNode :
public Sdf_PrimPartPathNode {
368 typedef TfToken ComparisonType;
369 static const NodeType nodeType = Sdf_PathNode::PrimNode;
372 Sdf_PrimPathNode(Sdf_PathNode
const *parent,
374 : Sdf_PrimPartPathNode(parent, nodeType)
377 SDF_API ~Sdf_PrimPathNode();
379 const ComparisonType &_GetComparisonValue()
const {
return _name; }
381 friend class Sdf_PathNode;
382 friend struct Sdf_PathNodePrivateAccess;
383 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
389 class Sdf_PrimPropertyPathNode :
public Sdf_PropPartPathNode {
391 typedef TfToken ComparisonType;
392 static const NodeType nodeType = Sdf_PathNode::PrimPropertyNode;
395 Sdf_PrimPropertyPathNode(Sdf_PathNode
const *parent,
397 : Sdf_PropPartPathNode(parent, nodeType)
400 SDF_API ~Sdf_PrimPropertyPathNode();
402 friend class Sdf_PathNode;
403 friend struct Sdf_PathNodePrivateAccess;
404 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
406 const ComparisonType &_GetComparisonValue()
const {
return _name; }
412 class Sdf_PrimVariantSelectionNode :
public Sdf_PrimPartPathNode {
414 typedef VariantSelectionType ComparisonType;
415 static const NodeType nodeType = Sdf_PathNode::PrimVariantSelectionNode;
417 const TfToken &_GetNameImpl()
const;
419 template <
class Buffer>
420 void _WriteTextImpl(Buffer &out)
const;
423 Sdf_PrimVariantSelectionNode(Sdf_PathNode
const *parent,
424 const VariantSelectionType &variantSelection)
425 : Sdf_PrimPartPathNode(parent, nodeType)
426 , _variantSelection(new VariantSelectionType(variantSelection)) {}
428 SDF_API ~Sdf_PrimVariantSelectionNode();
430 const ComparisonType &_GetComparisonValue()
const {
431 return *_variantSelection;
434 friend class Sdf_PathNode;
435 friend struct Sdf_PathNodePrivateAccess;
436 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
439 std::unique_ptr<VariantSelectionType> _variantSelection;
442 class Sdf_TargetPathNode :
public Sdf_PropPartPathNode {
444 typedef SdfPath ComparisonType;
445 static const NodeType nodeType = Sdf_PathNode::TargetNode;
447 template <
class Buffer>
448 void _WriteTextImpl(Buffer &out)
const;
451 Sdf_TargetPathNode(Sdf_PathNode
const *parent,
453 : Sdf_PropPartPathNode(parent, nodeType)
454 , _targetPath(targetPath) {}
456 SDF_API ~Sdf_TargetPathNode();
458 const ComparisonType& _GetComparisonValue()
const {
return _targetPath; }
460 friend class Sdf_PathNode;
461 friend struct Sdf_PathNodePrivateAccess;
462 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
468 class Sdf_RelationalAttributePathNode :
public Sdf_PropPartPathNode {
470 typedef TfToken ComparisonType;
471 static const NodeType nodeType = Sdf_PathNode::RelationalAttributeNode;
474 Sdf_RelationalAttributePathNode(Sdf_PathNode
const *parent,
476 : Sdf_PropPartPathNode(parent, nodeType)
479 SDF_API ~Sdf_RelationalAttributePathNode();
481 const ComparisonType& _GetComparisonValue()
const {
return _name; }
483 friend class Sdf_PathNode;
484 friend struct Sdf_PathNodePrivateAccess;
485 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
491 class Sdf_MapperPathNode :
public Sdf_PropPartPathNode {
493 typedef SdfPath ComparisonType;
494 static const NodeType nodeType = Sdf_PathNode::MapperNode;
496 template <
class Buffer>
497 void _WriteTextImpl(Buffer &out)
const;
500 Sdf_MapperPathNode(Sdf_PathNode
const *parent,
502 : Sdf_PropPartPathNode(parent, nodeType)
503 , _targetPath(targetPath) {}
505 SDF_API ~Sdf_MapperPathNode();
507 const ComparisonType& _GetComparisonValue()
const {
return _targetPath; }
509 friend class Sdf_PathNode;
510 friend struct Sdf_PathNodePrivateAccess;
511 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
517 class Sdf_MapperArgPathNode :
public Sdf_PropPartPathNode {
519 typedef TfToken ComparisonType;
520 static const NodeType nodeType = Sdf_PathNode::MapperArgNode;
522 template <
class Buffer>
523 void _WriteTextImpl(Buffer &out)
const;
526 Sdf_MapperArgPathNode(Sdf_PathNode
const *parent,
528 : Sdf_PropPartPathNode(parent, nodeType)
531 SDF_API ~Sdf_MapperArgPathNode();
533 const ComparisonType& _GetComparisonValue()
const {
return _name; }
535 friend class Sdf_PathNode;
536 friend struct Sdf_PathNodePrivateAccess;
537 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
543 class Sdf_ExpressionPathNode :
public Sdf_PropPartPathNode {
545 typedef void *ComparisonType;
546 static const NodeType nodeType = Sdf_PathNode::ExpressionNode;
548 template <
class Buffer>
549 void _WriteTextImpl(Buffer &out)
const;
552 Sdf_ExpressionPathNode(Sdf_PathNode
const *parent)
553 : Sdf_PropPartPathNode(parent, nodeType) {}
555 SDF_API ~Sdf_ExpressionPathNode();
557 ComparisonType _GetComparisonValue()
const {
return nullptr; }
559 friend class Sdf_PathNode;
560 friend struct Sdf_PathNodePrivateAccess;
561 template <
int nodeType,
class Comp>
friend struct Sdf_PathNodeCompare;
567 template <
int nodeType>
568 struct Sdf_PathNodeTypeToType {
570 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimNode> {
571 typedef Sdf_PrimPathNode Type;
573 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimPropertyNode> {
574 typedef Sdf_PrimPropertyPathNode Type;
576 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::RelationalAttributeNode> {
577 typedef Sdf_RelationalAttributePathNode Type;
579 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperArgNode> {
580 typedef Sdf_MapperArgPathNode Type;
582 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::TargetNode> {
583 typedef Sdf_TargetPathNode Type;
585 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::MapperNode> {
586 typedef Sdf_MapperPathNode Type;
588 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::PrimVariantSelectionNode> {
589 typedef Sdf_PrimVariantSelectionNode Type;
591 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::ExpressionNode> {
592 typedef Sdf_ExpressionPathNode Type;
594 template <>
struct Sdf_PathNodeTypeToType<Sdf_PathNode::RootNode> {
595 typedef Sdf_RootPathNode Type;
598 template <
int nodeType,
class Comp>
599 struct Sdf_PathNodeCompare {
600 inline bool operator()(
const Sdf_PathNode &lhs,
601 const Sdf_PathNode &rhs)
const {
602 typedef typename Sdf_PathNodeTypeToType<nodeType>::Type Type;
603 return Comp()(static_cast<const Type&>(lhs)._GetComparisonValue(),
604 static_cast<const Type&>(rhs)._GetComparisonValue());
608 template <
class Comp>
610 Sdf_PathNode::Compare(
const Sdf_PathNode &rhs)
const 620 NodeType nodeType = GetNodeType(), rhsNodeType = rhs.GetNodeType();
621 if (nodeType != rhsNodeType) {
622 return Comp()(nodeType, rhsNodeType);
627 case Sdf_PathNode::PrimNode:
628 return Sdf_PathNodeCompare<Sdf_PathNode::PrimNode,
630 case Sdf_PathNode::PrimPropertyNode:
631 return Sdf_PathNodeCompare<Sdf_PathNode::PrimPropertyNode,
633 case Sdf_PathNode::RelationalAttributeNode:
634 return Sdf_PathNodeCompare<Sdf_PathNode::RelationalAttributeNode,
636 case Sdf_PathNode::MapperArgNode:
637 return Sdf_PathNodeCompare<Sdf_PathNode::MapperArgNode,
639 case Sdf_PathNode::TargetNode:
640 return Sdf_PathNodeCompare<Sdf_PathNode::TargetNode,
642 case Sdf_PathNode::MapperNode:
643 return Sdf_PathNodeCompare<Sdf_PathNode::MapperNode,
645 case Sdf_PathNode::PrimVariantSelectionNode:
646 return Sdf_PathNodeCompare<Sdf_PathNode::PrimVariantSelectionNode,
648 case Sdf_PathNode::ExpressionNode:
649 return Sdf_PathNodeCompare<Sdf_PathNode::ExpressionNode,
651 case Sdf_PathNode::RootNode:
652 return Sdf_PathNodeCompare<Sdf_PathNode::RootNode,
661 Sdf_PathNode::_Destroy()
const 666 return delete _Downcast<Sdf_RootPathNode>();
668 return delete _Downcast<Sdf_PrimPathNode>();
669 case PrimPropertyNode:
670 return delete _Downcast<Sdf_PrimPropertyPathNode>();
671 case PrimVariantSelectionNode:
672 return delete _Downcast<Sdf_PrimVariantSelectionNode>();
674 return delete _Downcast<Sdf_TargetPathNode>();
675 case RelationalAttributeNode:
676 return delete _Downcast<Sdf_RelationalAttributePathNode>();
678 return delete _Downcast<Sdf_MapperPathNode>();
680 return delete _Downcast<Sdf_MapperArgPathNode>();
682 return delete _Downcast<Sdf_ExpressionPathNode>();
689 Sdf_PathNode::GetName()
const 693 return SdfPathTokens->empty;
695 return IsAbsolutePath() ?
696 SdfPathTokens->absoluteIndicator : SdfPathTokens->relativeRoot;
698 return _Downcast<Sdf_PrimPathNode>()->_name;
699 case PrimPropertyNode:
700 return _Downcast<Sdf_PrimPropertyPathNode>()->_name;
701 case PrimVariantSelectionNode:
702 return _Downcast<Sdf_PrimVariantSelectionNode>()->_GetNameImpl();
703 case RelationalAttributeNode:
704 return _Downcast<Sdf_RelationalAttributePathNode>()->_name;
706 return _Downcast<Sdf_MapperArgPathNode>()->_name;
708 return SdfPathTokens->expressionIndicator;
713 Sdf_PathNode::GetTargetPath()
const 719 return _Downcast<Sdf_TargetPathNode>()->_targetPath;
721 return _Downcast<Sdf_MapperPathNode>()->_targetPath;
725 inline const Sdf_PathNode::VariantSelectionType &
726 Sdf_PathNode::GetVariantSelection()
const 728 if (ARCH_LIKELY(_nodeType == PrimVariantSelectionNode)) {
729 return *_Downcast<Sdf_PrimVariantSelectionNode>()->_variantSelection;
731 return _GetEmptyVariantSelection();
735 Sdf_PathNode::GetElement()
const 741 return _Downcast<Sdf_PrimPathNode>()->_name;
743 return _GetElementImpl();
748 SDF_API
void Sdf_DumpPathStats();
750 inline void intrusive_ptr_add_ref(
const PXR_NS::Sdf_PathNode* p) {
753 inline void intrusive_ptr_release(
const PXR_NS::Sdf_PathNode* p) {
754 if (p->_refCount.fetch_and_decrement() == 1)
758 PXR_NAMESPACE_CLOSE_SCOPE
760 #endif // PXR_USD_SDF_PATH_NODE_H #define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
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...