7 #ifndef PXR_USD_SDF_PATH_H
8 #define PXR_USD_SDF_PATH_H
25 #include <type_traits>
45 struct Sdf_PathPrimTag;
46 struct Sdf_PathPropTag;
49 static constexpr
size_t Sdf_SizeofPrimPathNode = sizeof(
void *) * 3;
50 static constexpr
size_t Sdf_SizeofPropPathNode = sizeof(
void *) * 3;
53 Sdf_PathPrimTag, Sdf_SizeofPrimPathNode, 8>;
56 Sdf_PathPropTag, Sdf_SizeofPropPathNode, 8>;
68 static constexpr
bool IsCounted = Counted;
74 : _poolHandle(Handle::GetHandle(reinterpret_cast<char const *>(p))) {
89 : _poolHandle(rhs._poolHandle) {
101 Sdf_PathNodeHandleImpl &
103 if (Counted && *
this == rhs) {
106 this_type(rhs).
swap(*
this);
111 : _poolHandle(rhs._poolHandle) {
112 rhs._poolHandle =
nullptr;
115 Sdf_PathNodeHandleImpl &
117 this_type(std::move(rhs)).
swap(*
this);
121 Sdf_PathNodeHandleImpl &
123 this_type(rhs).
swap(*
this);
128 _poolHandle = Handle {
nullptr };
132 get()
const noexcept {
133 return reinterpret_cast<Sdf_PathNode *
>(_poolHandle.GetPtr());
146 explicit operator bool() const noexcept {
147 return static_cast<bool>(_poolHandle);
150 void swap(Sdf_PathNodeHandleImpl &rhs) noexcept {
151 _poolHandle.swap(rhs._poolHandle);
154 inline bool operator==(Sdf_PathNodeHandleImpl
const &rhs)
const noexcept {
155 return _poolHandle == rhs._poolHandle;
157 inline bool operator!=(Sdf_PathNodeHandleImpl
const &rhs)
const noexcept {
158 return _poolHandle != rhs._poolHandle;
160 inline bool operator<(Sdf_PathNodeHandleImpl
const &rhs)
const noexcept {
161 return _poolHandle < rhs._poolHandle;
171 inline void _AddRef()
const {
175 inline void _DecRef()
const {
181 Handle _poolHandle {
nullptr };
372 return static_cast<bool>(_propPart);
694 const std::string &variant)
const;
757 const SdfPath &newPrefix,
758 bool fixTargetPaths=
true)
const;
780 std::pair<SdfPath, SdfPath>
782 bool stopAtRootPrim =
false)
const;
836 static std::string
JoinIdentifier(
const std::vector<std::string> &names);
849 const std::string &rhs);
879 static std::pair<std::string, bool>
881 const std::string &matchNamespace);
889 std::string *errMsg = 0);
898 return _AsInt() == rhs._AsInt();
903 return !(*
this == rhs);
911 if (_AsInt() == rhs._AsInt()) {
914 if (!_primPart || !rhs._primPart) {
915 return !_primPart && rhs._primPart;
918 return _LessThanInternal(*
this, rhs);
930 return !(rhs < *
this);
936 return !(*
this < rhs);
939 template <
class HashState>
943 uint32_t primPart, propPart;
944 memcpy(&primPart, &path._primPart,
sizeof(primPart));
945 memcpy(&propPart, &path._propPart,
sizeof(propPart));
958 return Hash()(*this);
965 return a._AsInt() < b._AsInt();
1002 : _primPart(std::move(primNode)) {}
1006 : _primPart(std::move(primPart))
1007 , _propPart(std::move(propPart)) {}
1012 : _primPart(primPart)
1013 , _propPart(propPart) {}
1018 : _primPart(primPart)
1019 , _propPart(propPart) {}
1025 SdfPath _ReplacePrimPrefix(SdfPath
const &oldPrefix,
1026 SdfPath
const &newPrefix)
const;
1028 SdfPath _ReplaceTargetPathPrefixes(SdfPath
const &oldPrefix,
1029 SdfPath
const &newPrefix)
const;
1031 SdfPath _ReplacePropPrefix(SdfPath
const &oldPrefix,
1032 SdfPath
const &newPrefix,
1033 bool fixTargetPaths)
const;
1037 _LessThanInternal(SdfPath
const &lhs, SdfPath
const &rhs);
1039 inline uint64_t _AsInt()
const {
1040 static_assert(
sizeof(*
this) ==
sizeof(uint64_t),
"");
1042 std::memcpy(&ret,
this,
sizeof(*
this));
1046 friend void swap(SdfPath &lhs, SdfPath &rhs) {
1047 lhs._primPart.
swap(rhs._primPart);
1048 lhs._propPart.
swap(rhs._propPart);
1149 template <
class ForwardIterator,
class GetPathFn = Sdf_PathIdentity>
1150 std::pair<ForwardIterator, ForwardIterator>
1152 SdfPath
const &prefix,
1153 GetPathFn
const &getPath = GetPathFn()) {
1158 Compare(GetPathFn
const &getPath) : _getPath(getPath) {}
1159 GetPathFn
const &_getPath;
1160 bool operator()(IterRef
a, SdfPath
const &
b)
const {
1161 return _getPath(a) <
b;
1165 std::pair<ForwardIterator, ForwardIterator>
result;
1168 result.first = std::lower_bound(begin, end, prefix, Compare(getPath));
1172 result.second = TfFindBoundary(result.first, end,
1173 [&prefix, &getPath](IterRef iterRef) {
1174 return getPath(iterRef).HasPrefix(prefix);
1180 template <
class RandomAccessIterator,
class GetPathFn>
1181 RandomAccessIterator
1183 RandomAccessIterator
end,
1184 SdfPath
const &path,
1186 GetPathFn
const &getPath)
1192 Compare(GetPathFn
const &getPath) : _getPath(getPath) {}
1193 GetPathFn
const &_getPath;
1194 bool operator()(IterRef
a, SdfPath
const &
b)
const {
1195 return _getPath(a) <
b;
1208 Compare comp(getPath);
1211 RandomAccessIterator
result = std::lower_bound(begin, end, path, comp);
1215 if (!strictPrefix && result != end && getPath(*result) == path) {
1221 if (result == begin) {
1226 if (path.
HasPrefix(getPath(*--result))) {
1236 result = std::lower_bound(begin, end, newPath, comp);
1238 if (result != end && getPath(*result) == newPath) {
1241 if (result == begin) {
1244 if (newPath.
HasPrefix(getPath(*--result))) {
1259 class =
typename std::enable_if<
1261 std::random_access_iterator_tag,
1262 typename std::iterator_traits<
1263 RandomAccessIterator>::iterator_category
1267 RandomAccessIterator
1269 RandomAccessIterator
end,
1270 SdfPath
const &path,
1271 GetPathFn
const &getPath = GetPathFn())
1274 begin, end, path,
false, getPath);
1285 class =
typename std::enable_if<
1287 std::random_access_iterator_tag,
1288 typename std::iterator_traits<
1289 RandomAccessIterator>::iterator_category
1293 RandomAccessIterator
1295 RandomAccessIterator end,
1296 SdfPath
const &path,
1297 GetPathFn
const &getPath = GetPathFn())
1300 begin, end, path,
true, getPath);
1303 template <
class Iter,
class MapParam,
class GetPathFn = Sdf_PathIdentity>
1306 MapParam map, SdfPath
const &path,
bool strictPrefix,
1307 GetPathFn
const &getPath = GetPathFn())
1314 const Iter mapEnd = map.end();
1321 Iter
result = map.lower_bound(path);
1325 if (!strictPrefix && result != mapEnd && getPath(*result) == path)
1330 if (result == map.begin())
1341 return Sdf_PathFindLongestPrefixImpl<Iter, MapParam>(
1350 typename std::set<SdfPath>::const_iterator
1357 typename std::map<SdfPath, T>::const_iterator
1361 typename std::map<SdfPath, T>::const_iterator,
1362 std::map<SdfPath, T>
const &>(map,
path,
false,
1366 typename std::map<SdfPath, T>::iterator
1370 typename std::map<SdfPath, T>::iterator,
1371 std::map<SdfPath, T> &>(map,
path,
false,
1379 typename std::set<SdfPath>::const_iterator
1381 SdfPath
const &path);
1387 typename std::map<SdfPath, T>::const_iterator
1389 std::map<SdfPath, T>
const &map, SdfPath
const &path)
1392 typename std::map<SdfPath, T>::const_iterator,
1393 std::map<SdfPath, T>
const &>(map,
path,
true,
1397 typename std::map<SdfPath, T>::iterator
1399 std::map<SdfPath, T> &map, SdfPath
const &path)
1402 typename std::map<SdfPath, T>::iterator,
1403 std::map<SdfPath, T> &>(map,
path,
true,
1430 #endif // PXR_USD_SDF_PATH_H
SDF_API const char * GetText() const
SDF_API bool IsPrimOrPrimVariantSelectionPath() const
SDF_API SdfPath AppendTarget(const SdfPath &targetPath) const
SDF_API bool IsMapperPath() const
Returns whether the path identifies a connection mapper.
friend void swap(SdfPath &lhs, SdfPath &rhs)
SDF_API iterator & operator++()
SDF_API const std::string & GetName() const
static SDF_API const SdfPath & AbsoluteRootPath()
friend class Sdfext_PathAccess
Sdf_PathNodeHandleImpl(Sdf_PathNodeHandleImpl const &rhs) noexcept
SDF_API std::string GetElementString() const
SDF_API bool IsExpressionPath() const
Returns whether the path identifies a connection expression.
SDF_API SdfPath AppendExpression() const
iterator(const SdfPath &path)
Sdf_PathNodeHandleImpl(Handle h, bool add_ref=true)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const
STATIC_INLINE size_t Hash(const char *s, size_t len)
SDF_API char const * Sdf_PathGetDebuggerPathText(SdfPath const &)
bool operator==(const SdfPath &rhs) const
Equality operator.
Sdf_PathPropPartPool::Handle Sdf_PathPropHandle
SDF_API SdfPath ReplaceTargetPath(const SdfPath &newTargetPath) const
std::pair< ForwardIterator, ForwardIterator > SdfPathFindPrefixedRange(ForwardIterator begin, ForwardIterator end, SdfPath const &prefix, GetPathFn const &getPath=GetPathFn())
static SDF_API bool IsValidPathString(const std::string &pathString, std::string *errMsg=0)
GLsizei const GLfloat * value
RandomAccessIterator Sdf_PathFindLongestPrefixImpl(RandomAccessIterator begin, RandomAccessIterator end, SdfPath const &path, bool strictPrefix, GetPathFn const &getPath)
SDF_API bool IsAbsoluteRootPath() const
Return true if this path is the AbsoluteRootPath().
GLsizei const GLchar *const * path
SDF_API bool IsMapperArgPath() const
Returns whether the path identifies a connection mapper arg.
void TfDelegatedCountIncrement(Sdf_PathNode const *) noexcept
SDF_API const SdfPath & GetTargetPath() const
SDF_API bool IsPrimPropertyPath() const
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
SdfPathAncestorsRange(const SdfPath &path)
SDF_API TfToken GetAsToken() const
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNodeHandleImpl &&rhs) noexcept
bool operator==(const iterator &o) const
GLboolean GLboolean GLboolean GLboolean a
static SDF_API void RemoveDescendentPaths(SdfPathVector *paths)
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
bool operator==(Sdf_PathNodeHandleImpl const &rhs) const noexcept
**But if you need a result
Sdf_PathNodeHandleImpl(Sdf_PathNode const *p, bool add_ref=true)
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
SdfPath const & operator()(SdfPath const &arg) const
size_t GetHash() const
Equality operator.
SDF_API std::pair< std::string, std::string > GetVariantSelection() const
SDF_API SdfPath StripAllVariantSelections() const
bool operator!=(const iterator &o) const
SDF_API SdfPath AppendRelationalAttribute(TfToken const &attrName) const
static SDF_API std::vector< std::string > TokenizeIdentifier(const std::string &name)
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
const SdfPath & operator*() const
GLint GLint GLsizei GLint GLenum GLenum type
bool operator<(const SdfPath &rhs) const
void swap(Sdf_PathNodeHandleImpl &rhs) noexcept
friend void TfHashAppend(HashState &h, SdfPath const &path)
Equality operator.
SDF_API void GetAllTargetPathsRecursively(SdfPathVector *result) const
bool ContainsPropertyElements() const
SDF_API bool IsPrimVariantSelectionPath() const
bool operator!=(Sdf_PathNodeHandleImpl const &rhs) const noexcept
~Sdf_PathNodeHandleImpl()
SDF_API SdfPath AppendChild(TfToken const &childName) const
constexpr auto set(type rhs) -> int
static SDF_API bool IsValidNamespacedIdentifier(const std::string &name)
Sdf_PathNode const & operator*() const
bool operator>=(const SdfPath &rhs) const
SDF_API SdfPath AppendVariantSelection(const std::string &variantSet, const std::string &variant) const
SDF_API SdfPath AppendMapperArg(TfToken const &argName) const
SDF_API bool IsAbsolutePath() const
Returns whether the path is absolute.
static SDF_API std::string JoinIdentifier(const std::vector< std::string > &names)
std::vector< TfToken > TfTokenVector
Convenience types.
SDF_API bool ContainsTargetPath() const
static SDF_API bool IsValidIdentifier(const std::string &name)
SdfPath() noexcept=default
SDF_API size_t GetPathElementCount() const
Returns the number of path elements in this path.
GLuint const GLchar * name
SDF_API TfToken GetElementToken() const
Like GetElementString() but return the value as a TfToken.
SDF_API const std::string & GetString() const
SDF_API bool IsPrimPath() const
Returns whether the path identifies a prim.
GLboolean GLboolean GLboolean b
size_t operator()(const SdfPath &path) const
Sdf_PathPrimPartPool::Handle Sdf_PathPrimHandle
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNode const *rhs) noexcept
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
constexpr Sdf_PathNodeHandleImpl() noexcept
SDF_API const TfToken & GetNameToken() const
SDF_API bool HasPrefix(const SdfPath &prefix) const
SDF_API bool IsRelationalAttributePath() const
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
SDF_API SdfPath AppendProperty(TfToken const &propName) const
SDF_API bool ContainsPrimVariantSelection() const
__hostdev__ uint64_t last(uint32_t i) const
std::forward_iterator_tag iterator_category
GLfloat GLfloat GLfloat GLfloat h
bool operator<(Sdf_PathNodeHandleImpl const &rhs) const noexcept
SDF_API std::ostream & operator<<(std::ostream &out, const SdfPath &path)
Writes the string representation of path to out.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
const SdfPath * operator->() const
SDF_API SdfPathAncestorsRange GetAncestorsRange() const
SDF_API SdfPath GetCommonPrefix(const SdfPath &path) const
SDF_API TfToken const & GetToken() const
SDF_API bool IsTargetPath() const
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNodeHandleImpl const &rhs)
SDF_API std::pair< SdfPath, SdfPath > RemoveCommonSuffix(const SdfPath &otherPath, bool stopAtRootPrim=false) const
size_t hash_value(SdfPath const &path)
SDF_API bool IsRootPrimPath() const
SDF_API SdfPath AppendPath(const SdfPath &newSuffix) const
SDF_API std::string GetAsString() const
const SdfPath & GetPath() const
SDF_API SdfPath MakeAbsolutePath(const SdfPath &anchor) const
#define PXR_NAMESPACE_CLOSE_SCOPE
SDF_API bool IsNamespacedPropertyPath() const
SDF_API SdfPath AppendElementToken(const TfToken &elementTok) const
Like AppendElementString() but take the element as a TfToken.
SDF_API SdfPath GetParentPath() const
static SDF_API SdfPathVector GetConciseRelativePaths(const SdfPathVector &paths)
SDF_API SdfPath GetPrimOrPrimVariantSelectionPath() const
SDF_API bool IsPropertyPath() const
static SDF_API std::pair< std::string, bool > StripPrefixNamespace(const std::string &name, const std::string &matchNamespace)
SDF_API friend char const * Sdf_PathGetDebuggerPathText(SdfPath const &)
SDF_API friend difference_type distance(const iterator &first, const iterator &last)
RandomAccessIterator SdfPathFindLongestPrefix(RandomAccessIterator begin, RandomAccessIterator end, SdfPath const &path, GetPathFn const &getPath=GetPathFn())
static SDF_API void RemoveAncestorPaths(SdfPathVector *paths)
SDF_API bool IsAbsoluteRootOrPrimPath() const
Returns whether the path identifies a prim or the absolute root.
RandomAccessIterator SdfPathFindLongestStrictPrefix(RandomAccessIterator begin, RandomAccessIterator end, SdfPath const &path, GetPathFn const &getPath=GetPathFn())
Sdf_PathNode const * operator->() const
bool operator!=(const SdfPath &rhs) const
Inequality operator.
Sdf_PathNodeHandleImpl(Sdf_PathNodeHandleImpl &&rhs) noexcept
SDF_API SdfPathVector GetPrefixes() const
static SDF_API std::string StripNamespace(const std::string &name)
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
SDF_API SdfPath ReplaceName(TfToken const &newName) const
bool operator<=(const SdfPath &rhs) const
static SDF_API const SdfPath & ReflexiveRelativePath()
The relative path representing "self".
bool operator>(const SdfPath &rhs) const
SDF_API SdfPath AppendElementString(const std::string &element) const
bool operator()(const SdfPath &a, const SdfPath &b) const
VT_TYPE_IS_CHEAP_TO_COPY(class SdfPath)
std::ptrdiff_t difference_type
void TfDelegatedCountDecrement(Sdf_PathNode const *) noexcept
SDF_API SdfPath MakeRelativePath(const SdfPath &anchor) const
SDF_API SdfPath ReplacePrefix(const SdfPath &oldPrefix, const SdfPath &newPrefix, bool fixTargetPaths=true) const
SDF_API SdfPath GetPrimPath() const
static SDF_API TfTokenVector TokenizeIdentifierAsTokens(const std::string &name)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.