HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
path.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_SDF_PATH_H
25 #define PXR_USD_SDF_PATH_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/api.h"
29 #include "pxr/usd/sdf/pool.h"
30 #include "pxr/usd/sdf/tokens.h"
31 #include "pxr/base/tf/stl.h"
32 #include "pxr/base/tf/token.h"
33 #include "pxr/base/vt/traits.h"
34 
35 #include <hboost/intrusive_ptr.hpp>
36 #include <hboost/operators.hpp>
37 
38 #include <algorithm>
39 #include <iterator>
40 #include <set>
41 #include <string>
42 #include <type_traits>
43 #include <utility>
44 #include <vector>
45 
47 
48 class Sdf_PathNode;
50 
51 // Ref-counting pointer to a path node.
52 // Intrusive ref-counts are used to keep the size of SdfPath
53 // the same as a raw pointer. (shared_ptr, by comparison,
54 // is the size of two pointers.)
55 
56 typedef hboost::intrusive_ptr<const Sdf_PathNode> Sdf_PathNodeConstRefPtr;
57 
60 
61 // Tags used for the pools of path nodes.
62 struct Sdf_PathPrimTag;
63 struct Sdf_PathPropTag;
64 
65 // These are validated below.
66 static constexpr size_t Sdf_SizeofPrimPathNode = sizeof(void *) * 3;
67 static constexpr size_t Sdf_SizeofPropPathNode = sizeof(void *) * 3;
68 
70  Sdf_PathPrimTag, Sdf_SizeofPrimPathNode, /*regionBits=*/8>;
71 
73  Sdf_PathPropTag, Sdf_SizeofPropPathNode, /*regionBits=*/8>;
74 
77 
78 // This handle class wraps up the raw Prim/PropPartPool handles.
79 template <class Handle, bool Counted, class PathNode=Sdf_PathNode const>
81 private:
83 
84 public:
85  constexpr Sdf_PathNodeHandleImpl() noexcept {};
86 
87  explicit
88  Sdf_PathNodeHandleImpl(Sdf_PathNode const *p, bool add_ref = true)
89  : _poolHandle(Handle::GetHandle(reinterpret_cast<char const *>(p))) {
90  if (p && add_ref) {
91  _AddRef(p);
92  }
93  }
94 
95  explicit
96  Sdf_PathNodeHandleImpl(Handle h, bool add_ref = true)
97  : _poolHandle(h) {
98  if (h && add_ref) {
99  _AddRef();
100  }
101  }
102 
104  : _poolHandle(rhs._poolHandle) {
105  if (_poolHandle) {
106  _AddRef();
107  }
108  }
109 
111  if (_poolHandle) {
112  _DecRef();
113  }
114  }
115 
118  if (Counted && *this == rhs) {
119  return *this;
120  }
121  this_type(rhs).swap(*this);
122  return *this;
123  }
124 
126  : _poolHandle(rhs._poolHandle) {
127  rhs._poolHandle = nullptr;
128  }
129 
132  this_type(std::move(rhs)).swap(*this);
133  return *this;
134  }
135 
137  operator=(Sdf_PathNode const *rhs) noexcept {
138  this_type(rhs).swap(*this);
139  return *this;
140  }
141 
142  void reset() noexcept {
143  _poolHandle = Handle { nullptr };
144  }
145 
146  Sdf_PathNode const *
147  get() const noexcept {
148  return reinterpret_cast<Sdf_PathNode *>(_poolHandle.GetPtr());
149  }
150 
151  Sdf_PathNode const &
152  operator*() const {
153  return *get();
154  }
155 
156  Sdf_PathNode const *
157  operator->() const {
158  return get();
159  }
160 
161  explicit operator bool() const noexcept {
162  return static_cast<bool>(_poolHandle);
163  }
164 
165  void swap(Sdf_PathNodeHandleImpl &rhs) noexcept {
166  _poolHandle.swap(rhs._poolHandle);
167  }
168 
169  inline bool operator==(Sdf_PathNodeHandleImpl const &rhs) const noexcept {
170  return _poolHandle == rhs._poolHandle;
171  }
172  inline bool operator!=(Sdf_PathNodeHandleImpl const &rhs) const noexcept {
173  return _poolHandle != rhs._poolHandle;
174  }
175  inline bool operator<(Sdf_PathNodeHandleImpl const &rhs) const noexcept {
176  return _poolHandle < rhs._poolHandle;
177  }
178 private:
179 
180  void _AddRef(Sdf_PathNode const *p) const {
181  if (Counted) {
183  }
184  }
185 
186  void _AddRef() const {
187  _AddRef(get());
188  }
189 
190  void _DecRef() const {
191  if (Counted) {
192  intrusive_ptr_release(get());
193  }
194  }
195 
196  Handle _poolHandle { nullptr };
197 };
198 
201 
204 
205 
206 /// A set of SdfPaths.
207 typedef std::set<class SdfPath> SdfPathSet;
208 /// A vector of SdfPaths.
209 typedef std::vector<class SdfPath> SdfPathVector;
210 
211 // Tell VtValue that SdfPath is cheap to copy.
213 
214 /// \class SdfPath
215 ///
216 /// A path value used to locate objects in layers or scenegraphs.
217 ///
218 /// \section sec_SdfPath_Overview Overview
219 ///
220 /// SdfPath is used in several ways:
221 /// \li As a storage key for addressing and accessing values held in a SdfLayer
222 /// \li As a namespace identity for scenegraph objects
223 /// \li As a way to refer to other scenegraph objects through relative paths
224 ///
225 /// The paths represented by an SdfPath class may be either relative or
226 /// absolute. Relative paths are relative to the prim object that contains them
227 /// (that is, if an SdfRelationshipSpec target is relative, it is relative to
228 /// the SdfPrimSpec object that owns the SdfRelationshipSpec object).
229 ///
230 /// SdfPath objects can be readily created from and converted back to strings,
231 /// but as SdfPath objects, they have behaviors that make it easy and efficient
232 /// to work with them. The SdfPath class provides a full range of methods for
233 /// manipulating scene paths by appending a namespace child, appending a
234 /// relationship target, getting the parent path,
235 /// and so on. Since the SdfPath class uses a node-based representation
236 /// internally, you should use the editing functions rather than converting to
237 /// and from strings if possible.
238 ///
239 /// \section sec_SdfPath_Syntax Path Syntax
240 ///
241 /// Like a filesystem path, an SdfPath is conceptually just a sequence of
242 /// path components. Unlike a filesystem path, each component has a type,
243 /// and the type is indicated by the syntax.
244 ///
245 /// Two separators are used between parts of a path. A slash ("/") following an
246 /// identifier is used to introduce a namespace child. A period (".") following
247 /// an identifier is used to introduce a property. A property may also have
248 /// several non-sequential colons (':') in its name to provide a rudimentary
249 /// namespace within properties but may not end or begin with a colon.
250 ///
251 /// A leading slash in the string representation of an SdfPath object indicates
252 /// an absolute path. Two adjacent periods indicate the parent namespace.
253 ///
254 /// Brackets ("[" and "]") are used to indicate relationship target paths for
255 /// relational attributes.
256 ///
257 /// The first part in a path is assumed to be a namespace child unless
258 /// it is preceded by a period. That means:
259 /// \li <c>/Foo</c> is an absolute path specifying the root prim Foo.
260 /// \li <c>/Foo/Bar</c> is an absolute path specifying namespace child Bar
261 /// of root prim Foo.
262 /// \li <c>/Foo/Bar.baz</c> is an absolute path specifying property \c baz of
263 /// namespace child Bar of root prim Foo.
264 /// \li <c>Foo</c> is a relative path specifying namespace child Foo of
265 /// the current prim.
266 /// \li <c>Foo/Bar</c> is a relative path specifying namespace child Bar of
267 /// namespace child Foo of the current prim.
268 /// \li <c>Foo/Bar.baz</c> is a relative path specifying property \c baz of
269 /// namespace child Bar of namespace child Foo of the current prim.
270 /// \li <c>.foo</c> is a relative path specifying the property \c foo of the
271 /// current prim.
272 /// \li <c>/Foo.bar[/Foo.baz].attrib</c> is a relational attribute path. The
273 /// relationship <c>/Foo.bar</c> has a target <c>/Foo.baz</c>. There is a
274 /// relational attribute \c attrib on that relationship-&gt;target pair.
275 ///
276 /// \section sec_SdfPath_ThreadSafety A Note on Thread-Safety
277 ///
278 /// SdfPath is strongly thread-safe, in the sense that zero additional
279 /// synchronization is required between threads creating or using SdfPath
280 /// values. Just like TfToken, SdfPath values are immutable. Internally,
281 /// SdfPath uses a global prefix tree to efficiently share representations
282 /// of paths, and provide fast equality/hashing operations, but
283 /// modifications to this table are internally synchronized. Consequently,
284 /// as with TfToken, for best performance it is important to minimize
285 /// the number of values created (since it requires synchronized access to
286 /// this table) or copied (since it requires atomic ref-counting operations).
287 ///
288 class SdfPath : hboost::totally_ordered<SdfPath>
289 {
290 public:
291  /// The empty path value, equivalent to SdfPath().
292  SDF_API static const SdfPath & EmptyPath();
293 
294  /// The absolute path representing the top of the
295  /// namespace hierarchy.
296  SDF_API static const SdfPath & AbsoluteRootPath();
297 
298  /// The relative path representing "self".
299  SDF_API static const SdfPath & ReflexiveRelativePath();
300 
301  /// \name Constructors
302  /// @{
303 
304  /// Constructs the default, empty path.
305  ///
306  SdfPath() noexcept {
307  // This generates a single instruction instead of 2 on gcc 6.3. Seems
308  // to be fixed on gcc 7+ and newer clangs. Remove when we're there!
309  memset(this, 0, sizeof(*this));
310  }
311 
312  /// Creates a path from the given string.
313  ///
314  /// If the given string is not a well-formed path, this will raise
315  /// a Tf error. Note that passing an empty std::string() will also
316  /// raise an error; the correct way to get the empty path is SdfPath().
317  ///
318  /// Internal dot-dots will be resolved by removing the first dot-dot,
319  /// the element preceding it, and repeating until no internal dot-dots
320  /// remain.
321  ///
322  /// Note that most often new paths are expected to be created by
323  /// asking existing paths to return modified versions of themselves.
324  //
325  // XXX We may want to revisit the behavior when constructing
326  // a path with an empty string ("") to accept it without error and
327  // return EmptyPath.
328  SDF_API explicit SdfPath(const std::string &path);
329 
330  /// @}
331 
332  /// \name Querying paths
333  /// @{
334 
335  /// Returns the number of path elements in this path.
336  SDF_API size_t GetPathElementCount() const;
337 
338  /// Returns whether the path is absolute.
339  SDF_API bool IsAbsolutePath() const;
340 
341  /// Return true if this path is the AbsoluteRootPath().
342  SDF_API bool IsAbsoluteRootPath() const;
343 
344  /// Returns whether the path identifies a prim.
345  SDF_API bool IsPrimPath() const;
346 
347  /// Returns whether the path identifies a prim or the absolute root.
348  SDF_API bool IsAbsoluteRootOrPrimPath() const;
349 
350  /// Returns whether the path identifies a root prim.
351  ///
352  /// the path must be absolute and have a single element
353  /// (for example <c>/foo</c>).
354  SDF_API bool IsRootPrimPath() const;
355 
356  /// Returns whether the path identifies a property.
357  ///
358  /// A relational attribute is considered to be a property, so this
359  /// method will return true for relational attributes as well
360  /// as properties of prims.
361  SDF_API bool IsPropertyPath() const;
362 
363  /// Returns whether the path identifies a prim's property.
364  ///
365  /// A relational attribute is not a prim property.
366  SDF_API bool IsPrimPropertyPath() const;
367 
368  /// Returns whether the path identifies a namespaced property.
369  ///
370  /// A namespaced property has colon embedded in its name.
371  SDF_API bool IsNamespacedPropertyPath() const;
372 
373  /// Returns whether the path identifies a variant selection for a
374  /// prim.
375  SDF_API bool IsPrimVariantSelectionPath() const;
376 
377  /// Return true if this path is a prim path or is a prim variant
378  /// selection path.
380 
381  /// Returns whether the path or any of its parent paths identifies
382  /// a variant selection for a prim.
384 
385  /// Return true if this path contains any property elements, false
386  /// otherwise. A false return indicates a prim-like path, specifically a
387  /// root path, a prim path, or a prim variant selection path. A true return
388  /// indicates a property-like path: a prim property path, a target path, a
389  /// relational attribute path, etc.
391  return static_cast<bool>(_propPart);
392  }
393 
394  /// Return true if this path is or has a prefix that's a target path or a
395  /// mapper path.
396  SDF_API bool ContainsTargetPath() const;
397 
398  /// Returns whether the path identifies a relational attribute.
399  ///
400  /// If this is true, IsPropertyPath() will also be true.
401  SDF_API bool IsRelationalAttributePath() const;
402 
403  /// Returns whether the path identifies a relationship or
404  /// connection target.
405  SDF_API bool IsTargetPath() const;
406 
407  /// Returns whether the path identifies a connection mapper.
408  SDF_API bool IsMapperPath() const;
409 
410  /// Returns whether the path identifies a connection mapper arg.
411  SDF_API bool IsMapperArgPath() const;
412 
413  /// Returns whether the path identifies a connection expression.
414  SDF_API bool IsExpressionPath() const;
415 
416  /// Returns true if this is the empty path (SdfPath::EmptyPath()).
417  inline bool IsEmpty() const noexcept {
418  // No need to check _propPart, because it can only be non-null if
419  // _primPart is non-null.
420  return !_primPart;
421  }
422 
423  /// Return the string representation of this path as a TfToken.
424  ///
425  /// This function is recommended only for human-readable or diagnostic
426  /// output. Use the SdfPath API to manipulate paths. It is less
427  /// error-prone and has better performance.
428  SDF_API TfToken GetAsToken() const;
429 
430  /// Return the string representation of this path as a TfToken lvalue.
431  ///
432  /// This function returns a persistent lvalue. If an rvalue will suffice,
433  /// call GetAsToken() instead. That avoids populating internal data
434  /// structures to hold the persistent token.
435  ///
436  /// This function is recommended only for human-readable or diagnostic
437  /// output. Use the SdfPath API to manipulate paths. It is less
438  /// error-prone and has better performance.
439  SDF_API TfToken const &GetToken() const;
440 
441  /// Return the string representation of this path as a std::string.
442  ///
443  /// This function is recommended only for human-readable or diagnostic
444  /// output. Use the SdfPath API to manipulate paths. It is less
445  /// error-prone and has better performance.
447 
448  /// Return the string representation of this path as a std::string.
449  ///
450  /// This function returns a persistent lvalue. If an rvalue will suffice,
451  /// call GetAsString() instead. That avoids populating internal data
452  /// structures to hold the persistent string.
453  ///
454  /// This function is recommended only for human-readable or diagnostic
455  /// output. Use the SdfPath API to manipulate paths. It is less
456  /// error-prone and has better performance.
457  SDF_API const std::string &GetString() const;
458 
459  /// Returns the string representation of this path as a c string.
460  ///
461  /// This function returns a pointer to a persistent c string. If a
462  /// temporary c string will suffice, call GetAsString().c_str() instead.
463  /// That avoids populating internal data structures to hold the persistent
464  /// string.
465  ///
466  /// This function is recommended only for human-readable or diagnostic
467  /// output. Use the SdfPath API to manipulate paths. It is less
468  /// error-prone and has better performance.
469  SDF_API const char *GetText() const;
470 
471  /// Returns the prefix paths of this path.
472  ///
473  /// Prefixes are returned in order of shortest to longest. The path
474  /// itself is returned as the last prefix.
475  /// Note that if the prefix order does not need to be from shortest to
476  /// longest, it is more efficient to use GetAncestorsRange, which
477  /// produces an equivalent set of paths, ordered from longest to shortest.
478  SDF_API SdfPathVector GetPrefixes() const;
479 
480  /// Fills prefixes with prefixes of this path.
481  ///
482  /// This avoids copy constructing the return value.
483  ///
484  /// Prefixes are returned in order of shortest to longest. The path
485  /// itself is returned as the last prefix.
486  /// Note that if the prefix order does not need to be from shortest to
487  /// longest, it is more efficient to use GetAncestorsRange, which
488  /// produces an equivalent set of paths, ordered from longest to shortest.
489  SDF_API void GetPrefixes(SdfPathVector *prefixes) const;
490 
491  /// Return a range for iterating over the ancestors of this path.
492  ///
493  /// The range provides iteration over the prefixes of a path, ordered
494  /// from longest to shortest (the opposite of the order of the prefixes
495  /// returned by GetPrefixes).
497 
498  /// Returns the name of the prim, property or relational
499  /// attribute identified by the path.
500  ///
501  /// Returns EmptyPath if this path is a target or mapper path.
502  ///
503  /// <ul>
504  /// <li>Returns "" for EmptyPath.</li>
505  /// <li>Returns "." for ReflexiveRelativePath.</li>
506  /// <li>Returns ".." for a path ending in ParentPathElement.</li>
507  /// </ul>
508  SDF_API const std::string &GetName() const;
509 
510  /// Returns the name of the prim, property or relational
511  /// attribute identified by the path, as a token.
512  SDF_API const TfToken &GetNameToken() const;
513 
514  /// Returns an ascii representation of the "terminal" element
515  /// of this path, which can be used to reconstruct the path using
516  /// \c AppendElementString() on its parent.
517  ///
518  /// EmptyPath(), AbsoluteRootPath(), and ReflexiveRelativePath() are
519  /// \em not considered elements (one of the defining properties of
520  /// elements is that they have a parent), so \c GetElementString() will
521  /// return the empty string for these paths.
522  ///
523  /// Unlike \c GetName() and \c GetTargetPath(), which provide you "some"
524  /// information about the terminal element, this provides a complete
525  /// representation of the element, for all element types.
526  ///
527  /// Also note that whereas \c GetName(), \c GetNameToken(), \c GetText(),
528  /// \c GetString(), and \c GetTargetPath() return cached results,
529  /// \c GetElementString() always performs some amount of string
530  /// manipulation, which you should keep in mind if performance is a concern.
532 
533  /// Like GetElementString() but return the value as a TfToken.
535 
536  /// Return a copy of this path with its final component changed to
537  /// \a newName. This path must be a prim or property path.
538  ///
539  /// This method is shorthand for path.GetParentPath().AppendChild(newName)
540  /// for prim paths, path.GetParentPath().AppendProperty(newName) for
541  /// prim property paths, and
542  /// path.GetParentPath().AppendRelationalAttribute(newName) for relational
543  /// attribute paths.
544  ///
545  /// Note that only the final path component is ever changed. If the name of
546  /// the final path component appears elsewhere in the path, it will not be
547  /// modified.
548  ///
549  /// Some examples:
550  ///
551  /// ReplaceName('/chars/MeridaGroup', 'AngusGroup') -> '/chars/AngusGroup'
552  /// ReplaceName('/Merida.tx', 'ty') -> '/Merida.ty'
553  /// ReplaceName('/Merida.tx[targ].tx', 'ty') -> '/Merida.tx[targ].ty'
554  ///
555  SDF_API SdfPath ReplaceName(TfToken const &newName) const;
556 
557  /// Returns the relational attribute or mapper target path
558  /// for this path.
559  ///
560  /// Returns EmptyPath if this is not a target, relational attribute or
561  /// mapper path.
562  ///
563  /// Note that it is possible for a path to have multiple "target" paths.
564  /// For example a path that identifies a connection target for a
565  /// relational attribute includes the target of the connection as well
566  /// as the target of the relational attribute. In these cases, the
567  /// "deepest" or right-most target path will be returned (the connection
568  /// target in this example).
569  SDF_API const SdfPath &GetTargetPath() const;
570 
571  /// Returns all the relationship target or connection target
572  /// paths contained in this path, and recursively all the target paths
573  /// contained in those target paths in reverse depth-first order.
574  ///
575  /// For example, given the path: '/A/B.a[/C/D.a[/E/F.a]].a[/A/B.a[/C/D.a]]'
576  /// this method produces: '/A/B.a[/C/D.a]', '/C/D.a', '/C/D.a[/E/F.a]',
577  /// '/E/F.a'
578  SDF_API void GetAllTargetPathsRecursively(SdfPathVector *result) const;
579 
580  /// Returns the variant selection for this path, if this is a variant
581  /// selection path.
582  /// Returns a pair of empty strings if this path is not a variant
583  /// selection path.
584  SDF_API
585  std::pair<std::string, std::string> GetVariantSelection() const;
586 
587  /// Return true if both this path and \a prefix are not the empty
588  /// path and this path has \a prefix as a prefix. Return false otherwise.
589  SDF_API bool HasPrefix( const SdfPath &prefix ) const;
590 
591  /// @}
592 
593  /// \name Creating new paths by modifying existing paths
594  /// @{
595 
596  /// Return the path that identifies this path's namespace parent.
597  ///
598  /// For a prim path (like '/foo/bar'), return the prim's parent's path
599  /// ('/foo'). For a prim property path (like '/foo/bar.property'), return
600  /// the prim's path ('/foo/bar'). For a target path (like
601  /// '/foo/bar.property[/target]') return the property path
602  /// ('/foo/bar.property'). For a mapper path (like
603  /// '/foo/bar.property.mapper[/target]') return the property path
604  /// ('/foo/bar.property). For a relational attribute path (like
605  /// '/foo/bar.property[/target].relAttr') return the relationship target's
606  /// path ('/foo/bar.property[/target]'). For a prim variant selection path
607  /// (like '/foo/bar{var=sel}') return the prim path ('/foo/bar'). For a
608  /// root prim path (like '/rootPrim'), return AbsoluteRootPath() ('/'). For
609  /// a single element relative prim path (like 'relativePrim'), return
610  /// ReflexiveRelativePath() ('.'). For ReflexiveRelativePath(), return the
611  /// relative parent path ('..').
612  ///
613  /// Note that the parent path of a relative parent path ('..') is a relative
614  /// grandparent path ('../..'). Use caution writing loops that walk to
615  /// parent paths since relative paths have infinitely many ancestors. To
616  /// more safely traverse ancestor paths, consider iterating over an
617  /// SdfPathAncestorsRange instead, as returend by GetAncestorsRange().
618  SDF_API SdfPath GetParentPath() const;
619 
620  /// Creates a path by stripping all relational attributes, targets,
621  /// properties, and variant selections from the leafmost prim path, leaving
622  /// the nearest path for which \a IsPrimPath() returns true.
623  ///
624  /// See \a GetPrimOrPrimVariantSelectionPath also.
625  ///
626  /// If the path is already a prim path, the same path is returned.
627  SDF_API SdfPath GetPrimPath() const;
628 
629  /// Creates a path by stripping all relational attributes, targets,
630  /// and properties, leaving the nearest path for which
631  /// \a IsPrimOrPrimVariantSelectionPath() returns true.
632  ///
633  /// See \a GetPrimPath also.
634  ///
635  /// If the path is already a prim or a prim variant selection path, the same
636  /// path is returned.
638 
639  /// Creates a path by stripping all properties and relational
640  /// attributes from this path, leaving the path to the containing prim.
641  ///
642  /// If the path is already a prim or absolute root path, the same
643  /// path is returned.
645 
646  /// Create a path by stripping all variant selections from all
647  /// components of this path, leaving a path with no embedded variant
648  /// selections.
650 
651  /// Creates a path by appending a given relative path to this path.
652  ///
653  /// If the newSuffix is a prim path, then this path must be a prim path
654  /// or a root path.
655  ///
656  /// If the newSuffix is a prim property path, then this path must be
657  /// a prim path or the ReflexiveRelativePath.
658  SDF_API SdfPath AppendPath(const SdfPath &newSuffix) const;
659 
660  /// Creates a path by appending an element for \p childName
661  /// to this path.
662  ///
663  /// This path must be a prim path, the AbsoluteRootPath
664  /// or the ReflexiveRelativePath.
665  SDF_API SdfPath AppendChild(TfToken const &childName) const;
666 
667  /// Creates a path by appending an element for \p propName
668  /// to this path.
669  ///
670  /// This path must be a prim path or the ReflexiveRelativePath.
671  SDF_API SdfPath AppendProperty(TfToken const &propName) const;
672 
673  /// Creates a path by appending an element for \p variantSet
674  /// and \p variant to this path.
675  ///
676  /// This path must be a prim path.
677  SDF_API
678  SdfPath AppendVariantSelection(const std::string &variantSet,
679  const std::string &variant) const;
680 
681  /// Creates a path by appending an element for
682  /// \p targetPath.
683  ///
684  /// This path must be a prim property or relational attribute path.
685  SDF_API SdfPath AppendTarget(const SdfPath &targetPath) const;
686 
687  /// Creates a path by appending an element for
688  /// \p attrName to this path.
689  ///
690  /// This path must be a target path.
691  SDF_API
692  SdfPath AppendRelationalAttribute(TfToken const &attrName) const;
693 
694  /// Replaces the relational attribute's target path
695  ///
696  /// The path must be a relational attribute path.
697  SDF_API
698  SdfPath ReplaceTargetPath( const SdfPath &newTargetPath ) const;
699 
700  /// Creates a path by appending a mapper element for
701  /// \p targetPath.
702  ///
703  /// This path must be a prim property or relational attribute path.
704  SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const;
705 
706  /// Creates a path by appending an element for
707  /// \p argName.
708  ///
709  /// This path must be a mapper path.
710  SDF_API SdfPath AppendMapperArg(TfToken const &argName) const;
711 
712  /// Creates a path by appending an expression element.
713  ///
714  /// This path must be a prim property or relational attribute path.
716 
717  /// Creates a path by extracting and appending an element
718  /// from the given ascii element encoding.
719  ///
720  /// Attempting to append a root or empty path (or malformed path)
721  /// or attempting to append \em to the EmptyPath will raise an
722  /// error and return the EmptyPath.
723  ///
724  /// May also fail and return EmptyPath if this path's type cannot
725  /// possess a child of the type encoded in \p element.
726  SDF_API SdfPath AppendElementString(const std::string &element) const;
727 
728  /// Like AppendElementString() but take the element as a TfToken.
729  SDF_API SdfPath AppendElementToken(const TfToken &elementTok) const;
730 
731  /// Returns a path with all occurrences of the prefix path
732  /// \p oldPrefix replaced with the prefix path \p newPrefix.
733  ///
734  /// If fixTargetPaths is true, any embedded target paths will also
735  /// have their paths replaced. This is the default.
736  ///
737  /// If this is not a target, relational attribute or mapper path this
738  /// will do zero or one path prefix replacements, if not the number of
739  /// replacements can be greater than one.
740  SDF_API
741  SdfPath ReplacePrefix(const SdfPath &oldPrefix,
742  const SdfPath &newPrefix,
743  bool fixTargetPaths=true) const;
744 
745  /// Returns a path with maximal length that is a prefix path of
746  /// both this path and \p path.
748 
749  /// Find and remove the longest common suffix from two paths.
750  ///
751  /// Returns this path and \p otherPath with the longest common suffix
752  /// removed (first and second, respectively). If the two paths have no
753  /// common suffix then the paths are returned as-is. If the paths are
754  /// equal then this returns empty paths for relative paths and absolute
755  /// roots for absolute paths. The paths need not be the same length.
756  ///
757  /// If \p stopAtRootPrim is \c true then neither returned path will be
758  /// the root path. That, in turn, means that some common suffixes will
759  /// not be removed. For example, if \p stopAtRootPrim is \c true then
760  /// the paths /A/B and /B will be returned as is. Were it \c false
761  /// then the result would be /A and /. Similarly paths /A/B/C and
762  /// /B/C would return /A/B and /B if \p stopAtRootPrim is \c true but
763  /// /A and / if it's \c false.
764  SDF_API
765  std::pair<SdfPath, SdfPath>
766  RemoveCommonSuffix(const SdfPath& otherPath,
767  bool stopAtRootPrim = false) const;
768 
769  /// Returns the absolute form of this path using \p anchor
770  /// as the relative basis.
771  ///
772  /// \p anchor must be an absolute prim path.
773  ///
774  /// If this path is a relative path, resolve it using \p anchor as the
775  /// relative basis.
776  ///
777  /// If this path is already an absolute path, just return a copy.
778  SDF_API SdfPath MakeAbsolutePath(const SdfPath & anchor) const;
779 
780  /// Returns the relative form of this path using \p anchor
781  /// as the relative basis.
782  ///
783  /// \p anchor must be an absolute prim path.
784  ///
785  /// If this path is an absolute path, return the corresponding relative path
786  /// that is relative to the absolute path given by \p anchor.
787  ///
788  /// If this path is a relative path, return the optimal relative
789  /// path to the absolute path given by \p anchor. (The optimal
790  /// relative path from a given prim path is the relative path
791  /// with the least leading dot-dots.
792  SDF_API SdfPath MakeRelativePath(const SdfPath & anchor) const;
793 
794  /// @}
795 
796  /// \name Valid path strings, prim and property names
797  /// @{
798 
799  /// Returns whether \p name is a legal identifier for any
800  /// path component.
801  SDF_API static bool IsValidIdentifier(const std::string &name);
802 
803  /// Returns whether \p name is a legal namespaced identifier.
804  /// This returns \c true if IsValidIdentifier() does.
806 
807  /// Tokenizes \p name by the namespace delimiter.
808  /// Returns the empty vector if \p name is not a valid namespaced
809  /// identifier.
810  SDF_API static std::vector<std::string> TokenizeIdentifier(const std::string &name);
811 
812  /// Tokenizes \p name by the namespace delimiter.
813  /// Returns the empty vector if \p name is not a valid namespaced
814  /// identifier.
815  SDF_API
817 
818  /// Join \p names into a single identifier using the namespace delimiter.
819  /// Any empty strings present in \p names are ignored when joining.
820  SDF_API
821  static std::string JoinIdentifier(const std::vector<std::string> &names);
822 
823  /// Join \p names into a single identifier using the namespace delimiter.
824  /// Any empty strings present in \p names are ignored when joining.
825  SDF_API
827 
828  /// Join \p lhs and \p rhs into a single identifier using the
829  /// namespace delimiter.
830  /// Returns \p lhs if \p rhs is empty and vice verse.
831  /// Returns an empty string if both \p lhs and \p rhs are empty.
832  SDF_API
833  static std::string JoinIdentifier(const std::string &lhs,
834  const std::string &rhs);
835 
836  /// Join \p lhs and \p rhs into a single identifier using the
837  /// namespace delimiter.
838  /// Returns \p lhs if \p rhs is empty and vice verse.
839  /// Returns an empty string if both \p lhs and \p rhs are empty.
840  SDF_API
841  static std::string JoinIdentifier(const TfToken &lhs, const TfToken &rhs);
842 
843  /// Returns \p name stripped of any namespaces.
844  /// This does not check the validity of the name; it just attempts
845  /// to remove anything that looks like a namespace.
846  SDF_API
848 
849  /// Returns \p name stripped of any namespaces.
850  /// This does not check the validity of the name; it just attempts
851  /// to remove anything that looks like a namespace.
852  SDF_API
853  static TfToken StripNamespace(const TfToken &name);
854 
855  /// Returns (\p name, \c true) where \p name is stripped of the prefix
856  /// specified by \p matchNamespace if \p name indeed starts with
857  /// \p matchNamespace. Returns (\p name, \c false) otherwise, with \p name
858  /// unmodified.
859  ///
860  /// This function deals with both the case where \p matchNamespace contains
861  /// the trailing namespace delimiter ':' or not.
862  ///
863  SDF_API
864  static std::pair<std::string, bool>
866  const std::string &matchNamespace);
867 
868  /// Return true if \p pathString is a valid path string, meaning that
869  /// passing the string to the \a SdfPath constructor will result in a valid,
870  /// non-empty SdfPath. Otherwise, return false and if \p errMsg is not NULL,
871  /// set the pointed-to string to the parse error.
872  SDF_API
873  static bool IsValidPathString(const std::string &pathString,
874  std::string *errMsg = 0);
875 
876  /// @}
877 
878  /// \name Operators
879  /// @{
880 
881  /// Equality operator.
882  /// (Boost provides inequality from this.)
883  inline bool operator==(const SdfPath &rhs) const {
884  return _AsInt() == rhs._AsInt();
885  }
886 
887  /// Comparison operator.
888  ///
889  /// This orders paths lexicographically, aka dictionary-style.
890  ///
891  inline bool operator<(const SdfPath &rhs) const {
892  if (_AsInt() == rhs._AsInt()) {
893  return false;
894  }
895  if (!_primPart || !rhs._primPart) {
896  return !_primPart && rhs._primPart;
897  }
898  // Valid prim parts -- must walk node structure, etc.
899  return _LessThanInternal(*this, rhs);
900  }
901 
902  template <class HashState>
903  friend void TfHashAppend(HashState &h, SdfPath const &path) {
904  // The hash function is pretty sensitive performance-wise. Be
905  // careful making changes here, and run tests.
906  uint32_t primPart, propPart;
907  memcpy(&primPart, &path._primPart, sizeof(primPart));
908  memcpy(&propPart, &path._propPart, sizeof(propPart));
909  h.Append(primPart);
910  h.Append(propPart);
911  }
912 
913  // For hash maps and sets
914  struct Hash {
915  inline size_t operator()(const SdfPath& path) const {
916  return TfHash()(path);
917  }
918  };
919 
920  inline size_t GetHash() const {
921  return Hash()(*this);
922  }
923 
924  // For cases where an unspecified total order that is not stable from
925  // run-to-run is needed.
926  struct FastLessThan {
927  inline bool operator()(const SdfPath& a, const SdfPath& b) const {
928  return a._AsInt() < b._AsInt();
929  }
930  };
931 
932  /// @}
933 
934  /// \name Utilities
935  /// @{
936 
937  /// Given some vector of paths, get a vector of concise unambiguous
938  /// relative paths.
939  ///
940  /// GetConciseRelativePaths requires a vector of absolute paths. It
941  /// finds a set of relative paths such that each relative path is
942  /// unique.
943  SDF_API static SdfPathVector
944  GetConciseRelativePaths(const SdfPathVector& paths);
945 
946  /// Remove all elements of \a paths that are prefixed by other
947  /// elements in \a paths. As a side-effect, the result is left in sorted
948  /// order.
949  SDF_API static void RemoveDescendentPaths(SdfPathVector *paths);
950 
951  /// Remove all elements of \a paths that prefix other elements in
952  /// \a paths. As a side-effect, the result is left in sorted order.
953  SDF_API static void RemoveAncestorPaths(SdfPathVector *paths);
954 
955  /// @}
956 
957 private:
958 
959  // This is used for all internal path construction where we do operations
960  // via nodes and then want to return a new path with a resulting prim and
961  // property parts.
962 
963  // Accept rvalues.
964  explicit SdfPath(Sdf_PathPrimNodeHandle &&primNode)
965  : _primPart(std::move(primNode)) {}
966 
967  // Construct from prim & prop parts.
968  SdfPath(Sdf_PathPrimNodeHandle const &primPart,
969  Sdf_PathPropNodeHandle const &propPart)
970  : _primPart(primPart)
971  , _propPart(propPart) {}
972 
973  // Construct from prim & prop node pointers.
974  SdfPath(Sdf_PathNode const *primPart,
975  Sdf_PathNode const *propPart)
976  : _primPart(primPart)
977  , _propPart(propPart) {}
978 
979  friend class Sdf_PathNode;
980  friend class Sdfext_PathAccess;
981  friend class SdfPathAncestorsRange;
982 
983  // converts elements to a string for parsing (unfortunate)
984  static std::string
985  _ElementsToString(bool absolute, const std::vector<std::string> &elements);
986 
987  SdfPath _ReplacePrimPrefix(SdfPath const &oldPrefix,
988  SdfPath const &newPrefix) const;
989 
990  SdfPath _ReplaceTargetPathPrefixes(SdfPath const &oldPrefix,
991  SdfPath const &newPrefix) const;
992 
993  SdfPath _ReplacePropPrefix(SdfPath const &oldPrefix,
994  SdfPath const &newPrefix,
995  bool fixTargetPaths) const;
996 
997  // Helper to implement the uninlined portion of operator<.
998  SDF_API static bool
999  _LessThanInternal(SdfPath const &lhs, SdfPath const &rhs);
1000 
1001  inline uint64_t _AsInt() const {
1002  static_assert(sizeof(*this) == sizeof(uint64_t), "");
1003  uint64_t ret;
1004  std::memcpy(&ret, this, sizeof(*this));
1005  return ret;
1006  }
1007 
1008  friend void swap(SdfPath &lhs, SdfPath &rhs) {
1009  lhs._primPart.swap(rhs._primPart);
1010  lhs._propPart.swap(rhs._propPart);
1011  }
1012 
1013  Sdf_PathPrimNodeHandle _primPart;
1014  Sdf_PathPropNodeHandle _propPart;
1015 
1016 };
1017 
1018 
1019 /// \class SdfPathAncestorsRange
1020 ///
1021 /// Range representing a path and ancestors, and providing methods for
1022 /// iterating over them.
1023 ///
1024 /// An ancestor range represents a path and all of its ancestors ordered from
1025 /// nearest to furthest (root-most).
1026 /// For example, given a path like `/a/b.prop`, the range represents paths
1027 /// `/a/b.prop`, `/a/b` and `/a`, in that order.
1028 /// A range accepts relative paths as well: For path `a/b.prop`, the range
1029 /// represents paths 'a/b.prop`, `a/b` and `a`.
1030 /// If a path contains parent path elements, (`..`), those elements are treated
1031 /// as elements of the range. For instance, given path `../a/b`, the range
1032 /// represents paths `../a/b`, `../a` and `..`.
1033 /// This represents the same of set of `prefix` paths as SdfPath::GetPrefixes,
1034 /// but in reverse order.
1036 {
1037 public:
1038 
1040  : _path(path) {}
1041 
1042  const SdfPath& GetPath() const { return _path; }
1043 
1044  struct iterator {
1045  using iterator_category = std::forward_iterator_tag;
1047  using difference_type = std::ptrdiff_t;
1048  using reference = const SdfPath&;
1049  using pointer = const SdfPath*;
1050 
1051  iterator(const SdfPath& path) : _path(path) {}
1052 
1053  iterator() = default;
1054 
1055  SDF_API
1056  iterator& operator++();
1057 
1058  const SdfPath& operator*() const { return _path; }
1059 
1060  const SdfPath* operator->() const { return &_path; }
1061 
1062  bool operator==(const iterator& o) const { return _path == o._path; }
1063 
1064  bool operator!=(const iterator& o) const { return _path != o._path; }
1065 
1066  /// Return the distance between two iterators.
1067  /// It is only valid to compute the distance between paths
1068  /// that share a common prefix.
1069  SDF_API friend difference_type
1070  distance(const iterator& first, const iterator& last);
1071 
1072  private:
1073  SdfPath _path;
1074  };
1075 
1076  iterator begin() const { return iterator(_path); }
1077 
1078  iterator end() const { return iterator(); }
1079 
1080 private:
1081  SdfPath _path;
1082 };
1083 
1084 
1085 // Overload hash_value for SdfPath. Used by things like hboost::hash.
1086 inline size_t hash_value(SdfPath const &path)
1087 {
1088  return path.GetHash();
1089 }
1090 
1091 /// Writes the string representation of \p path to \p out.
1092 SDF_API std::ostream & operator<<( std::ostream &out, const SdfPath &path );
1093 
1094 // Helper for SdfPathFindPrefixedRange & SdfPathFindLongestPrefix. A function
1095 // object that returns an SdfPath const & unchanged.
1097  inline SdfPath const &operator()(SdfPath const &arg) const {
1098  return arg;
1099  }
1100 };
1101 
1102 /// Find the subrange of the sorted range [\a begin, \a end) that includes all
1103 /// paths prefixed by \a path. The input range must be ordered according to
1104 /// SdfPath::operator<. If your range's iterators' value_types are not SdfPath,
1105 /// but you can obtain SdfPaths from them (e.g. map<SdfPath, X>::iterator), you
1106 /// can pass a function to extract the path from the dereferenced iterator in
1107 /// \p getPath.
1108 template <class ForwardIterator, class GetPathFn = Sdf_PathIdentity>
1109 std::pair<ForwardIterator, ForwardIterator>
1110 SdfPathFindPrefixedRange(ForwardIterator begin, ForwardIterator end,
1111  SdfPath const &prefix,
1112  GetPathFn const &getPath = GetPathFn()) {
1113  using IterRef =
1115 
1116  struct Compare {
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;
1121  }
1122  };
1123 
1124  std::pair<ForwardIterator, ForwardIterator> result;
1125 
1126  // First, use lower_bound to find where \a prefix would go.
1127  result.first = std::lower_bound(begin, end, prefix, Compare(getPath));
1128 
1129  // Next, find end of range starting from the lower bound, using the
1130  // prefixing condition to define the boundary.
1131  result.second = TfFindBoundary(result.first, end,
1132  [&prefix, &getPath](IterRef iterRef) {
1133  return getPath(iterRef).HasPrefix(prefix);
1134  });
1135 
1136  return result;
1137 }
1138 
1139 template <class RandomAccessIterator, class GetPathFn>
1140 RandomAccessIterator
1141 Sdf_PathFindLongestPrefixImpl(RandomAccessIterator begin,
1142  RandomAccessIterator end,
1143  SdfPath const &path,
1144  bool strictPrefix,
1145  GetPathFn const &getPath)
1146 {
1147  using IterRef =
1149 
1150  struct Compare {
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;
1155  }
1156  };
1157 
1158  // Search for the path in [begin, end). If present, return it. If not,
1159  // examine prior element in [begin, end). If none, return end. Else, is it
1160  // a prefix of path? If so, return it. Else find common prefix of that
1161  // element and path and recurse.
1162 
1163  // If empty sequence, return.
1164  if (begin == end)
1165  return end;
1166 
1167  Compare comp(getPath);
1168 
1169  // Search for where this path would lexicographically appear in the range.
1170  RandomAccessIterator result = std::lower_bound(begin, end, path, comp);
1171 
1172  // If we didn't get the end, check to see if we got the path exactly if
1173  // we're not looking for a strict prefix.
1174  if (!strictPrefix && result != end && getPath(*result) == path) {
1175  return result;
1176  }
1177 
1178  // If we got begin (and didn't match in the case of a non-strict prefix)
1179  // then there's no prefix.
1180  if (result == begin) {
1181  return end;
1182  }
1183 
1184  // If the prior element is a prefix, we're done.
1185  if (path.HasPrefix(getPath(*--result))) {
1186  return result;
1187  }
1188 
1189  // Otherwise, find the common prefix of the lexicographical predecessor and
1190  // look for its prefix in the preceding range.
1191  SdfPath newPath = path.GetCommonPrefix(getPath(*result));
1192  auto origEnd = end;
1193  do {
1194  end = result;
1195  result = std::lower_bound(begin, end, newPath, comp);
1196 
1197  if (result != end && getPath(*result) == newPath) {
1198  return result;
1199  }
1200  if (result == begin) {
1201  return origEnd;
1202  }
1203  if (newPath.HasPrefix(getPath(*--result))) {
1204  return result;
1205  }
1206  newPath = newPath.GetCommonPrefix(getPath(*result));
1207  } while (true);
1208 }
1209 
1210 /// Return an iterator to the element of [\a begin, \a end) that is the longest
1211 /// prefix of the given path (including the path itself), if there is such an
1212 /// element, otherwise \a end. The input range must be ordered according to
1213 /// SdfPath::operator<. If your range's iterators' value_types are not SdfPath,
1214 /// but you can obtain SdfPaths from them (e.g. vector<pair<SdfPath,
1215 /// X>>::iterator), you can pass a function to extract the path from the
1216 /// dereferenced iterator in \p getPath.
1217 template <class RandomAccessIterator, class GetPathFn = Sdf_PathIdentity,
1218  class = typename std::enable_if<
1219  std::is_base_of<
1220  std::random_access_iterator_tag,
1221  typename std::iterator_traits<
1222  RandomAccessIterator>::iterator_category
1223  >::value
1224  >::type
1225  >
1226 RandomAccessIterator
1227 SdfPathFindLongestPrefix(RandomAccessIterator begin,
1228  RandomAccessIterator end,
1229  SdfPath const &path,
1230  GetPathFn const &getPath = GetPathFn())
1231 {
1233  begin, end, path, /*strictPrefix=*/false, getPath);
1234 }
1235 
1236 /// Return an iterator to the element of [\a begin, \a end) that is the longest
1237 /// prefix of the given path (excluding the path itself), if there is such an
1238 /// element, otherwise \a end. The input range must be ordered according to
1239 /// SdfPath::operator<. If your range's iterators' value_types are not SdfPath,
1240 /// but you can obtain SdfPaths from them (e.g. vector<pair<SdfPath,
1241 /// X>>::iterator), you can pass a function to extract the path from the
1242 /// dereferenced iterator in \p getPath.
1243 template <class RandomAccessIterator, class GetPathFn = Sdf_PathIdentity,
1244  class = typename std::enable_if<
1245  std::is_base_of<
1246  std::random_access_iterator_tag,
1247  typename std::iterator_traits<
1248  RandomAccessIterator>::iterator_category
1249  >::value
1250  >::type
1251  >
1252 RandomAccessIterator
1253 SdfPathFindLongestStrictPrefix(RandomAccessIterator begin,
1254  RandomAccessIterator end,
1255  SdfPath const &path,
1256  GetPathFn const &getPath = GetPathFn())
1257 {
1259  begin, end, path, /*strictPrefix=*/true, getPath);
1260 }
1261 
1262 template <class Iter, class MapParam, class GetPathFn = Sdf_PathIdentity>
1263 Iter
1265  MapParam map, SdfPath const &path, bool strictPrefix,
1266  GetPathFn const &getPath = GetPathFn())
1267 {
1268  // Search for the path in map. If present, return it. If not, examine
1269  // prior element in map. If none, return end. Else, is it a prefix of
1270  // path? If so, return it. Else find common prefix of that element and
1271  // path and recurse.
1272 
1273  const Iter mapEnd = map.end();
1274 
1275  // If empty, return.
1276  if (map.empty())
1277  return mapEnd;
1278 
1279  // Search for where this path would lexicographically appear in the range.
1280  Iter result = map.lower_bound(path);
1281 
1282  // If we didn't get the end, check to see if we got the path exactly if
1283  // we're not looking for a strict prefix.
1284  if (!strictPrefix && result != mapEnd && getPath(*result) == path)
1285  return result;
1286 
1287  // If we got begin (and didn't match in the case of a non-strict prefix)
1288  // then there's no prefix.
1289  if (result == map.begin())
1290  return mapEnd;
1291 
1292  // If the prior element is a prefix, we're done.
1293  if (path.HasPrefix(getPath(*--result)))
1294  return result;
1295 
1296  // Otherwise, find the common prefix of the lexicographical predecessor and
1297  // recurse looking for it or its longest prefix in the preceding range. We
1298  // always pass strictPrefix=false, since now we're operating on prefixes of
1299  // the original caller's path.
1300  return Sdf_PathFindLongestPrefixImpl<Iter, MapParam>(
1301  map, path.GetCommonPrefix(getPath(*result)), /*strictPrefix=*/false,
1302  getPath);
1303 }
1304 
1305 /// Return an iterator pointing to the element of \a set whose key is the
1306 /// longest prefix of the given path (including the path itself). If there is
1307 /// no such element, return \a set.end().
1308 SDF_API
1309 typename std::set<SdfPath>::const_iterator
1310 SdfPathFindLongestPrefix(std::set<SdfPath> const &set, SdfPath const &path);
1311 
1312 /// Return an iterator pointing to the element of \a map whose key is the
1313 /// longest prefix of the given path (including the path itself). If there is
1314 /// no such element, return \a map.end().
1315 template <class T>
1316 typename std::map<SdfPath, T>::const_iterator
1317 SdfPathFindLongestPrefix(std::map<SdfPath, T> const &map, SdfPath const &path)
1318 {
1320  typename std::map<SdfPath, T>::const_iterator,
1321  std::map<SdfPath, T> const &>(map, path, /*strictPrefix=*/false,
1322  TfGet<0>());
1323 }
1324 template <class T>
1325 typename std::map<SdfPath, T>::iterator
1326 SdfPathFindLongestPrefix(std::map<SdfPath, T> &map, SdfPath const &path)
1327 {
1329  typename std::map<SdfPath, T>::iterator,
1330  std::map<SdfPath, T> &>(map, path, /*strictPrefix=*/false,
1331  TfGet<0>());
1332 }
1333 
1334 /// Return an iterator pointing to the element of \a set whose key is the
1335 /// longest prefix of the given path (excluding the path itself). If there is
1336 /// no such element, return \a set.end().
1337 SDF_API
1338 typename std::set<SdfPath>::const_iterator
1339 SdfPathFindLongestStrictPrefix(std::set<SdfPath> const &set,
1340  SdfPath const &path);
1341 
1342 /// Return an iterator pointing to the element of \a map whose key is the
1343 /// longest prefix of the given path (excluding the path itself). If there is
1344 /// no such element, return \a map.end().
1345 template <class T>
1346 typename std::map<SdfPath, T>::const_iterator
1348  std::map<SdfPath, T> const &map, SdfPath const &path)
1349 {
1351  typename std::map<SdfPath, T>::const_iterator,
1352  std::map<SdfPath, T> const &>(map, path, /*strictPrefix=*/true,
1353  TfGet<0>());
1354 }
1355 template <class T>
1356 typename std::map<SdfPath, T>::iterator
1358  std::map<SdfPath, T> &map, SdfPath const &path)
1359 {
1361  typename std::map<SdfPath, T>::iterator,
1362  std::map<SdfPath, T> &>(map, path, /*strictPrefix=*/true,
1363  TfGet<0>());
1364 }
1365 
1367 
1368 // Sdf_PathNode is not public API, but we need to include it here
1369 // so we can inline the ref-counting operations, which must manipulate
1370 // its internal _refCount member.
1371 #include "pxr/usd/sdf/pathNode.h"
1372 
1374 
1375 static_assert(Sdf_SizeofPrimPathNode == sizeof(Sdf_PrimPathNode), "");
1376 static_assert(Sdf_SizeofPropPathNode == sizeof(Sdf_PrimPropertyPathNode), "");
1377 
1379 
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
Definition: glcorearb.h:1221
friend void swap(SdfPath &lhs, SdfPath &rhs)
Definition: path.h:1008
SDF_API iterator & operator++()
SDF_API const std::string & GetName() const
static SDF_API const SdfPath & AbsoluteRootPath()
friend class Sdfext_PathAccess
Definition: path.h:980
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)
Definition: path.h:1051
Sdf_PathNodeHandleImpl(Handle h, bool add_ref=true)
Definition: path.h:96
SDF_API SdfPath AppendMapper(const SdfPath &targetPath) const
GLint first
Definition: glcorearb.h:404
STATIC_INLINE size_t Hash(const char *s, size_t len)
Definition: farmhash.h:2038
bool operator==(const SdfPath &rhs) const
Definition: path.h:883
Sdf_PathPropPartPool::Handle Sdf_PathPropHandle
Definition: path.h:76
SDF_API SdfPath ReplaceTargetPath(const SdfPath &newTargetPath) const
void reset() noexcept
Definition: path.h:142
std::pair< ForwardIterator, ForwardIterator > SdfPathFindPrefixedRange(ForwardIterator begin, ForwardIterator end, SdfPath const &prefix, GetPathFn const &getPath=GetPathFn())
Definition: path.h:1110
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)
Definition: path.h:1141
SDF_API bool IsAbsoluteRootPath() const
Return true if this path is the AbsoluteRootPath().
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
SDF_API bool IsMapperArgPath() const
Returns whether the path identifies a connection mapper arg.
GLenum const void GLuint GLint reference
Definition: glew.h:13927
SDF_API const SdfPath & GetTargetPath() const
GLenum GLsizei const void * pathString
Definition: glew.h:13919
SDF_API bool IsPrimPropertyPath() const
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
SdfPathAncestorsRange(const SdfPath &path)
Definition: path.h:1039
SDF_API TfToken GetAsToken() const
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNodeHandleImpl &&rhs) noexcept
Definition: path.h:131
bool operator==(const iterator &o) const
Definition: path.h:1062
static SDF_API void RemoveDescendentPaths(SdfPathVector *paths)
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:417
bool operator==(Sdf_PathNodeHandleImpl const &rhs) const noexcept
Definition: path.h:169
SdfPath() noexcept
Definition: path.h:306
GLuint const GLchar * name
Definition: glcorearb.h:785
Sdf_PathNodeHandleImpl(Sdf_PathNode const *p, bool add_ref=true)
Definition: path.h:88
SdfPath const & operator()(SdfPath const &arg) const
Definition: path.h:1097
size_t GetHash() const
Definition: path.h:920
SDF_API std::pair< std::string, std::string > GetVariantSelection() const
SDF_API SdfPath StripAllVariantSelections() const
bool operator!=(const iterator &o) const
Definition: path.h:1064
SDF_API SdfPath AppendRelationalAttribute(TfToken const &attrName) const
Definition: hash.h:447
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)
Definition: path.h:103
const SdfPath & operator*() const
Definition: path.h:1058
Definition: token.h:87
GLuint64EXT * result
Definition: glew.h:14311
bool operator<(const SdfPath &rhs) const
Definition: path.h:891
void swap(Sdf_PathNodeHandleImpl &rhs) noexcept
Definition: path.h:165
friend void TfHashAppend(HashState &h, SdfPath const &path)
Definition: path.h:903
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
SDF_API void GetAllTargetPathsRecursively(SdfPathVector *result) const
bool ContainsPropertyElements() const
Definition: path.h:390
SDF_API bool IsPrimVariantSelectionPath() const
bool operator!=(Sdf_PathNodeHandleImpl const &rhs) const noexcept
Definition: path.h:172
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
Definition: path.h:152
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
GLuint GLuint end
Definition: glcorearb.h:474
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
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.
GLfloat GLfloat p
Definition: glew.h:16656
static SDF_API std::string JoinIdentifier(const std::vector< std::string > &names)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
GLuint const GLuint * names
Definition: glew.h:2695
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.
Definition: stl.h:391
Definition: path.h:288
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
Definition: path.h:915
Sdf_PathPrimPartPool::Handle Sdf_PathPrimHandle
Definition: path.h:75
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNode const *rhs) noexcept
Definition: path.h:137
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:209
constexpr Sdf_PathNodeHandleImpl() noexcept
Definition: path.h:85
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.
Definition: path.h:207
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
Definition: core.h:1640
SDF_API SdfPath AppendProperty(TfToken const &propName) const
SDF_API bool ContainsPrimVariantSelection() const
hboost::intrusive_ptr< const Sdf_PathNode > Sdf_PathNodeConstRefPtr
Definition: path.h:49
std::forward_iterator_tag iterator_category
Definition: path.h:1045
#define SDF_API
Definition: api.h:40
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
bool operator<(Sdf_PathNodeHandleImpl const &rhs) const noexcept
Definition: path.h:175
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
Definition: path.h:1375
const SdfPath * operator->() const
Definition: path.h:1060
SDF_API SdfPathAncestorsRange GetAncestorsRange() const
SDF_API SdfPath GetCommonPrefix(const SdfPath &path) const
SDF_API TfToken const & GetToken() const
SDF_API bool IsTargetPath() const
iterator end() const
Definition: path.h:1078
Sdf_PathNodeHandleImpl & operator=(Sdf_PathNodeHandleImpl const &rhs)
Definition: path.h:117
SDF_API std::pair< SdfPath, SdfPath > RemoveCommonSuffix(const SdfPath &otherPath, bool stopAtRootPrim=false) const
size_t hash_value(SdfPath const &path)
Definition: path.h:1086
SDF_API bool IsRootPrimPath() const
SDF_API SdfPath AppendPath(const SdfPath &newSuffix) const
SDF_API std::string GetAsString() const
const SdfPath & GetPath() const
Definition: path.h:1042
iterator begin() const
Definition: path.h:1076
void intrusive_ptr_release(Sdf_PathNode const *)
SDF_API SdfPath MakeAbsolutePath(const SdfPath &anchor) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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
Definition: glcorearb.h:823
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())
Definition: path.h:1227
static SDF_API void RemoveAncestorPaths(SdfPathVector *paths)
#define const
Definition: zconf.h:214
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())
Definition: path.h:1253
Sdf_PathNode const * operator->() const
Definition: path.h:157
Sdf_PathNodeHandleImpl(Sdf_PathNodeHandleImpl &&rhs) noexcept
Definition: path.h:125
SDF_API SdfPathVector GetPrefixes() const
static SDF_API std::string StripNamespace(const std::string &name)
friend struct Handle
Definition: pool.h:94
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
Definition: path.h:927
VT_TYPE_IS_CHEAP_TO_COPY(class SdfPath)
Definition: pool.h:79
std::ptrdiff_t difference_type
Definition: path.h:1047
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
Definition: glew.h:13872
void * Handle
Definition: plugin.h:27
static SDF_API TfTokenVector TokenizeIdentifierAsTokens(const std::string &name)