24 #ifndef PXR_USD_SDF_PATH_H
25 #define PXR_USD_SDF_PATH_H
35 #include <hboost/intrusive_ptr.hpp>
36 #include <hboost/operators.hpp>
42 #include <type_traits>
62 struct Sdf_PathPrimTag;
63 struct Sdf_PathPropTag;
66 static constexpr
size_t Sdf_SizeofPrimPathNode =
sizeof(
void *) * 3;
67 static constexpr
size_t Sdf_SizeofPropPathNode =
sizeof(
void *) * 3;
70 Sdf_PathPrimTag, Sdf_SizeofPrimPathNode, 8>;
73 Sdf_PathPropTag, Sdf_SizeofPropPathNode, 8>;
79 template <
class Handle,
bool Counted,
class PathNode=Sdf_PathNode const>
89 : _poolHandle(
Handle::GetHandle(reinterpret_cast<char
const *>(p))) {
104 : _poolHandle(rhs._poolHandle) {
118 if (Counted && *
this == rhs) {
126 : _poolHandle(rhs._poolHandle) {
127 rhs._poolHandle =
nullptr;
143 _poolHandle =
Handle {
nullptr };
147 get()
const noexcept {
148 return reinterpret_cast<Sdf_PathNode *
>(_poolHandle.GetPtr());
161 explicit operator bool()
const noexcept {
162 return static_cast<bool>(_poolHandle);
166 _poolHandle.swap(rhs._poolHandle);
170 return _poolHandle == rhs._poolHandle;
173 return _poolHandle != rhs._poolHandle;
176 return _poolHandle < rhs._poolHandle;
186 void _AddRef()
const {
190 void _DecRef()
const {
196 Handle _poolHandle {
nullptr };
288 class SdfPath : hboost::totally_ordered<SdfPath>
309 memset(
this, 0,
sizeof(*
this));
391 return static_cast<bool>(_propPart);
743 bool fixTargetPaths=
true)
const;
765 std::pair<SdfPath, SdfPath>
767 bool stopAtRootPrim =
false)
const;
864 static std::pair<std::string, bool>
884 return _AsInt() == rhs._AsInt();
892 if (_AsInt() == rhs._AsInt()) {
895 if (!_primPart || !rhs._primPart) {
896 return !_primPart && rhs._primPart;
899 return _LessThanInternal(*
this, rhs);
902 template <
class HashState>
906 uint32_t primPart, propPart;
907 memcpy(&primPart, &path._primPart,
sizeof(primPart));
908 memcpy(&propPart, &path._propPart,
sizeof(propPart));
921 return Hash()(*this);
928 return a._AsInt() < b._AsInt();
965 : _primPart(std::move(primNode)) {}
970 : _primPart(primPart)
971 , _propPart(propPart) {}
976 : _primPart(primPart)
977 , _propPart(propPart) {}
985 _ElementsToString(
bool absolute,
const std::vector<std::string> &elements);
988 SdfPath const &newPrefix)
const;
991 SdfPath const &newPrefix)
const;
995 bool fixTargetPaths)
const;
1001 inline uint64_t _AsInt()
const {
1002 static_assert(
sizeof(*
this) ==
sizeof(uint64_t),
"");
1004 std::memcpy(&ret,
this,
sizeof(*
this));
1009 lhs._primPart.
swap(rhs._primPart);
1010 lhs._propPart.
swap(rhs._propPart);
1108 template <
class ForwardIterator,
class GetPathFn = Sdf_PathIdentity>
1109 std::pair<ForwardIterator, ForwardIterator>
1112 GetPathFn
const &getPath = GetPathFn()) {
1117 Compare(GetPathFn
const &getPath) : _getPath(getPath) {}
1118 GetPathFn
const &_getPath;
1119 bool operator()(IterRef
a,
SdfPath const &
b)
const {
1120 return _getPath(a) <
b;
1124 std::pair<ForwardIterator, ForwardIterator>
result;
1127 result.first = std::lower_bound(begin, end, prefix, Compare(getPath));
1131 result.second = TfFindBoundary(result.first, end,
1132 [&prefix, &getPath](IterRef iterRef) {
1133 return getPath(iterRef).HasPrefix(prefix);
1139 template <
class RandomAccessIterator,
class GetPathFn>
1140 RandomAccessIterator
1142 RandomAccessIterator
end,
1145 GetPathFn
const &getPath)
1151 Compare(GetPathFn
const &getPath) : _getPath(getPath) {}
1152 GetPathFn
const &_getPath;
1153 bool operator()(IterRef
a,
SdfPath const &
b)
const {
1154 return _getPath(a) <
b;
1167 Compare comp(getPath);
1170 RandomAccessIterator
result = std::lower_bound(begin, end, path, comp);
1174 if (!strictPrefix && result != end && getPath(*result) == path) {
1180 if (result == begin) {
1185 if (path.
HasPrefix(getPath(*--result))) {
1195 result = std::lower_bound(begin, end, newPath, comp);
1197 if (result != end && getPath(*result) == newPath) {
1200 if (result == begin) {
1203 if (newPath.
HasPrefix(getPath(*--result))) {
1218 class =
typename std::enable_if<
1220 std::random_access_iterator_tag,
1221 typename std::iterator_traits<
1222 RandomAccessIterator>::iterator_category
1226 RandomAccessIterator
1228 RandomAccessIterator
end,
1230 GetPathFn
const &getPath = GetPathFn())
1233 begin, end, path,
false, getPath);
1244 class =
typename std::enable_if<
1246 std::random_access_iterator_tag,
1247 typename std::iterator_traits<
1248 RandomAccessIterator>::iterator_category
1252 RandomAccessIterator
1254 RandomAccessIterator end,
1256 GetPathFn
const &getPath = GetPathFn())
1259 begin, end, path,
true, getPath);
1262 template <
class Iter,
class MapParam,
class GetPathFn = Sdf_PathIdentity>
1265 MapParam map,
SdfPath const &path,
bool strictPrefix,
1266 GetPathFn
const &getPath = GetPathFn())
1273 const Iter mapEnd = map.end();
1280 Iter
result = map.lower_bound(path);
1284 if (!strictPrefix && result != mapEnd && getPath(*result) == path)
1289 if (result == map.begin())
1300 return Sdf_PathFindLongestPrefixImpl<Iter, MapParam>(
1309 typename std::set<SdfPath>::const_iterator
1316 typename std::map<SdfPath, T>::const_iterator
1320 typename std::map<SdfPath, T>::const_iterator,
1321 std::map<SdfPath, T>
const &>(map,
path,
false,
1325 typename std::map<SdfPath, T>::iterator
1329 typename std::map<SdfPath, T>::iterator,
1330 std::map<SdfPath, T> &>(map,
path,
false,
1338 typename std::set<SdfPath>::const_iterator
1346 typename std::map<SdfPath, T>::const_iterator
1348 std::map<SdfPath, T>
const &map,
SdfPath const &path)
1351 typename std::map<SdfPath, T>::const_iterator,
1352 std::map<SdfPath, T>
const &>(map,
path,
true,
1356 typename std::map<SdfPath, T>::iterator
1358 std::map<SdfPath, T> &map,
SdfPath const &path)
1361 typename std::map<SdfPath, T>::iterator,
1362 std::map<SdfPath, T> &>(map,
path,
true,
1380 #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.
GLboolean GLboolean GLboolean b
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_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)
SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const
STATIC_INLINE size_t Hash(const char *s, size_t len)
bool operator==(const SdfPath &rhs) const
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)
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.
GLenum const void GLuint GLint reference
SDF_API const SdfPath & GetTargetPath() const
GLenum GLsizei const void * pathString
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
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
GLuint const GLchar * name
Sdf_PathNodeHandleImpl(Sdf_PathNode const *p, bool add_ref=true)
SdfPath const & operator()(SdfPath const &arg) const
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().
Sdf_PathNodeHandleImpl(Sdf_PathNodeHandleImpl const &rhs)
const SdfPath & operator*() const
bool operator<(const SdfPath &rhs) const
void swap(Sdf_PathNodeHandleImpl &rhs) noexcept
friend void TfHashAppend(HashState &h, SdfPath const &path)
GLint GLint GLsizei GLint GLenum GLenum type
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()
void intrusive_ptr_add_ref(Sdf_PathNode const *)
SDF_API SdfPath AppendChild(TfToken const &childName) const
static SDF_API bool IsValidNamespacedIdentifier(const std::string &name)
Sdf_PathNode const & operator*() const
GLboolean GLboolean GLboolean GLboolean a
GLsizei const GLchar *const * string
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.
GLuint const GLuint * names
SDF_API bool ContainsTargetPath() const
static SDF_API bool IsValidIdentifier(const std::string &name)
SDF_API size_t GetPathElementCount() const
Returns the number of path elements in this path.
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.
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.
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
SDF_API SdfPath AppendProperty(TfToken const &propName) const
SDF_API bool ContainsPrimVariantSelection() const
hboost::intrusive_ptr< const Sdf_PathNode > Sdf_PathNodeConstRefPtr
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
void intrusive_ptr_release(Sdf_PathNode 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.
GLsizei const GLfloat * value
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 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
Sdf_PathNodeHandleImpl(Sdf_PathNodeHandleImpl &&rhs) noexcept
SDF_API SdfPathVector GetPrefixes() const
static SDF_API std::string StripNamespace(const std::string &name)
SDF_API SdfPath ReplaceName(TfToken const &newName) const
static SDF_API const SdfPath & ReflexiveRelativePath()
The relative path representing "self".
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
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
GLenum const void * paths
static SDF_API TfTokenVector TokenizeIdentifierAsTokens(const std::string &name)