HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
prim.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_PRIM_H
8 #define PXR_USD_USD_PRIM_H
9 
10 /// \file usd/prim.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/usd/common.h"
15 #include "pxr/usd/usd/object.h"
16 #include "pxr/usd/usd/primFlags.h"
18 
19 #include "pxr/usd/sdf/schema.h"
20 #include "pxr/base/trace/trace.h"
21 
23 #include "pxr/base/tf/refBase.h"
24 #include "pxr/base/tf/token.h"
25 #include "pxr/base/tf/weakBase.h"
26 
27 #include "pxr/usd/sdf/path.h"
28 
29 #include <iterator>
30 #include <string>
31 #include <type_traits>
32 #include <vector>
33 
35 
36 class UsdPrim;
37 class UsdPrimDefinition;
38 class UsdPrimRange;
39 class Usd_PrimData;
40 
41 class UsdAttribute;
42 class UsdEditTarget;
43 class UsdRelationship;
44 class UsdPayloads;
45 class UsdReferences;
46 class UsdResolveTarget;
47 class UsdSchemaBase;
48 class UsdAPISchemaBase;
49 class UsdInherits;
50 class UsdSpecializes;
51 class UsdVariantSets;
52 class UsdVariantSet;
53 
54 class SdfPayload;
55 
58 
61 
62 /// \class UsdPrim
63 ///
64 /// UsdPrim is the sole persistent scenegraph object on a UsdStage, and
65 /// is the embodiment of a "Prim" as described in the <em>Universal Scene
66 /// Description Composition Compendium</em>
67 ///
68 /// A UsdPrim is the principal container of other types of scene description.
69 /// It provides API for accessing and creating all of the contained kinds
70 /// of scene description, which include:
71 /// \li UsdVariantSets - all VariantSets on the prim (GetVariantSets(), GetVariantSet())
72 /// \li UsdReferences - all references on the prim (GetReferences())
73 /// \li UsdInherits - all inherits on the prim (GetInherits())
74 /// \li UsdSpecializes - all specializes on the prim (GetSpecializes())
75 ///
76 /// As well as access to the API objects for properties contained within the
77 /// prim - UsdPrim as well as all of the following classes are subclasses
78 /// of UsdObject:
79 /// \li UsdProperty - generic access to all attributes and relationships.
80 /// A UsdProperty can be queried and cast to a UsdAttribute or UsdRelationship
81 /// using UsdObject::Is<>() and UsdObject::As<>(). (GetPropertyNames(),
82 /// GetProperties(), GetPropertiesInNamespace(), GetPropertyOrder(),
83 /// SetPropertyOrder())
84 /// \li UsdAttribute - access to default and timesampled attribute values, as
85 /// well as value resolution information, and attribute-specific metadata
86 /// (CreateAttribute(), GetAttribute(), GetAttributes(), HasAttribute())
87 /// \li UsdRelationship - access to authoring and resolving relationships
88 /// to other prims and properties (CreateRelationship(), GetRelationship(),
89 /// GetRelationships(), HasRelationship())
90 ///
91 /// UsdPrim also provides access to iteration through its prim children,
92 /// optionally making use of the \ref primFlags.h "prim predicates facility"
93 /// (GetChildren(), GetAllChildren(), GetFilteredChildren()).
94 ///
95 /// \section UsdPrim_Lifetime_Management Lifetime Management
96 ///
97 /// Clients acquire UsdPrim objects, which act like weak/guarded pointers
98 /// to persistent objects owned and managed by their originating UsdStage.
99 /// We provide the following guarantees for a UsdPrim acquired via
100 /// UsdStage::GetPrimAtPath() or UsdStage::OverridePrim() or
101 /// UsdStage::DefinePrim():
102 /// \li As long as no further mutations to the structure of the UsdStage
103 /// are made, the UsdPrim will still be valid. Loading and
104 /// Unloading are considered structural mutations.
105 /// \li When the UsdStage's structure \em is mutated, the thread performing
106 /// the mutation will receive a UsdNotice::ObjectsChanged notice
107 /// after the stage has been reconfigured, which provides details as to
108 /// what prims may have been created or destroyed, and what prims
109 /// may simply have changed in some structural way.
110 ///
111 /// Prim access in "reader" threads should be limited to GetPrimAtPath(), which
112 /// will never cause a mutation to the Stage or its layers.
113 ///
114 /// Please refer to \ref UsdNotice for a listing of
115 /// the events that could cause UsdNotice::ObjectsChanged to be emitted.
116 class UsdPrim : public UsdObject
117 {
118 public:
119  /// Convenience typedefs.
122 
123  /// Convenience typedefs.
126 
127  /// Construct an invalid prim.
129 
130  /// Return the prim's full type info composed from its type name, applied
131  /// API schemas, and any fallback types defined on the stage for
132  /// unrecognized prim type names. The returned type structure contains the
133  /// "true" schema type used to create this prim's prim definition and answer
134  /// the IsA query. This value is cached and efficient to query. The cached
135  /// values are guaranteed to exist for (at least) as long as the prim's
136  /// stage is open.
137  /// \sa GetTypeName
138  /// \sa GetAppliedSchemas
139  /// \sa \ref Usd_OM_FallbackPrimTypes
141  return _Prim()->GetPrimTypeInfo();
142  }
143 
144  /// Return this prim's definition based on the prim's type if the type
145  /// is a registered prim type. Returns an empty prim definition if it is
146  /// not.
148  return _Prim()->GetPrimDefinition();
149  }
150 
151  /// Return this prim's composed specifier.
152  SdfSpecifier GetSpecifier() const { return _Prim()->GetSpecifier(); };
153 
154  /// Return all the authored SdfPrimSpecs that may contain opinions for this
155  /// prim in order from strong to weak.
156  ///
157  /// This does not include all the places where contributing prim specs could
158  /// potentially be created; rather, it includes only those prim specs that
159  /// already exist. To discover all the places that prim specs could be
160  /// authored that would contribute opinions, see
161  /// \ref "Composition Structure"
162  ///
163  /// \note Use this method for debugging and diagnostic purposes. It is
164  /// **not** advisable to retain a PrimStack for expedited metadata value
165  /// resolution, since not all metadata resolves with simple "strongest
166  /// opinion wins" semantics.
167  USD_API
168  SdfPrimSpecHandleVector GetPrimStack() const;
169 
170  /// Return all the authored SdfPrimSpecs that may contain opinions for this
171  /// prim in order from strong to weak paired with the cumulative layer
172  /// offset from the stage's root layer to the layer containing the prim
173  /// spec.
174  ///
175  /// This behaves exactly the same as UsdPrim::GetPrimStack with the
176  /// addition of providing the cumulative layer offset of each spec's layer.
177  ///
178  /// \note Use this method for debugging and diagnostic purposes. It is
179  /// **not** advisable to retain a PrimStack for expedited metadata value
180  /// resolution, since not all metadata resolves with simple "strongest
181  /// opinion wins" semantics.
182  USD_API
183  std::vector<std::pair<SdfPrimSpecHandle, SdfLayerOffset>>
185 
186  /// Author an opinion for this Prim's specifier at the current edit
187  /// target.
188  bool SetSpecifier(SdfSpecifier specifier) const {
189  return SetMetadata(SdfFieldKeys->Specifier, specifier);
190  }
191 
192  /// Return this prim's composed type name. This value is cached and is
193  /// efficient to query.
194  /// Note that this is just the composed type name as authored and may not
195  /// represent the full type of the prim and its prim definition. If you
196  /// need to reason about the actual type of the prim, use GetPrimTypeInfo
197  /// instead as it accounts for recognized schemas, applied API schemas,
198  /// fallback types, etc.
199  const TfToken &GetTypeName() const { return _Prim()->GetTypeName(); };
200 
201  /// Author this Prim's typeName at the current EditTarget.
202  bool SetTypeName(const TfToken & typeName) const {
203  return SetMetadata(SdfFieldKeys->TypeName, typeName);
204  }
205 
206  /// Clear the opinion for this Prim's typeName at the current edit
207  /// target.
208  bool ClearTypeName() const {
209  return ClearMetadata(SdfFieldKeys->TypeName);
210  }
211 
212  /// Return true if a typeName has been authored.
213  bool HasAuthoredTypeName() const {
214  return HasAuthoredMetadata(SdfFieldKeys->TypeName);
215  }
216 
217  /// Return true if this prim is active, meaning neither it nor any of its
218  /// ancestors have active=false. Return false otherwise.
219  ///
220  /// See \ref Usd_ActiveInactive for what it means for a prim to be active.
221  bool IsActive() const { return _Prim()->IsActive(); }
222 
223  /// Author 'active' metadata for this prim at the current EditTarget.
224  ///
225  /// See \ref Usd_ActiveInactive for the effects of activating or deactivating
226  /// a prim.
227  bool SetActive(bool active) const {
228  return SetMetadata(SdfFieldKeys->Active, active);
229  }
230 
231  /// Remove the authored 'active' opinion at the current EditTarget. Do
232  /// nothing if there is no authored opinion.
233  ///
234  /// See \ref Usd_ActiveInactive for the effects of activating or deactivating
235  /// a prim.
236  bool ClearActive() const {
237  return ClearMetadata(SdfFieldKeys->Active);
238  }
239 
240  /// Return true if this prim has an authored opinion for 'active', false
241  /// otherwise.
242  ///
243  /// See \ref Usd_ActiveInactive for what it means for a prim to be active.
244  bool HasAuthoredActive() const {
245  return HasAuthoredMetadata(SdfFieldKeys->Active);
246  }
247 
248  /// Return true if this prim is active, and \em either it is loadable and
249  /// it is loaded, \em or its nearest loadable ancestor is loaded, \em or it
250  /// has no loadable ancestor; false otherwise.
251  bool IsLoaded() const { return _Prim()->IsLoaded(); }
252 
253  /// Return true if this prim is a model based on its kind metadata, false
254  /// otherwise.
255  bool IsModel() const { return _Prim()->IsModel(); }
256 
257  /// Return true if this prim is a model group based on its kind metadata,
258  /// false otherwise. If this prim is a group, it is also necessarily a
259  /// model.
260  ///
261  /// Note that pseudoroot is always a group (in order to respect model
262  /// hierarchy rules), even though it cannot have a kind.
263  bool IsGroup() const { return _Prim()->IsGroup(); }
264 
265  /// Return true if this prim is a component model based on its kind
266  /// metadata, false otherwise. If this prim is a component, it is also
267  /// necessarily a model.
268  bool IsComponent() const { return _Prim()->IsComponent(); }
269 
270  /// Return true if this prim is a subcomponent based on its kind metadata,
271  /// false otherwise.
272  ///
273  /// Note that subcomponent query is not cached because we only cache
274  /// model-hierarchy-related information, and therefore will be considerably
275  /// slower than other kind-based queries.
276  USD_API
277  bool IsSubComponent() const { return _Prim()->IsSubComponent(); }
278 
279  /// Return true if this prim or any of its ancestors is a class.
280  bool IsAbstract() const { return _Prim()->IsAbstract(); }
281 
282  /// Return true if this prim and all its ancestors have defining specifiers,
283  /// false otherwise. \sa SdfIsDefiningSpecifier.
284  bool IsDefined() const { return _Prim()->IsDefined(); }
285 
286  /// Return true if this prim has the specifier SdfSpecifierClass.
287  bool HasClassSpecifier() const {
288  return _Prim()->HasClassSpecifier();
289  }
290 
291  /// Return true if this prim has the specifier SdfSpecifierDef or
292  /// SdfSpecifierClass. \sa SdfIsDefiningSpecifier
293  bool HasDefiningSpecifier() const {
294  return _Prim()->HasDefiningSpecifier();
295  }
296 
297  /// Return a vector containing the names of API schemas which have
298  /// been applied to this prim.
299  ///
300  /// The returned vector includes both the authored API schemas applied using
301  /// the Apply() method on the particular schema class as well as any
302  /// built-in API schemas that are automatically included through the prim
303  /// type's prim definition.
304  ///
305  /// To get only the authored API schemas use GetPrimTypeInfo instead.
306  USD_API
307  const TfTokenVector &GetAppliedSchemas() const;
308 
309  /// Alias for the "predicate" function parameter passed into the various
310  /// Get{Authored}{PropertyNames,Properties} methods.
311  using PropertyPredicateFunc =
312  std::function<bool (const TfToken &propertyName)>;
313 
314  /// Return all of this prim's property names (attributes and relationships),
315  /// including all builtin properties.
316  ///
317  /// If a valid \p predicate is passed in, then only properties whose names
318  /// pass the predicate are included in the result. This is useful if the
319  /// client is interested only in a subset of properties on the prim. For
320  /// example, only the ones in a given namespace or only the ones needed to
321  /// compute a value.
322  ///
323  /// \sa GetAuthoredPropertyNames()
324  /// \sa UsdProperty::IsAuthored()
325  USD_API
327  const PropertyPredicateFunc &predicate={}) const;
328 
329  /// Return this prim's property names (attributes and relationships) that
330  /// have authored scene description, ordered according to the strongest
331  /// propertyOrder statement in scene description if one exists, otherwise
332  /// ordered according to TfDictionaryLessThan.
333  ///
334  /// If a valid \p predicate is passed in, then only the authored properties
335  /// whose names pass the predicate are included in the result. This is
336  /// useful if the client is interested only in a subset of authored
337  /// properties on the prim. For example, only the ones in a given namespace
338  /// or only the ones needed to compute a value.
339  ///
340  /// \sa GetPropertyNames()
341  /// \sa UsdProperty::IsAuthored()
342  USD_API
344  const PropertyPredicateFunc &predicate={}) const;
345 
346  /// Return all of this prim's properties (attributes and relationships),
347  /// including all builtin properties, ordered by name according to the
348  /// strongest propertyOrder statement in scene description if one exists,
349  /// otherwise ordered according to TfDictionaryLessThan.
350  ///
351  /// If a valid \p predicate is passed in, then only properties whose names
352  /// pass the predicate are included in the result. This is useful if the
353  /// client is interested only in a subset of properties on the prim. For
354  /// example, only the ones in a given namespace or only the ones needed to
355  /// compute a value.
356  ///
357  /// To obtain only either attributes or relationships, use either
358  /// GetAttributes() or GetRelationships().
359  ///
360  /// To determine whether a property is either an attribute or a
361  /// relationship, use the UsdObject::As() and UsdObject::Is() methods in
362  /// C++:
363  ///
364  /// \code
365  /// // Use As<>() to obtain a subclass instance.
366  /// if (UsdAttribute attr = property.As<UsdAttribute>()) {
367  /// // use attribute 'attr'.
368  /// else if (UsdRelationship rel = property.As<UsdRelationship>()) {
369  /// // use relationship 'rel'.
370  /// }
371  ///
372  /// // Use Is<>() to discriminate only.
373  /// if (property.Is<UsdAttribute>()) {
374  /// // property is an attribute.
375  /// }
376  /// \endcode
377  ///
378  /// In Python, use the standard isinstance() function:
379  ///
380  /// \code
381  /// if isinstance(property, Usd.Attribute):
382  /// # property is a Usd.Attribute.
383  /// elif isinstance(property, Usd.Relationship):
384  /// # property is a Usd.Relationship.
385  /// \endcode
386  ///
387  /// \sa GetAuthoredProperties()
388  /// \sa UsdProperty::IsAuthored()
389  USD_API
390  std::vector<UsdProperty> GetProperties(
391  const PropertyPredicateFunc &predicate={}) const;
392 
393  /// Return this prim's properties (attributes and relationships) that have
394  /// authored scene description, ordered by name according to the strongest
395  /// propertyOrder statement in scene description if one exists, otherwise
396  /// ordered according to TfDictionaryLessThan.
397  ///
398  /// If a valid \p predicate is passed in, then only authored properties
399  /// whose names pass the predicate are included in the result. This is
400  /// useful if the client is interested only in a subset of authored
401  /// properties on the prim. For example, only the ones in a given namespace
402  /// or only the ones needed to compute a value.
403  ///
404  /// \sa GetProperties()
405  /// \sa UsdProperty::IsAuthored()
406  USD_API
407  std::vector<UsdProperty> GetAuthoredProperties(
408  const PropertyPredicateFunc &predicate={}) const;
409 
410  /// Return this prim's properties that are inside the given property
411  /// namespace ordered according to the strongest propertyOrder statement in
412  /// scene description if one exists, otherwise ordered according to
413  /// TfDictionaryLessThan.
414  ///
415  /// A \p namespaces argument whose elements are ["ri", "attribute"] will
416  /// return all the properties under the namespace "ri:attribute",
417  /// i.e. "ri:attribute:*". An empty \p namespaces argument is equivalent to
418  /// GetProperties().
419  ///
420  /// For details of namespaced properties, see \ref Usd_Ordering
421  USD_API
422  std::vector<UsdProperty>
423  GetPropertiesInNamespace(const std::vector<std::string> &namespaces) const;
424 
425  /// \overload
426  /// \p namespaces must be an already-concatenated ordered set of namespaces,
427  /// and may or may not terminate with the namespace-separator character. If
428  /// \p namespaces is empty, this method is equivalent to GetProperties().
429  USD_API
430  std::vector<UsdProperty>
431  GetPropertiesInNamespace(const std::string &namespaces) const;
432 
433  /// Like GetPropertiesInNamespace(), but exclude properties that do not have
434  /// authored scene description from the result. See
435  /// UsdProperty::IsAuthored().
436  ///
437  /// For details of namespaced properties, see \ref Usd_Ordering
438  USD_API
439  std::vector<UsdProperty>
441  const std::vector<std::string> &namespaces) const;
442 
443  /// \overload
444  /// \p namespaces must be an already-concatenated ordered set of namespaces,
445  /// and may or may not terminate with the namespace-separator character. If
446  /// \p namespaces is empty, this method is equivalent to
447  /// GetAuthoredProperties().
448  USD_API
449  std::vector<UsdProperty>
450  GetAuthoredPropertiesInNamespace(const std::string &namespaces) const;
451 
452  /// Return the strongest propertyOrder metadata value authored on this prim.
453  USD_API
455 
456  /// Author an opinion for propertyOrder metadata on this prim at the current
457  /// EditTarget.
458  void SetPropertyOrder(const TfTokenVector &order) const {
459  SetMetadata(SdfFieldKeys->PropertyOrder, order);
460  }
461 
462  /// Change the order of items in 'names' so that all the things in 'order'
463  /// that are also in 'names' are at the beginning in the order that they
464  /// appear in 'order', followed by any remaining items in 'names' in their
465  /// existing order.
466  USD_API
467  static void
469 
470  /// Remove the opinion for propertyOrder metadata on this prim at the current
471  /// EditTarget.
472  void ClearPropertyOrder() const {
473  ClearMetadata(SdfFieldKeys->PropertyOrder);
474  }
475 
476  /// Remove all scene description for the property with the
477  /// given \p propName <em>in the current UsdEditTarget</em>.
478  /// Return true if the property is removed, false otherwise.
479  ///
480  /// Because this method can only remove opinions about the property from
481  /// the current EditTarget, you may generally find it more useful to use
482  /// UsdAttribute::Block(), which will ensure that all values from the
483  /// EditTarget and weaker layers for the property will be ignored, or
484  /// UsdAttribute::BlockAnimation(), which will ensure that all timeSamples
485  /// or spline values from the EditTarget and weaker layers for the property
486  /// will be ignored.
487  USD_API
488  bool RemoveProperty(const TfToken &propName);
489 
490  /// Return a UsdProperty with the name \a propName. The property
491  /// returned may or may not \b actually exist so it must be checked for
492  /// validity. Suggested use:
493  ///
494  /// \code
495  /// if (UsdProperty myProp = prim.GetProperty("myProp")) {
496  /// // myProp is safe to use.
497  /// // Edits to the owning stage requires subsequent validation.
498  /// } else {
499  /// // myProp was not defined/authored
500  /// }
501  /// \endcode
502  USD_API
503  UsdProperty GetProperty(const TfToken &propName) const;
504 
505  /// Return true if this prim has an property named \p propName, false
506  /// otherwise.
507  USD_API
508  bool HasProperty(const TfToken &propName) const;
509 
510  /// Retrieve the authored \p kind for this prim.
511  ///
512  /// To test whether the returned \p kind matches a particular known
513  /// "clientKind":
514  /// \code
515  /// TfToken kind;
516  ///
517  /// bool isClientKind = prim.GetKind(&kind) and
518  /// KindRegistry::IsA(kind, clientKind);
519  /// \endcode
520  ///
521  /// \return true if there was an authored kind that was successfully read,
522  /// otherwise false. Note that this will return false for pseudoroot even
523  /// though pseudoroot is always a group, without any kind (in order to
524  /// respect model hierarchy rules)
525  ///
526  /// \sa \ref mainpage_kind "The Kind module" for further details on
527  /// how to use Kind for classification, and how to extend the taxonomy.
528  USD_API
529  bool GetKind(TfToken *kind) const;
530 
531  /// Author a \p kind for this prim, at the current UsdEditTarget.
532  /// \return true if \p kind was successully authored, otherwise false.
533  USD_API
534  bool SetKind(const TfToken &kind) const;
535 
536 private:
537  // Helper functions for the public schema query and API schema
538  // authoring functions. The public functions have overloads that take
539  // a type, an identifier, or a family which all are used to find the
540  // SchemaInfo from the schema registry.
541  USD_API
542  bool _IsA(const UsdSchemaRegistry::SchemaInfo *schemaInfo) const;
543 
544  USD_API
545  bool _HasAPI(const UsdSchemaRegistry::SchemaInfo *schemaInfo) const;
546 
547  USD_API
548  bool _HasAPIInstance(
549  const UsdSchemaRegistry::SchemaInfo *schemaInfo,
550  const TfToken &instanceName) const;
551 
552  USD_API
553  bool _CanApplySingleApplyAPI(
554  const UsdSchemaRegistry::SchemaInfo &schemaInfo,
555  std::string *whyNot) const;
556 
557  USD_API
558  bool _CanApplyMultipleApplyAPI(
559  const UsdSchemaRegistry::SchemaInfo &schemaInfo,
560  const TfToken& instanceName,
561  std::string *whyNot) const;
562 
563  USD_API
564  bool _ApplySingleApplyAPI(
565  const UsdSchemaRegistry::SchemaInfo &schemaInfo) const;
566 
567  USD_API
568  bool _ApplyMultipleApplyAPI(
569  const UsdSchemaRegistry::SchemaInfo &schemaInfo,
570  const TfToken &instanceName) const;
571 
572  USD_API
573  bool _RemoveSingleApplyAPI(
574  const UsdSchemaRegistry::SchemaInfo &schemaInfo) const;
575 
576  USD_API
577  bool _RemoveMultipleApplyAPI(
578  const UsdSchemaRegistry::SchemaInfo &schemaInfo,
579  const TfToken &instanceName) const;
580 
581 public:
582  /// \name IsA
583  ///
584  /// @{
585 
586  /// Return true if the prim's schema type, is or inherits from the TfType
587  /// of the schema class type \p SchemaType.
588  ///
589  /// \sa GetPrimTypeInfo
590  /// \sa UsdPrimTypeInfo::GetSchemaType
591  /// \sa \ref Usd_OM_FallbackPrimTypes
592  template <typename SchemaType>
593  bool IsA() const {
595  "Provided type must derive UsdSchemaBase.");
596  return _IsA(UsdSchemaRegistry::FindSchemaInfo<SchemaType>());
597  };
598 
599  /// This is an overload of \ref IsA that takes a TfType \p schemaType .
600  USD_API
601  bool IsA(const TfType& schemaType) const;
602 
603  /// This is an overload of \ref IsA that takes a \p schemaIdentifier to
604  /// determine the schema type.
605  USD_API
606  bool IsA(const TfToken& schemaIdentifier) const;
607 
608  /// This is an overload of \ref IsA that takes a \p schemaFamily and
609  /// \p schemaVersion to determine the schema type.
610  USD_API
611  bool IsA(const TfToken& schemaFamily,
612  UsdSchemaVersion schemaVersion) const;
613 
614  /// @}
615 
616  /// \name IsInFamily
617  ///
618  /// @{
619 
620  /// Return true if the prim's schema type is or inherits from the schema
621  /// type of any version of the schemas in the given \p schemaFamily.
622  USD_API
623  bool IsInFamily(const TfToken &schemaFamily) const;
624 
625  /// Return true if the prim's schema type, is or inherits from the schema
626  /// type of any schema in the given \p schemaFamily that matches the version
627  /// filter provided by \p schemaVersion and \p versionPolicy.
628  USD_API
629  bool IsInFamily(
630  const TfToken &schemaFamily,
631  UsdSchemaVersion schemaVersion,
632  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
633 
634  /// Overload for convenience of
635  /// \ref IsInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "IsInFamily"
636  /// that finds a registered schema for the C++ schema class \p SchemaType
637  /// and uses that schema's family and version.
638  template <typename SchemaType>
640  UsdSchemaRegistry::VersionPolicy versionPolicy) const {
642  "Provided type must derive UsdSchemaBase.");
643  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
644  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
645  if (!schemaInfo) {
646  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
647  "UsdSchemaRegistry as a schema type. The schema may need to be "
648  "regenerated.",
649  TfType::Find<SchemaType>().GetTypeName().c_str());
650  return false;
651  }
652  return IsInFamily(schemaInfo->family, schemaInfo->version,
653  versionPolicy);
654  };
655 
656  /// Overload for convenience of
657  /// \ref IsInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "IsInFamily"
658  /// that finds a registered schema for the given \p schemaType and uses that
659  /// schema's family and version.
660  USD_API
661  bool IsInFamily(
662  const TfType &schemaType,
663  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
664 
665  /// Overload for convenience of
666  /// \ref IsInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "IsInFamily"
667  /// that parses the schema family and version to use from the given
668  /// \p schemaIdentifier.
669  ///
670  /// Note that the schema identifier is not required to be a registered
671  /// schema as it only parsed to get what its family and version would be
672  /// See UsdSchemaRegistry::ParseSchemaFamilyAndVersionFromIdentifier.
673  USD_API
674  bool IsInFamily(
675  const TfToken &schemaIdentifier,
676  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
677 
678  /// Return true if the prim's schema type, is or inherits from the schema
679  /// type of any version the schema in the given \p schemaFamily and if so,
680  /// populates \p schemaVersion with the version of the schema that this
681  /// prim \ref IsA.
682  USD_API
684  const TfToken &schemaFamily,
685  UsdSchemaVersion *schemaVersion) const;
686 
687  /// @}
688 
689  /// \name HasAPI
690  ///
691  /// __Using HasAPI in C++__
692  /// \code
693  /// UsdPrim prim = stage->OverridePrim("/path/to/prim");
694  /// MyDomainBozAPI = MyDomainBozAPI::Apply(prim);
695  /// assert(prim.HasAPI<MyDomainBozAPI>());
696  /// assert(prim.HasAPI(TfToken("BozAPI")));
697  /// assert(prim.HasAPI(TfToken("BozAPI"), /*schemaVersion*/ 0));
698  ///
699  /// UsdCollectionAPI collAPI = UsdCollectionAPI::Apply(prim,
700  /// /*instanceName*/ TfToken("geom"));
701  /// assert(prim.HasAPI<UsdCollectionAPI>();
702  /// assert(prim.HasAPI(TfToken("CollectionAPI"));
703  /// assert(prim.HasAPI(TfToken("CollectionAPI"), /*schemaVersion*/ 0);
704  ///
705  /// assert(prim.HasAPI<UsdCollectionAPI>(/*instanceName*/ TfToken("geom")))
706  /// assert(prim.HasAPI(TfToken("CollectionAPI",
707  /// /*instanceName*/ TfToken("geom")));
708  /// assert(prim.HasAPI(TfToken("CollectionAPI"), /*schemaVersion*/ 0,
709  /// /*instanceName*/ TfToken("geom"));
710  /// \endcode
711  ///
712  /// The python version of this method takes as an argument the TfType
713  /// of the API schema class.
714  ///
715  /// __Using HasAPI in Python__
716  /// \code{.py}
717  /// prim = stage.OverridePrim("/path/to/prim")
718  /// bozAPI = MyDomain.BozAPI.Apply(prim)
719  /// assert(prim.HasAPI(MyDomain.BozAPI))
720  /// assert(prim.HasAPI("BozAPI"))
721  /// assert(prim.HasAPI("BozAPI", 0))
722  ///
723  /// collAPI = Usd.CollectionAPI.Apply(prim, "geom")
724  /// assert(prim.HasAPI(Usd.CollectionAPI))
725  /// assert(prim.HasAPI("CollectionAPI"))
726  /// assert(prim.HasAPI("CollectionAPI", 0))
727  ///
728  /// assert(prim.HasAPI(Usd.CollectionAPI, instanceName="geom"))
729  /// assert(prim.HasAPI("CollectionAPI", instanceName="geom"))
730  /// assert(prim.HasAPI("CollectionAPI", 0, instanceName="geom"))
731  /// \endcode
732  ///
733  /// @{
734 
735  /// Return true if the UsdPrim has had an applied API schema represented by
736  /// the C++ class type \p SchemaType applied to it.
737  ///
738  /// This function works for both single-apply and multiple-apply API schema
739  /// types. If the schema is a multiple-apply API schema this will return
740  /// true if any instance of the multiple-apply API has been applied.
741  template <typename SchemaType>
742  bool
743  HasAPI() const {
745  "Provided type must derive UsdAPISchemaBase.");
747  "Provided type must not be UsdAPISchemaBase.");
748  static_assert(
749  SchemaType::schemaKind == UsdSchemaKind::SingleApplyAPI ||
750  SchemaType::schemaKind == UsdSchemaKind::MultipleApplyAPI,
751  "Provided schema type must be an applied API schema.");
752 
753  return _HasAPI(UsdSchemaRegistry::FindSchemaInfo<SchemaType>());
754  }
755 
756  /// Return true if the UsdPrim has the specific instance, \p instanceName,
757  /// of the multiple-apply API schema represented by the C++ class type
758  /// \p SchemaType applied to it.
759  ///
760  /// \p instanceName must be non-empty, otherwise it is a coding error.
761  template <typename SchemaType>
762  bool
763  HasAPI(const TfToken &instanceName) const {
765  "Provided type must derive UsdAPISchemaBase.");
767  "Provided type must not be UsdAPISchemaBase.");
768  static_assert(SchemaType::schemaKind == UsdSchemaKind::MultipleApplyAPI,
769  "Provided schema type must be a multi apply API schema.");
770 
771  return _HasAPIInstance(
772  UsdSchemaRegistry::FindSchemaInfo<SchemaType>(), instanceName);
773  }
774 
775  /// This is an overload of \ref HasAPI that takes a TfType \p schemaType .
776  USD_API
777  bool HasAPI(const TfType& schemaType) const;
778 
779  /// This is an overload of \ref HasAPI(const TfToken &) const "HasAPI" with
780  /// \p instanceName that takes a TfType \p schemaType .
781  USD_API
782  bool HasAPI(const TfType& schemaType,
783  const TfToken& instanceName) const;
784 
785  /// This is an overload of \ref HasAPI that takes a \p schemaIdentifier to
786  /// determine the schema type.
787  USD_API
788  bool HasAPI(const TfToken& schemaIdentifier) const;
789 
790  /// This is an overload of \ref HasAPI(const TfToken &) const "HasAPI" with
791  /// \p instanceName that takes a \p schemaIdentifier to determine the schema
792  /// type.
793  USD_API
794  bool HasAPI(const TfToken& schemaIdentifier,
795  const TfToken& instanceName) const;
796 
797  /// This is an overload of \ref HasAPI that takes a \p schemaFamily and
798  /// \p schemaVersion to determine the schema type.
799  USD_API
800  bool HasAPI(const TfToken& schemaFamily,
801  UsdSchemaVersion schemaVersion) const;
802 
803  /// This is an overload of \ref HasAPI(const TfToken &) const "HasAPI" with
804  /// \p instanceName that takes a \p schemaFamily and \p schemaVersion to
805  /// determine the schema type.
806  USD_API
807  bool HasAPI(const TfToken& schemaFamily,
808  UsdSchemaVersion schemaVersion,
809  const TfToken& instanceName) const;
810 
811  /// @}
812 
813  /// \name HasAPIInFamily
814  ///
815  /// @{
816 
817  /// Return true if the prim has an applied API schema that is any version of
818  /// the schemas in the given \p schemaFamily.
819  ///
820  /// This function will consider both single-apply and multiple-apply API
821  /// schemas in the schema family. For the multiple-apply API schemas, this
822  /// will return true if any instance of one of the schemas has been applied.
823  USD_API
824  bool HasAPIInFamily(
825  const TfToken &schemaFamily) const;
826 
827  /// Return true if the prim has a specific instance \p instanceName of an
828  /// applied multiple-apply API schema that is any version the schemas in
829  /// the given \p schemaFamily.
830  ///
831  /// \p instanceName must be non-empty, otherwise it is a coding error.
832  USD_API
833  bool HasAPIInFamily(
834  const TfToken &schemaFamily,
835  const TfToken &instanceName) const;
836 
837  /// Return true if the prim has an applied API schema that is a schema in
838  /// the given \p schemaFamily that matches the version filter provided by
839  /// \p schemaVersion and \p versionPolicy.
840  ///
841  /// This function will consider both single-apply and multiple-apply API
842  /// schemas in the schema family. For the multiple-apply API schemas, this
843  /// will return true if any instance of one of the filter-passing schemas
844  /// has been applied.
845  USD_API
846  bool HasAPIInFamily(
847  const TfToken &schemaFamily,
848  UsdSchemaVersion schemaVersion,
849  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
850 
851  /// Return true if the prim has a specific instance \p instanceName of an
852  /// applied multiple-apply API schema in the given \p schemaFamily that
853  /// matches the version filter provided by \p schemaVersion and
854  /// \p versionPolicy.
855  ///
856  /// \p instanceName must be non-empty, otherwise it is a coding error.
857  USD_API
858  bool HasAPIInFamily(
859  const TfToken &schemaFamily,
860  UsdSchemaVersion schemaVersion,
861  UsdSchemaRegistry::VersionPolicy versionPolicy,
862  const TfToken &instanceName) const;
863 
864  /// Overload for convenience of
865  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "HasAPIInFamily"
866  /// that finds a registered schema for the C++ schema class \p SchemaType
867  /// and uses that schema's family and version.
868  template <typename SchemaType>
870  UsdSchemaRegistry::VersionPolicy versionPolicy) const {
872  "Provided type must derive UsdSchemaBase.");
873  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
874  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
875  if (!schemaInfo) {
876  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
877  "UsdSchemaRegistry as a schema type. The schema may need to be "
878  "regenerated.",
879  TfType::Find<SchemaType>().GetTypeName().c_str());
880  return false;
881  }
882  return HasAPIInFamily(schemaInfo->family, schemaInfo->version,
883  versionPolicy);
884  };
885 
886  /// Overload for convenience of
887  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy, const TfToken &) const "HasAPIInFamily"
888  /// that finds a registered schema for the C++ schema class \p SchemaType
889  /// and uses that schema's family and version.
890  template <typename SchemaType>
892  UsdSchemaRegistry::VersionPolicy versionPolicy,
893  const TfToken &instanceName) const {
895  "Provided type must derive UsdSchemaBase.");
896  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
897  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
898  if (!schemaInfo) {
899  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
900  "UsdSchemaRegistry as a schema type. The schema may need to be "
901  "regenerated.",
902  TfType::Find<SchemaType>().GetTypeName().c_str());
903  return false;
904  }
905  return HasAPIInFamily(schemaInfo->family, schemaInfo->version,
906  versionPolicy, instanceName);
907  };
908 
909  /// Overload for convenience of
910  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "HasAPIInFamily"
911  /// that finds a registered schema for the given \p schemaType and uses that
912  /// schema's family and version.
913  USD_API
914  bool HasAPIInFamily(
915  const TfType &schemaType,
916  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
917 
918  /// Overload for convenience of
919  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy, const TfToken &) const "HasAPIInFamily"
920  /// that finds a registered schema for the given \p schemaType and uses that
921  /// schema's family and version.
922  USD_API
923  bool HasAPIInFamily(
924  const TfType &schemaType,
925  UsdSchemaRegistry::VersionPolicy versionPolicy,
926  const TfToken &instanceName) const;
927 
928  /// Overload for convenience of
929  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy) const "HasAPIInFamily"
930  /// that parses the schema family and version to use from the given
931  /// \p schemaIdentifier.
932  ///
933  /// Note that the schema identifier is not required to be a registered
934  /// schema as it only parsed to get what its family and version would be
935  /// See UsdSchemaRegistry::ParseSchemaFamilyAndVersionFromIdentifier.
936  USD_API
937  bool HasAPIInFamily(
938  const TfToken &schemaIdentifier,
939  UsdSchemaRegistry::VersionPolicy versionPolicy) const;
940 
941  /// Overload for convenience of
942  /// \ref HasAPIInFamily(const TfToken&, UsdSchemaVersion, UsdSchemaRegistry::VersionPolicy, const TfToken &) const "HasAPIInFamily"
943  /// that parses the schema family and version to use from the given
944  /// \p schemaIdentifier.
945  ///
946  /// Note that the schema identifier is not required to be a registered
947  /// schema as it only parsed to get what its family and version would be
948  /// See UsdSchemaRegistry::ParseSchemaFamilyAndVersionFromIdentifier.
949  USD_API
950  bool HasAPIInFamily(
951  const TfToken &schemaIdentifier,
952  UsdSchemaRegistry::VersionPolicy versionPolicy,
953  const TfToken &instanceName) const;
954 
955  /// Return true if the prim has an applied API schema that is any version
956  /// the schemas in the given \p schemaFamily and if so, populates
957  /// \p schemaVersion with the version of the schema that this prim
958  /// \ref HasAPI.
959  ///
960  /// This function will consider both single-apply and multiple-apply API
961  /// schemas in the schema family. For the multiple-apply API schemas is a
962  /// this will return true if any instance of one of the schemas has been
963  /// applied.
964  ///
965  /// Note that if more than one version of the schemas in \p schemaFamily
966  /// are applied to this prim, the highest version number of these schemas
967  /// will be populated in \p schemaVersion.
968  USD_API
969  bool
971  const TfToken &schemaFamily,
972  UsdSchemaVersion *schemaVersion) const;
973 
974  /// Return true if the prim has a specific instance \p instanceName of an
975  /// applied multiple-apply API schema that is any version the schemas in
976  /// the given \p schemaFamily and if so, populates \p schemaVersion with the
977  /// version of the schema that this prim
978  /// \ref HasAPI(const TfToken &) const "HasAPI".
979  ///
980  /// \p instanceName must be non-empty, otherwise it is a coding error.
981  ///
982  /// Note that if more than one version of the schemas in \p schemaFamily
983  /// is multiple-apply and applied to this prim with the given
984  /// \p instanceName, the highest version number of these schemas will be
985  /// populated in \p schemaVersion.
986  USD_API
987  bool
989  const TfToken &schemaFamily,
990  const TfToken &instanceName,
991  UsdSchemaVersion *schemaVersion) const;
992 
993  /// @}
994 
995  /// \name CanApplyAPI
996  ///
997  /// @{
998 
999  /// Returns whether a __single-apply__ API schema with the given C++ type
1000  /// \p SchemaType can be applied to this prim. If the return value is false,
1001  /// and \p whyNot is provided, the reason the schema cannot be applied is
1002  /// written to whyNot.
1003  ///
1004  /// Whether the schema can be applied is determined by the schema type
1005  /// definition which may specify that the API schema can only be applied to
1006  /// certain prim types.
1007  ///
1008  /// The return value of this function only indicates whether it would be
1009  /// valid to apply this schema to the prim. It has no bearing on whether
1010  /// calling ApplyAPI will be successful or not.
1011  template <typename SchemaType>
1012  bool CanApplyAPI(std::string *whyNot = nullptr) const {
1014  "Provided type must derive UsdAPISchemaBase.");
1016  "Provided type must not be UsdAPISchemaBase.");
1017  static_assert(SchemaType::schemaKind == UsdSchemaKind::SingleApplyAPI,
1018  "Provided schema type must be a single apply API schema.");
1019 
1020  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1021  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1022  if (!schemaInfo) {
1023  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1024  "UsdSchemaRegistry as a schema type. The schema may need to be "
1025  "regenerated.",
1026  TfType::Find<SchemaType>().GetTypeName().c_str());
1027  return false;
1028  }
1029  return _CanApplySingleApplyAPI(*schemaInfo, whyNot);
1030  }
1031 
1032  /// Returns whether a __multiple-apply__ API schema with the given C++
1033  /// type \p SchemaType can be applied to this prim with the given
1034  /// \p instanceName. If the return value is false, and \p whyNot is
1035  /// provided, the reason the schema cannot be applied is written to whyNot.
1036  ///
1037  /// Whether the schema can be applied is determined by the schema type
1038  /// definition which may specify that the API schema can only be applied to
1039  /// certain prim types. It also determines whether the instance name is a
1040  /// valid instance name for the multiple apply schema.
1041  ///
1042  /// The return value of this function only indicates whether it would be
1043  /// valid to apply this schema to the prim. It has no bearing on whether
1044  /// calling ApplyAPI will be successful or not.
1045  template <typename SchemaType>
1046  bool CanApplyAPI(const TfToken &instanceName,
1047  std::string *whyNot = nullptr) const {
1049  "Provided type must derive UsdAPISchemaBase.");
1051  "Provided type must not be UsdAPISchemaBase.");
1052  static_assert(SchemaType::schemaKind == UsdSchemaKind::MultipleApplyAPI,
1053  "Provided schema type must be a multiple apply API schema.");
1054 
1055  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1056  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1057  if (!schemaInfo) {
1058  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1059  "UsdSchemaRegistry as a schema type. The schema may need to be "
1060  "regenerated.",
1061  TfType::Find<SchemaType>().GetTypeName().c_str());
1062  return false;
1063  }
1064  return _CanApplyMultipleApplyAPI(*schemaInfo, instanceName, whyNot);
1065  }
1066 
1067  /// This is an overload of \ref CanApplyAPI that takes a TfType
1068  /// \p schemaType .
1069  USD_API
1070  bool CanApplyAPI(const TfType& schemaType,
1071  std::string *whyNot = nullptr) const;
1072 
1073  /// This is an overload of
1074  /// \ref CanApplyAPI(const TfToken &, std::string *) const "CanApplyAPI"
1075  /// with \p instanceName that takes a TfType \p schemaType .
1076  USD_API
1077  bool CanApplyAPI(const TfType& schemaType,
1078  const TfToken& instanceName,
1079  std::string *whyNot = nullptr) const;
1080 
1081  /// This is an overload of \ref CanApplyAPI that takes a \p schemaIdentifier
1082  /// to determine the schema type.
1083  USD_API
1084  bool CanApplyAPI(const TfToken& schemaIdentifier,
1085  std::string *whyNot = nullptr) const;
1086 
1087  /// This is an overload of
1088  /// \ref CanApplyAPI(const TfToken &, std::string *) const "CanApplyAPI"
1089  /// with \p instanceName that takes a \p schemaIdentifier to determine the
1090  /// schema type.
1091  USD_API
1092  bool CanApplyAPI(const TfToken& schemaIdentifier,
1093  const TfToken& instanceName,
1094  std::string *whyNot = nullptr) const;
1095 
1096  /// This is an overload of \ref CanApplyAPI that takes a \p schemaFamily and
1097  /// \p schemaVersion to determine the schema type.
1098  USD_API
1099  bool CanApplyAPI(const TfToken& schemaFamily,
1100  UsdSchemaVersion schemaVersion,
1101  std::string *whyNot = nullptr) const;
1102 
1103  /// This is an overload of
1104  /// \ref CanApplyAPI(const TfToken &, std::string *) const "CanApplyAPI"
1105  /// with \p instanceName that takes a \p schemaFamily and \p schemaVersion
1106  /// to determine the schema type.
1107  USD_API
1108  bool CanApplyAPI(const TfToken& schemaFamily,
1109  UsdSchemaVersion schemaVersion,
1110  const TfToken& instanceName,
1111  std::string *whyNot = nullptr) const;
1112 
1113  /// @}
1114 
1115  /// \name ApplyAPI
1116  ///
1117  /// @{
1118 
1119  /// Applies a __single-apply__ API schema with the given C++ type
1120  /// \p SchemaType to this prim in the current edit target.
1121  ///
1122  /// This information is stored by adding the API schema's name token to the
1123  /// token-valued, listOp metadata \em apiSchemas on this prim.
1124  ///
1125  /// Returns true upon success or if the API schema is already applied in
1126  /// the current edit target.
1127  ///
1128  /// An error is issued and false returned for any of the following
1129  /// conditions:
1130  /// \li this prim is not a valid prim for editing
1131  /// \li this prim is valid, but cannot be reached or overridden in the
1132  /// current edit target
1133  /// \li the schema name cannot be added to the apiSchemas listOp metadata
1134  template <typename SchemaType>
1135  bool ApplyAPI() const {
1137  "Provided type must derive UsdAPISchemaBase.");
1139  "Provided type must not be UsdAPISchemaBase.");
1140  static_assert(SchemaType::schemaKind == UsdSchemaKind::SingleApplyAPI,
1141  "Provided schema type must be a single apply API schema.");
1142 
1143  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1144  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1145  if (!schemaInfo) {
1146  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1147  "UsdSchemaRegistry as a schema type. The schema may need to be "
1148  "regenerated.",
1149  TfType::Find<SchemaType>().GetTypeName().c_str());
1150  return false;
1151  }
1152  return _ApplySingleApplyAPI(*schemaInfo);
1153  }
1154 
1155  /// Applies a __multiple-apply__ API schema with the given C++ type
1156  /// \p SchemaType and instance name \p instanceName to this prim in the
1157  /// current edit target.
1158  ///
1159  /// This information is stored in the token-valued, listOp metadata
1160  /// \em apiSchemas on this prim. For example, if SchemaType is
1161  /// 'UsdCollectionAPI' and \p instanceName is 'plasticStuff', the name
1162  /// 'CollectionAPI:plasticStuff' is added to the 'apiSchemas' listOp
1163  /// metadata.
1164  ///
1165  /// Returns true upon success or if the API schema is already applied with
1166  /// this \p instanceName in the current edit target.
1167  ///
1168  /// An error is issued and false returned for any of the following
1169  /// conditions:
1170  /// \li \p instanceName is empty
1171  /// \li this prim is not a valid prim for editing
1172  /// \li this prim is valid, but cannot be reached or overridden in the
1173  /// current edit target
1174  /// \li the schema name cannot be added to the apiSchemas listOp metadata
1175  template <typename SchemaType>
1176  bool ApplyAPI(const TfToken &instanceName) const {
1178  "Provided type must derive UsdAPISchemaBase.");
1180  "Provided type must not be UsdAPISchemaBase.");
1181  static_assert(SchemaType::schemaKind == UsdSchemaKind::MultipleApplyAPI,
1182  "Provided schema type must be a multiple apply API schema.");
1183 
1184  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1185  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1186  if (!schemaInfo) {
1187  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1188  "UsdSchemaRegistry as a schema type. The schema may need to be "
1189  "regenerated.",
1190  TfType::Find<SchemaType>().GetTypeName().c_str());
1191  return false;
1192  }
1193  return _ApplyMultipleApplyAPI(*schemaInfo, instanceName);
1194  }
1195 
1196  /// This is an overload of \ref ApplyAPI that takes a TfType \p schemaType .
1197  USD_API
1198  bool ApplyAPI(const TfType& schemaType) const;
1199 
1200  /// This is an overload of \ref ApplyAPI(const TfToken &) const "ApplyAPI"
1201  /// with \p instanceName that takes a TfType \p schemaType .
1202  USD_API
1203  bool ApplyAPI(const TfType& schemaType,
1204  const TfToken& instanceName) const;
1205 
1206  /// This is an overload of \ref ApplyAPI that takes a \p schemaIdentifier
1207  /// to determine the schema type.
1208  USD_API
1209  bool ApplyAPI(const TfToken& schemaIdentifier) const;
1210 
1211  /// This is an overload of \ref ApplyAPI(const TfToken &) const "ApplyAPI"
1212  /// with \p instanceName that takes a \p schemaIdentifier to determine the
1213  /// schema type.
1214  USD_API
1215  bool ApplyAPI(const TfToken& schemaIdentifier,
1216  const TfToken& instanceName) const;
1217 
1218  /// This is an overload of \ref ApplyAPI that takes a \p schemaFamily and
1219  /// \p schemaVersion to determine the schema type.
1220  USD_API
1221  bool ApplyAPI(const TfToken& schemaFamily,
1222  UsdSchemaVersion schemaVersion) const;
1223 
1224  /// This is an overload of \ref ApplyAPI(const TfToken &) const "ApplyAPI"
1225  /// with \p instanceName that takes a \p schemaFamily and \p schemaVersion
1226  /// to determine the schema type.
1227  USD_API
1228  bool ApplyAPI(const TfToken& schemaFamily,
1229  UsdSchemaVersion schemaVersion,
1230  const TfToken& instanceName) const;
1231 
1232  /// @}
1233 
1234  /// \name RemoveAPI
1235  ///
1236  /// @{
1237 
1238  /// Removes a __single-apply__ API schema with the given C++ type
1239  /// \p SchemaType from this prim in the current edit target.
1240  ///
1241  /// This is done by removing the API schema's name token from the
1242  /// token-valued, listOp metadata \em apiSchemas on this prim as well as
1243  /// authoring an explicit deletion of schema name from the listOp.
1244  ///
1245  /// Returns true upon success or if the API schema is already deleted in
1246  /// the current edit target.
1247  ///
1248  /// An error is issued and false returned for any of the following
1249  /// conditions:
1250  /// \li this prim is not a valid prim for editing
1251  /// \li this prim is valid, but cannot be reached or overridden in the
1252  /// current edit target
1253  /// \li the schema name cannot be deleted in the apiSchemas listOp metadata
1254  template <typename SchemaType>
1255  bool RemoveAPI() const {
1257  "Provided type must derive UsdAPISchemaBase.");
1259  "Provided type must not be UsdAPISchemaBase.");
1260  static_assert(SchemaType::schemaKind == UsdSchemaKind::SingleApplyAPI,
1261  "Provided schema type must be a single apply API schema.");
1262 
1263  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1264  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1265  if (!schemaInfo) {
1266  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1267  "UsdSchemaRegistry as a schema type. The schema may need to be "
1268  "regenerated.",
1269  TfType::Find<SchemaType>().GetTypeName().c_str());
1270  return false;
1271  }
1272  return _RemoveSingleApplyAPI(*schemaInfo);
1273  }
1274 
1275  /// Removes a __multiple-apply__ API schema with the given C++ type
1276  /// 'SchemaType' and instance name \p instanceName from this prim in the
1277  /// current edit target.
1278  ///
1279  /// This is done by removing the instanced schema name token from the
1280  /// token-valued, listOp metadata \em apiSchemas on this prim as well as
1281  /// authoring an explicit deletion of the name from the listOp. For example,
1282  /// if SchemaType is 'UsdCollectionAPI' and \p instanceName is
1283  /// 'plasticStuff', the name 'CollectionAPI:plasticStuff' is deleted
1284  /// from the 'apiSchemas' listOp metadata.
1285  ///
1286  /// Returns true upon success or if the API schema with this \p instanceName
1287  /// is already deleted in the current edit target.
1288  ///
1289  /// An error is issued and false returned for any of the following
1290  /// conditions:
1291  /// \li \p instanceName is empty
1292  /// \li this prim is not a valid prim for editing
1293  /// \li this prim is valid, but cannot be reached or overridden in the
1294  /// current edit target
1295  /// \li the schema name cannot be deleted in the apiSchemas listOp metadata
1296  template <typename SchemaType>
1297  bool RemoveAPI(const TfToken &instanceName) const {
1299  "Provided type must derive UsdAPISchemaBase.");
1301  "Provided type must not be UsdAPISchemaBase.");
1302  static_assert(SchemaType::schemaKind == UsdSchemaKind::MultipleApplyAPI,
1303  "Provided schema type must be a multiple apply API schema.");
1304 
1305  const UsdSchemaRegistry::SchemaInfo *schemaInfo =
1306  UsdSchemaRegistry::FindSchemaInfo<SchemaType>();
1307  if (!schemaInfo) {
1308  TF_CODING_ERROR("Class '%s' is not correctly registered with the "
1309  "UsdSchemaRegistry as a schema type. The schema may need to be "
1310  "regenerated.",
1311  TfType::Find<SchemaType>().GetTypeName().c_str());
1312  return false;
1313  }
1314  return _RemoveMultipleApplyAPI(*schemaInfo, instanceName);
1315  }
1316 
1317  /// This is an overload of \ref RemoveAPI that takes a TfType \p schemaType .
1318  USD_API
1319  bool RemoveAPI(const TfType& schemaType) const;
1320 
1321  /// This is an overload of \ref RemoveAPI(const TfToken &) const "RemoveAPI"
1322  /// with \p instanceName that takes a TfType \p schemaType .
1323  USD_API
1324  bool RemoveAPI(const TfType& schemaType,
1325  const TfToken& instanceName) const;
1326 
1327  /// This is an overload of \ref RemoveAPI that takes a \p schemaIdentifier
1328  /// to determine the schema type.
1329  USD_API
1330  bool RemoveAPI(const TfToken& schemaIdentifier) const;
1331 
1332  /// This is an overload of \ref RemoveAPI(const TfToken &) const "RemoveAPI"
1333  /// with \p instanceName that takes a \p schemaIdentifier to determine the
1334  /// schema type.
1335  USD_API
1336  bool RemoveAPI(const TfToken& schemaIdentifier,
1337  const TfToken& instanceName) const;
1338 
1339  /// This is an overload of \ref RemoveAPI that takes a \p schemaFamily and
1340  /// \p schemaVersion to determine the schema type.
1341  USD_API
1342  bool RemoveAPI(const TfToken& schemaFamily,
1343  UsdSchemaVersion schemaVersion) const;
1344 
1345  /// This is an overload of \ref RemoveAPI(const TfToken &) const "RemoveAPI"
1346  /// with \p instanceName that takes a \p schemaFamily and \p schemaVersion
1347  /// to determine the schema type.
1348  USD_API
1349  bool RemoveAPI(const TfToken& schemaFamily,
1350  UsdSchemaVersion schemaVersion,
1351  const TfToken& instanceName) const;
1352 
1353  /// @}
1354 
1355  /// Adds the applied API schema name token \p appliedSchemaName to the
1356  /// \em apiSchemas metadata for this prim at the current edit target. For
1357  /// multiple-apply schemas the name token should include the instance name
1358  /// for the applied schema, for example 'CollectionAPI:plasticStuff'.
1359  ///
1360  /// The name will only be added if the \ref SdfListOp "list operation" at
1361  /// the edit target does not already have this applied schema in its
1362  /// explicit, prepended, or appended lists and is always added to the end
1363  /// of either the prepended or explicit items.
1364  ///
1365  /// Returns true upon success or if the API schema is already applied in
1366  /// the current edit target.
1367  ///
1368  /// An error is issued and false returned for any of the following
1369  /// conditions:
1370  /// \li this prim is not a valid prim for editing
1371  /// \li this prim is valid, but cannot be reached or overridden in the
1372  /// current edit target
1373  /// \li the schema name cannot be added to the apiSchemas listOp metadata
1374  ///
1375  /// Unlike ApplyAPI this method does not require that the name token
1376  /// refer to a valid API schema type. ApplyAPI is the preferred method
1377  /// for applying valid API schemas.
1378  USD_API
1379  bool AddAppliedSchema(const TfToken &appliedSchemaName) const;
1380 
1381  /// Removes the applied API schema name token \p appliedSchemaName from the
1382  /// \em apiSchemas metadata for this prim at the current edit target. For
1383  /// multiple-apply schemas the name token should include the instance name
1384  /// for the applied schema, for example 'CollectionAPI:plasticStuff'
1385  ///
1386  /// For an explicit \ref SdfListOp "list operation", this removes the
1387  /// applied schema name from the explicit items list if it was present. For
1388  /// a non-explicit \ref SdfListOp "list operation", this will remove any
1389  /// occurrence of the applied schema name from the prepended and appended
1390  /// item as well as adding it to the deleted items list.
1391  ///
1392  /// Returns true upon success or if the API schema is already deleted in
1393  /// the current edit target.
1394  ///
1395  /// An error is issued and false returned for any of the following
1396  /// conditions:
1397  /// \li this prim is not a valid prim for editing
1398  /// \li this prim is valid, but cannot be reached or overridden in the
1399  /// current edit target
1400  /// \li the schema name cannot be deleted in the apiSchemas listOp metadata
1401  ///
1402  /// Unlike RemoveAPI this method does not require that the name token
1403  /// refer to a valid API schema type. RemoveAPI is the preferred method
1404  /// for removing valid API schemas.
1405  USD_API
1406  bool RemoveAppliedSchema(const TfToken &appliedSchemaName) const;
1407 
1408  // --------------------------------------------------------------------- //
1409  /// \name Prim Children
1410  // --------------------------------------------------------------------- //
1411 
1412  /// Return this prim's direct child named \p name if it has one, otherwise
1413  /// return an invalid UsdPrim. Equivalent to:
1414  /// \code
1415  /// prim.GetStage()->GetPrimAtPath(prim.GetPath().AppendChild(name))
1416  /// \endcode
1417  USD_API
1418  UsdPrim GetChild(const TfToken &name) const;
1419 
1420  /// Return this prim's active, loaded, defined, non-abstract children as an
1421  /// iterable range. Equivalent to:
1422  /// \code
1423  /// GetFilteredChildren(UsdPrimDefaultPredicate)
1424  /// \endcode
1425  ///
1426  /// See \ref Usd_PrimFlags "Prim predicate flags"
1427  /// and #UsdPrimDefaultPredicate for more information.
1428  inline SiblingRange GetChildren() const;
1429 
1430  /// Return all this prim's children as an iterable range.
1431  inline SiblingRange GetAllChildren() const;
1432 
1433  /// Return a subset of all of this prim's children filtered by \p predicate
1434  /// as an iterable range. The \p predicate is generated by combining a
1435  /// series of prim flag terms with either && or || and !.
1436  ///
1437  /// Example usage:
1438  /// \code
1439  /// // Get all active model children.
1440  /// GetFilteredChildren(UsdPrimIsActive && UsdPrimIsModel);
1441  ///
1442  /// // Get all model children that pass the default predicate.
1443  /// GetFilteredChildren(UsdPrimDefaultPredicate && UsdPrimIsModel);
1444  /// \endcode
1445  ///
1446  /// If this prim is an instance, no children will be returned unless
1447  /// #UsdTraverseInstanceProxies is used to allow instance proxies to be
1448  /// returned, or if this prim is itself an instance proxy.
1449  ///
1450  /// See \ref Usd_PrimFlags "Prim predicate flags"
1451  /// and #UsdPrimDefaultPredicate for more information.
1452  inline SiblingRange
1453  GetFilteredChildren(const Usd_PrimFlagsPredicate &predicate) const;
1454 
1455  /// Return the names of the child prims in the order they appear when
1456  /// iterating over GetChildren.
1457  USD_API
1459 
1460  /// Return the names of the child prims in the order they appear when
1461  /// iterating over GetAllChildren.
1462  USD_API
1464 
1465  /// Return the names of the child prims in the order they appear when
1466  /// iterating over GetFilteredChildren(\p predicate).
1467  USD_API
1469  const Usd_PrimFlagsPredicate &predicate) const;
1470 
1471  /// Return this prim's active, loaded, defined, non-abstract descendants as
1472  /// an iterable range. Equivalent to:
1473  /// \code
1474  /// GetFilteredDescendants(UsdPrimDefaultPredicate)
1475  /// \endcode
1476  ///
1477  /// \note This method is not yet available in python, pending some
1478  /// refactoring to make it more feasible.
1479  ///
1480  /// See \ref Usd_PrimFlags "Prim predicate flags" and
1481  /// #UsdPrimDefaultPredicate for more information, UsdStage::Traverse(),
1482  /// and \c UsdPrimRange for more general Stage traversal behaviors.
1483  inline SubtreeRange GetDescendants() const;
1484 
1485  /// Return all this prim's descendants as an iterable range.
1486  ///
1487  /// \note This method is not yet available in python, pending some
1488  /// refactoring to make it more feasible.
1489  ///
1490  /// See \ref Usd_PrimFlags "Prim predicate flags" and
1491  /// #UsdPrimDefaultPredicate for more information, UsdStage::Traverse(),
1492  /// and \c UsdPrimRange for more general Stage traversal behaviors.
1493  inline SubtreeRange GetAllDescendants() const;
1494 
1495  /// Return a subset of all of this prim's descendants filtered by
1496  /// \p predicate as an iterable range. The \p predicate is generated by
1497  /// combining a series of prim flag terms with either && or || and !.
1498  ///
1499  /// Example usage:
1500  /// \code
1501  /// // Get all active model descendants.
1502  /// GetFilteredDescendants(UsdPrimIsActive && UsdPrimIsModel);
1503  ///
1504  /// // Get all model descendants that pass the default predicate.
1505  /// GetFilteredDescendants(UsdPrimDefaultPredicate && UsdPrimIsModel);
1506  /// \endcode
1507  ///
1508  /// If this prim is an instance, no descendants will be returned unless
1509  /// #UsdTraverseInstanceProxies is used to allow instance proxies to be
1510  /// returned, or if this prim is itself an instance proxy.
1511  ///
1512  /// \note This method is not yet available in python, pending some
1513  /// refactoring to make it more feasible.
1514  ///
1515  /// See \ref Usd_PrimFlags "Prim predicate flags" and
1516  /// #UsdPrimDefaultPredicate for more information, UsdStage::Traverse(),
1517  /// and \c UsdPrimRange for more general Stage traversal behaviors.
1518  inline SubtreeRange
1519  GetFilteredDescendants(const Usd_PrimFlagsPredicate &predicate) const;
1520 
1521  /// Return the strongest opinion for the metadata used to reorder children
1522  /// of this prim. Due to how reordering of prim children is composed,
1523  /// this value cannot be relied on to get the actual order of the prim's
1524  /// children. Use GetChidrenNames, GetAllChildrenNames,
1525  /// GetFilteredChildrenNames to get the true child order if needed.
1526  USD_API
1528 
1529  /// Author an opinion for the metadata used to reorder children of this
1530  /// prim at the current EditTarget.
1532  SetMetadata(SdfFieldKeys->PrimOrder, order);
1533  }
1534 
1535  /// Remove the opinion for the metadata used to reorder children of this
1536  /// prim at the current EditTarget.
1537  void ClearChildrenReorder() const {
1538  ClearMetadata(SdfFieldKeys->PrimOrder);
1539  }
1540 
1541 public:
1542  // --------------------------------------------------------------------- //
1543  /// \name Parent & Stage
1544  // --------------------------------------------------------------------- //
1545 
1546  /// Return this prim's parent prim. Return a pseudoroot UsdPrim if this is
1547  /// a root prim. Return an invalid UsdPrim if this is a pseudoroot prim.
1548  UsdPrim GetParent() const {
1550  SdfPath proxyPrimPath = _ProxyPrimPath();
1551  Usd_MoveToParent(prim, proxyPrimPath);
1552  return UsdPrim(prim, proxyPrimPath);
1553  }
1554 
1555  /// Return this prim's next active, loaded, defined, non-abstract sibling
1556  /// if it has one, otherwise return an invalid UsdPrim. Equivalent to:
1557  /// \code
1558  /// GetFilteredNextSibling(UsdPrimDefaultPredicate)
1559  /// \endcode
1560  ///
1561  /// See \ref Usd_PrimFlags "Prim predicate flags"
1562  /// and #UsdPrimDefaultPredicate for more information.
1563  USD_API
1564  UsdPrim GetNextSibling() const;
1565 
1566  /// Return this prim's next sibling that matches \p predicate if it has one,
1567  /// otherwise return the invalid UsdPrim.
1568  ///
1569  /// See \ref Usd_PrimFlags "Prim predicate flags"
1570  /// and #UsdPrimDefaultPredicate for more information.
1571  USD_API
1573  const Usd_PrimFlagsPredicate &predicate) const;
1574 
1575  /// Returns true if the prim is the pseudo root.
1576  ///
1577  /// Equivalent to
1578  /// \code
1579  /// prim.GetPath() == SdfPath::AbsoluteRootPath()
1580  /// \endcode
1581  USD_API
1582  bool IsPseudoRoot() const;
1583 
1584  /// Returns the prim at \p path on the same stage as this prim.
1585  /// If path is is relative, it will be anchored to the path of this prim.
1586  /// \sa UsdStage::GetPrimAtPath(const SdfPath&) const
1587  USD_API UsdPrim GetPrimAtPath(const SdfPath& path) const;
1588 
1589  /// Returns the object at \p path on the same stage as this prim.
1590  /// If path is is relative, it will be anchored to the path of this prim.
1591  /// \sa UsdStage::GetObjectAtPath(const SdfPath&) const
1593 
1594  /// Returns the property at \p path on the same stage as this prim.
1595  /// If path is relative, it will be anchored to the path of this prim.
1596  ///
1597  /// \note There is no guarantee that this method returns a property on
1598  /// this prim. This is only guaranteed if path is a purely relative
1599  /// property path.
1600  /// \sa GetProperty(const TfToken&) const
1601  /// \sa UsdStage::GetPropertyAtPath(const SdfPath&) const
1603 
1604  /// Returns the attribute at \p path on the same stage as this prim.
1605  /// If path is relative, it will be anchored to the path of this prim.
1606  ///
1607  /// \note There is no guarantee that this method returns an attribute on
1608  /// this prim. This is only guaranteed if path is a purely relative
1609  /// property path.
1610  /// \sa GetAttribute(const TfToken&) const
1611  /// \sa UsdStage::GetAttributeAtPath(const SdfPath&) const
1613 
1614  /// Returns the relationship at \p path on the same stage as this prim.
1615  /// If path is relative, it will be anchored to the path of this prim.
1616  ///
1617  /// \note There is no guarantee that this method returns a relationship on
1618  /// this prim. This is only guaranteed if path is a purely relative
1619  /// property path.
1620  /// \sa GetRelationship(const TfToken&) const
1621  /// \sa UsdStage::GetRelationshipAtPath(const SdfPath&) const
1623 
1624  // --------------------------------------------------------------------- //
1625  /// \name Variants
1626  // --------------------------------------------------------------------- //
1627 
1628  /// Return a UsdVariantSets object representing all the VariantSets
1629  /// present on this prim.
1630  ///
1631  /// The returned object also provides the API for adding new VariantSets
1632  /// to the prim.
1633  USD_API
1635 
1636  /// Retrieve a specifically named VariantSet for editing or constructing
1637  /// a UsdEditTarget.
1638  ///
1639  /// This is a shortcut for
1640  /// \code
1641  /// prim.GetVariantSets().GetVariantSet(variantSetName)
1642  /// \endcode
1643  USD_API
1644  UsdVariantSet GetVariantSet(const std::string& variantSetName) const;
1645 
1646  /// Return true if this prim has any authored VariantSets.
1647  ///
1648  /// \note this connotes only the *existence* of one of more VariantSets,
1649  /// *not* that such VariantSets necessarily contain any variants or
1650  /// variant opinions.
1651  USD_API
1652  bool HasVariantSets() const;
1653 
1654  // --------------------------------------------------------------------- //
1655  /// \name Attributes
1656  // --------------------------------------------------------------------- //
1657 
1658  /// Author scene description for the attribute named \a attrName at the
1659  /// current EditTarget if none already exists. Return a valid attribute if
1660  /// scene description was successfully authored or if it already existed,
1661  /// return invalid attribute otherwise. Note that the supplied \a typeName
1662  /// and \a custom arguments are only used in one specific case. See below
1663  /// for details.
1664  ///
1665  /// Suggested use:
1666  /// \code
1667  /// if (UsdAttribute myAttr = prim.CreateAttribute(...)) {
1668  /// // success.
1669  /// }
1670  /// \endcode
1671  ///
1672  /// To call this, GetPrim() must return a valid prim.
1673  ///
1674  /// - If a spec for this attribute already exists at the current edit
1675  /// target, do nothing.
1676  ///
1677  /// - If a spec for \a attrName of a different spec type (e.g. a
1678  /// relationship) exists at the current EditTarget, issue an error.
1679  ///
1680  /// - If \a name refers to a builtin attribute according to the prim's
1681  /// definition, author an attribute spec with required metadata from the
1682  /// definition.
1683  ///
1684  /// - If \a name refers to a builtin relationship, issue an error.
1685  ///
1686  /// - If there exists an absolute strongest authored attribute spec for
1687  /// \a attrName, author an attribute spec at the current EditTarget by
1688  /// copying required metadata from that strongest spec.
1689  ///
1690  /// - If there exists an absolute strongest authored relationship spec for
1691  /// \a attrName, issue an error.
1692  ///
1693  /// - Otherwise author an attribute spec at the current EditTarget using
1694  /// the provided \a typeName and \a custom for the required metadata fields.
1695  /// Note that these supplied arguments are only ever used in this particular
1696  /// circumstance, in all other cases they are ignored.
1697  USD_API
1698  UsdAttribute
1699  CreateAttribute(const TfToken& name,
1700  const SdfValueTypeName &typeName,
1701  bool custom,
1702  SdfVariability variability = SdfVariabilityVarying) const;
1703  /// \overload
1704  /// Create a custom attribute with \p name, \p typeName and \p variability.
1705  USD_API
1706  UsdAttribute
1707  CreateAttribute(const TfToken& name,
1708  const SdfValueTypeName &typeName,
1709  SdfVariability variability = SdfVariabilityVarying) const;
1710 
1711  /// \overload
1712  /// This overload of CreateAttribute() accepts a vector of name components
1713  /// used to construct a \em namespaced property name. For details, see
1714  /// \ref Usd_Ordering
1715  USD_API
1717  const std::vector<std::string> &nameElts,
1718  const SdfValueTypeName &typeName,
1719  bool custom,
1720  SdfVariability variability = SdfVariabilityVarying) const;
1721  /// \overload
1722  /// Create a custom attribute with \p nameElts, \p typeName, and
1723  /// \p variability.
1724  USD_API
1726  const std::vector<std::string> &nameElts,
1727  const SdfValueTypeName &typeName,
1728  SdfVariability variability = SdfVariabilityVarying) const;
1729 
1730  /// Like GetProperties(), but exclude all relationships from the result.
1731  USD_API
1732  std::vector<UsdAttribute> GetAttributes() const;
1733 
1734  /// Like GetAttributes(), but exclude attributes without authored scene
1735  /// description from the result. See UsdProperty::IsAuthored().
1736  USD_API
1737  std::vector<UsdAttribute> GetAuthoredAttributes() const;
1738 
1739  /// Return a UsdAttribute with the name \a attrName. The attribute
1740  /// returned may or may not \b actually exist so it must be checked for
1741  /// validity. Suggested use:
1742  ///
1743  /// \code
1744  /// if (UsdAttribute myAttr = prim.GetAttribute("myAttr")) {
1745  /// // myAttr is safe to use.
1746  /// // Edits to the owning stage requires subsequent validation.
1747  /// } else {
1748  /// // myAttr was not defined/authored
1749  /// }
1750  /// \endcode
1751  USD_API
1752  UsdAttribute GetAttribute(const TfToken& attrName) const;
1753 
1754  /// Return true if this prim has an attribute named \p attrName, false
1755  /// otherwise.
1756  USD_API
1757  bool HasAttribute(const TfToken& attrName) const;
1758 
1759  /// Search the prim subtree rooted at this prim according to \p
1760  /// traversalPredicate for attributes for which \p predicate returns true,
1761  /// collect their connection source paths and return them in an arbitrary
1762  /// order. If \p recurseOnSources is true, act as if this function was
1763  /// invoked on the connected prims and owning prims of connected properties
1764  /// also and return the union.
1765  USD_API
1768  Usd_PrimFlagsPredicate const &traversalPredicate,
1769  std::function<bool (UsdAttribute const &)> const &pred = nullptr,
1770  bool recurseOnSources = false) const;
1771 
1772  /// \overload
1773  /// Invoke FindAllAttributeConnectionPaths() with the
1774  /// UsdPrimDefaultPredicate as its traversalPredicate.
1775  USD_API
1778  std::function<bool (UsdAttribute const &)> const &pred = nullptr,
1779  bool recurseOnSources = false) const;
1780 
1781  // --------------------------------------------------------------------- //
1782  /// \name Relationships
1783  // --------------------------------------------------------------------- //
1784 
1785  /// Author scene description for the relationship named \a relName at the
1786  /// current EditTarget if none already exists. Return a valid relationship
1787  /// if scene description was successfully authored or if it already existed,
1788  /// return an invalid relationship otherwise.
1789  ///
1790  /// Suggested use:
1791  /// \code
1792  /// if (UsdRelationship myRel = prim.CreateRelationship(...)) {
1793  /// // success.
1794  /// }
1795  /// \endcode
1796  ///
1797  /// To call this, GetPrim() must return a valid prim.
1798  ///
1799  /// - If a spec for this relationship already exists at the current edit
1800  /// target, do nothing.
1801  ///
1802  /// - If a spec for \a relName of a different spec type (e.g. an
1803  /// attribute) exists at the current EditTarget, issue an error.
1804  ///
1805  /// - If \a name refers to a builtin relationship according to the prim's
1806  /// definition, author a relationship spec with required metadata from the
1807  /// definition.
1808  ///
1809  /// - If \a name refers to a builtin attribute, issue an error.
1810  ///
1811  /// - If there exists an absolute strongest authored relationship spec for
1812  /// \a relName, author a relationship spec at the current EditTarget by
1813  /// copying required metadata from that strongest spec.
1814  ///
1815  /// - If there exists an absolute strongest authored attribute spec for \a
1816  /// relName, issue an error.
1817  ///
1818  /// - Otherwise author a uniform relationship spec at the current
1819  /// EditTarget, honoring \p custom .
1820  ///
1821  USD_API
1823  bool custom=true) const;
1824 
1825  /// \overload
1826  /// This overload of CreateRelationship() accepts a vector of
1827  /// name components used to construct a \em namespaced property name.
1828  /// For details, see \ref Usd_Ordering
1829  USD_API
1830  UsdRelationship CreateRelationship(const std::vector<std::string> &nameElts,
1831  bool custom=true)
1832  const;
1833 
1834  /// Like GetProperties(), but exclude all attributes from the result.
1835  USD_API
1836  std::vector<UsdRelationship> GetRelationships() const;
1837 
1838  /// Like GetRelationships(), but exclude relationships without authored
1839  /// scene description from the result. See UsdProperty::IsAuthored().
1840  USD_API
1841  std::vector<UsdRelationship> GetAuthoredRelationships() const;
1842 
1843  /// Return a UsdRelationship with the name \a relName. The relationship
1844  /// returned may or may not \b actually exist so it must be checked for
1845  /// validity. Suggested use:
1846  ///
1847  /// \code
1848  /// if (UsdRelationship myRel = prim.GetRelationship("myRel")) {
1849  /// // myRel is safe to use.
1850  /// // Edits to the owning stage requires subsequent validation.
1851  /// } else {
1852  /// // myRel was not defined/authored
1853  /// }
1854  /// \endcode
1855  USD_API
1856  UsdRelationship GetRelationship(const TfToken& relName) const;
1857 
1858  /// Return true if this prim has a relationship named \p relName, false
1859  /// otherwise.
1860  USD_API
1861  bool HasRelationship(const TfToken& relName) const;
1862 
1863  /// Search the prim subtree rooted at this prim according to \p
1864  /// traversalPredicate for relationships for which \p predicate returns
1865  /// true, collect their target paths and return them in an arbitrary order.
1866  /// If \p recurseOnTargets is true, act as if this function was invoked on
1867  /// the targeted prims and owning prims of targeted properties also (but not
1868  /// of forwarding relationships) and return the union.
1869  USD_API
1872  Usd_PrimFlagsPredicate const &traversalPredicate,
1873  std::function<bool (UsdRelationship const &)> const &pred = nullptr,
1874  bool recurseOnTargets = false) const;
1875 
1876  /// \overload
1877  /// Invoke FindAllRelationshipTargetPaths() with the UsdPrimDefaultPredicate
1878  /// as its traversalPredicate.
1879  USD_API
1882  std::function<bool (UsdRelationship const &)> const &pred = nullptr,
1883  bool recurseOnTargets = false) const;
1884 
1885  // --------------------------------------------------------------------- //
1886  /// \name Payload Authoring
1887  /// \deprecated
1888  /// This API is now deprecated. Please use the HasAuthoredPayloads and the
1889  /// UsdPayloads API returned from GetPayloads() to query and author payloads
1890  /// instead.
1891  /// @{
1892  // --------------------------------------------------------------------- //
1893 
1894  /// \deprecated
1895  /// Clears the payload at the current EditTarget for this prim. Return false
1896  /// if the payload could not be cleared.
1897  USD_API
1898  bool ClearPayload() const;
1899 
1900  /// \deprecated
1901  /// Return true if a payload is present on this prim.
1902  ///
1903  /// \sa \ref Usd_Payloads
1904  USD_API
1905  bool HasPayload() const;
1906 
1907  /// \deprecated
1908  /// Author payload metadata for this prim at the current edit
1909  /// target. Return true on success, false if the value could not be set.
1910  ///
1911  /// \sa \ref Usd_Payloads
1912  USD_API
1913  bool SetPayload(const SdfPayload& payload) const;
1914 
1915  /// \deprecated
1916  /// Shorthand for SetPayload(SdfPayload(assetPath, primPath)).
1917  USD_API
1918  bool SetPayload(
1919  const std::string& assetPath, const SdfPath& primPath) const;
1920 
1921  /// \deprecated
1922  /// Shorthand for SetPayload(SdfPayload(layer->GetIdentifier(),
1923  /// primPath)).
1924  USD_API
1925  bool SetPayload(const SdfLayerHandle& layer, const SdfPath& primPath) const;
1926 
1927  /// @}
1928 
1929  // --------------------------------------------------------------------- //
1930  /// \name Payloads, Load and Unload
1931  // --------------------------------------------------------------------- //
1932 
1933  /// Return a UsdPayloads object that allows one to add, remove, or
1934  /// mutate payloads <em>at the currently set UsdEditTarget</em>.
1935  ///
1936  /// While the UsdPayloads object has no methods for \em listing the
1937  /// currently authored payloads on a prim, one can use a
1938  /// UsdPrimCompositionQuery to query the payload arcs that are composed
1939  /// by this prim.
1940  USD_API
1941  UsdPayloads GetPayloads() const;
1942 
1943  /// Return true if this prim has any authored payloads.
1944  USD_API
1945  bool HasAuthoredPayloads() const;
1946 
1947  /// Load this prim, all its ancestors, and by default all its descendants.
1948  /// If \p loadPolicy is UsdLoadWithoutDescendants, then load only this prim
1949  /// and its ancestors.
1950  ///
1951  /// See UsdStage::Load for additional details.
1952  USD_API
1953  void Load(UsdLoadPolicy policy = UsdLoadWithDescendants) const;
1954 
1955  /// Unloads this prim and all its descendants.
1956  ///
1957  /// See UsdStage::Unload for additional details.
1958  USD_API
1959  void Unload() const;
1960 
1961  // --------------------------------------------------------------------- //
1962  /// \name References
1963  // --------------------------------------------------------------------- //
1964 
1965  /// Return a UsdReferences object that allows one to add, remove, or
1966  /// mutate references <em>at the currently set UsdEditTarget</em>.
1967  ///
1968  /// While the UsdReferences object has no methods for \em listing the
1969  /// currently authored references on a prim, one can use a
1970  /// UsdPrimCompositionQuery to query the reference arcs that are composed
1971  /// by this prim.
1972  ///
1973  /// \sa UsdPrimCompositionQuery::GetDirectReferences
1974  USD_API
1975  UsdReferences GetReferences() const;
1976 
1977  /// Return true if this prim has any authored references.
1978  USD_API
1979  bool HasAuthoredReferences() const;
1980 
1981  // --------------------------------------------------------------------- //
1982  /// \name Inherits
1983  // --------------------------------------------------------------------- //
1984 
1985  /// Return a UsdInherits object that allows one to add, remove, or
1986  /// mutate inherits <em>at the currently set UsdEditTarget</em>.
1987  ///
1988  /// While the UsdInherits object has no methods for \em listing the
1989  /// currently authored inherits on a prim, one can use a
1990  /// UsdPrimCompositionQuery to query the inherits arcs that are composed
1991  /// by this prim.
1992  ///
1993  /// \sa UsdPrimCompositionQuery::GetDirectInherits
1994  USD_API
1995  UsdInherits GetInherits() const;
1996 
1997  /// Return true if this prim has any authored inherits.
1998  USD_API
1999  bool HasAuthoredInherits() const;
2000 
2001  // --------------------------------------------------------------------- //
2002  /// \name Specializes
2003  // --------------------------------------------------------------------- //
2004 
2005  /// Return a UsdSpecializes object that allows one to add, remove, or
2006  /// mutate specializes <em>at the currently set UsdEditTarget</em>.
2007  ///
2008  /// While the UsdSpecializes object has no methods for \em listing the
2009  /// currently authored specializes on a prim, one can use a
2010  /// UsdPrimCompositionQuery to query the specializes arcs that are composed
2011  /// by this prim.
2012  USD_API
2014 
2015  /// Returns true if this prim has any authored specializes.
2016  USD_API
2017  bool HasAuthoredSpecializes() const;
2018 
2019  // --------------------------------------------------------------------- //
2020  /// \name Instancing
2021  /// See \ref Usd_Page_ScenegraphInstancing for more details.
2022  /// @{
2023  // --------------------------------------------------------------------- //
2024 
2025  /// Return true if this prim has been marked as instanceable.
2026  ///
2027  /// Note that this is not the same as IsInstance(). A prim may return
2028  /// true for IsInstanceable() and false for IsInstance() if this prim
2029  /// is not active or if it is marked as instanceable but contains no
2030  /// instanceable data.
2031  bool IsInstanceable() const {
2032  bool instanceable = false;
2033  return GetMetadata(SdfFieldKeys->Instanceable, &instanceable) &&
2034  instanceable;
2035  }
2036 
2037  /// Author 'instanceable' metadata for this prim at the current
2038  /// EditTarget.
2039  bool SetInstanceable(bool instanceable) const {
2040  return SetMetadata(SdfFieldKeys->Instanceable, instanceable);
2041  }
2042 
2043  /// Remove the authored 'instanceable' opinion at the current EditTarget.
2044  /// Do nothing if there is no authored opinion.
2045  bool ClearInstanceable() const {
2046  return ClearMetadata(SdfFieldKeys->Instanceable);
2047  }
2048 
2049  /// Return true if this prim has an authored opinion for 'instanceable',
2050  /// false otherwise.
2052  return HasAuthoredMetadata(SdfFieldKeys->Instanceable);
2053  }
2054 
2055  /// Return true if this prim is an instance of a prototype, false
2056  /// otherwise.
2057  ///
2058  /// If this prim is an instance, calling GetPrototype() will return
2059  /// the UsdPrim for the corresponding prototype prim.
2060  bool IsInstance() const { return _Prim()->IsInstance(); }
2061 
2062  /// Return true if this prim is an instance proxy, false otherwise.
2063  /// An instance proxy prim represents a descendent of an instance
2064  /// prim.
2065  bool IsInstanceProxy() const {
2067  }
2068 
2069  /// Return true if the given \p path identifies a prototype prim,
2070  /// false otherwise.
2071  ///
2072  /// This function will return false for prim and property paths
2073  /// that are descendants of a prototype prim path.
2074  ///
2075  /// \sa IsPathInPrototype
2076  USD_API
2077  static bool IsPrototypePath(const SdfPath& path);
2078 
2079  /// Return true if the given \p path identifies a prototype prim or
2080  /// a prim or property descendant of a prototype prim, false otherwise.
2081  ///
2082  /// \sa IsPrototypePath
2083  USD_API
2084  static bool IsPathInPrototype(const SdfPath& path);
2085 
2086  /// Return true if this prim is an instancing prototype prim,
2087  /// false otherwise.
2088  ///
2089  /// \sa IsInPrototype
2090  bool IsPrototype() const { return _Prim()->IsPrototype(); }
2091 
2092  /// Return true if this prim is a prototype prim or a descendant
2093  /// of a prototype prim, false otherwise.
2094  ///
2095  /// \sa IsPrototype
2096  bool IsInPrototype() const {
2097  return (IsInstanceProxy() ?
2099  }
2100 
2101  /// If this prim is an instance, return the UsdPrim for the corresponding
2102  /// prototype. Otherwise, return an invalid UsdPrim.
2103  USD_API
2104  UsdPrim GetPrototype() const;
2105 
2106  /// If this prim is an instance proxy, return the UsdPrim for the
2107  /// corresponding prim in the instance's prototype. Otherwise, return an
2108  /// invalid UsdPrim.
2110  if (IsInstanceProxy()) {
2111  return UsdPrim(_Prim(), SdfPath());
2112  }
2113  return UsdPrim();
2114  }
2115 
2116  /// If this prim is a prototype prim, returns all prims that are instances
2117  /// of this prototype. Otherwise, returns an empty vector.
2118  ///
2119  /// Note that this function will return prims in prototypes for instances
2120  /// that are nested beneath other instances.
2121  USD_API
2122  std::vector<UsdPrim> GetInstances() const;
2123  /// @}
2124 
2125  // --------------------------------------------------------------------- //
2126  /// \name Composition Structure
2127  /// @{
2128  // --------------------------------------------------------------------- //
2129 
2130  /// Return the cached prim index containing all sites that can contribute
2131  /// opinions to this prim.
2132  ///
2133  /// The prim index can be used to examine the composition arcs and scene
2134  /// description sites that can contribute to this prim's property and
2135  /// metadata values.
2136  ///
2137  /// The prim index returned by this function is optimized and may not
2138  /// include sites that do not contribute opinions to this prim. Use
2139  /// UsdPrim::ComputeExpandedPrimIndex to compute a prim index that includes
2140  /// all possible sites that could contribute opinions.
2141  ///
2142  /// This prim index will be empty for prototype prims. This ensures that
2143  /// these prims do not provide any attribute or metadata values. For all
2144  /// other prims in prototypes, this is the prim index that was chosen to
2145  /// be shared with all other instances. In either case, the prim index's
2146  /// path will not be the same as the prim's path.
2147  ///
2148  /// Prim indexes may be invalidated by changes to the UsdStage and cannot
2149  /// detect if they are expired. Clients should avoid keeping copies of the
2150  /// prim index across such changes, which include scene description
2151  /// changes or changes to load state.
2152  const PcpPrimIndex &GetPrimIndex() const { return _Prim()->GetPrimIndex(); }
2153 
2154  /// Compute the prim index containing all sites that could contribute
2155  /// opinions to this prim.
2156  ///
2157  /// This function is similar to UsdPrim::GetPrimIndex. However, the
2158  /// returned prim index includes all sites that could possibly contribute
2159  /// opinions to this prim, not just the sites that currently do so. This is
2160  /// useful in certain situations; for example, this could be used to
2161  /// generate a list of sites where clients could make edits to affect this
2162  /// prim, or for debugging purposes.
2163  ///
2164  /// For all prims in prototypes, including the prototype prim itself, this
2165  /// is the expanded version of the prim index that was chosen to be shared
2166  /// with all other instances. Thus, the prim index's path will not be the
2167  /// same as the prim's path. Note that this behavior deviates slightly from
2168  /// UsdPrim::GetPrimIndex which always returns an empty prim index for the
2169  /// prototype prim itself.
2170  ///
2171  /// This function may be relatively slow, since it will recompute the prim
2172  /// index on every call. Clients should prefer UsdPrim::GetPrimIndex unless
2173  /// the additional site information is truly needed.
2174  USD_API
2176 
2177  /// Creates and returns a resolve target that, when passed to a
2178  /// UsdAttributeQuery for one of this prim's attributes, causes value
2179  /// resolution to only consider weaker specs up to and including the spec
2180  /// that would be authored for this prim when using the given \p editTarget.
2181  ///
2182  /// If the edit target would not affect any specs that could contribute to
2183  /// this prim, a null resolve target is returned.
2184  USD_API
2186  const UsdEditTarget &editTarget) const;
2187 
2188  /// Creates and returns a resolve target that, when passed to a
2189  /// UsdAttributeQuery for one of this prim's attributes, causes value
2190  /// resolution to only consider specs that are stronger than the spec
2191  /// that would be authored for this prim when using the given \p editTarget.
2192  ///
2193  /// If the edit target would not affect any specs that could contribute to
2194  /// this prim, a null resolve target is returned.
2195  USD_API
2197  const UsdEditTarget &editTarget) const;
2198 
2199  /// @}
2200 
2201 private:
2202  class _ProtoToInstancePathMap {
2203  friend class UsdPrim;
2204  public:
2205  using _Map = std::vector<std::pair<SdfPath, SdfPath>>;
2206  SdfPath MapProtoToInstance(SdfPath const &protoPath) const;
2207  private:
2208  _Map _map;
2209  };
2210 
2211  friend class UsdObject;
2214  friend class UsdProperty;
2215  friend class UsdSchemaBase;
2216  friend class UsdAPISchemaBase;
2217  friend class UsdStage;
2218  friend class UsdPrimRange;
2219  friend class Usd_PrimData;
2221  friend struct Usd_StageImplAccess;
2224 
2225  // Prim constructor.
2226  UsdPrim(const Usd_PrimDataHandle &primData,
2227  const SdfPath &proxyPrimPath)
2228  : UsdObject(primData, proxyPrimPath) { }
2229 
2230  // General constructor.
2231  UsdPrim(UsdObjType objType,
2232  const Usd_PrimDataHandle &prim,
2233  const SdfPath &proxyPrimPath,
2234  const TfToken &propName)
2235  : UsdObject(objType, prim, proxyPrimPath, propName) {}
2236 
2237  // Helper to make a sibling range.
2238  inline SiblingRange
2239  _MakeSiblingRange(const Usd_PrimFlagsPredicate &pred) const;
2240 
2241  // Helper to make a range of descendants.
2242  inline SubtreeRange
2243  _MakeDescendantsRange(const Usd_PrimFlagsPredicate &pred) const;
2244 
2245  // Helper to make a vector of properties from names.
2246  std::vector<UsdProperty>
2247  _MakeProperties(const TfTokenVector &names) const;
2248 
2249  // Helper for Get{Authored}{PropertyNames,Properties}
2250  TfTokenVector _GetPropertyNames(
2251  bool onlyAuthored,
2252  bool applyOrder=true,
2253  const PropertyPredicateFunc &predicate={}) const;
2254 
2255  // Helper for Get(Authored)PropertiesInNamespace.
2256  std::vector<UsdProperty>
2257  _GetPropertiesInNamespace(const std::string &namespaces,
2258  bool onlyAuthored) const;
2259 
2260  // Helper for Get(Authored)Attributes.
2261  std::vector<UsdAttribute>
2262  _GetAttributes(bool onlyAuthored, bool applyOrder=false) const;
2263 
2264  // Helper for Get(Authored)Relationships.
2265  std::vector<UsdRelationship>
2266  _GetRelationships(bool onlyAuthored, bool applyOrder=false) const;
2267 
2268  friend const PcpPrimIndex &Usd_PrimGetSourcePrimIndex(const UsdPrim&);
2269  // Return a const reference to the source PcpPrimIndex for this prim.
2270  //
2271  // For all prims in prototypes (which includes the prototype prim itself),
2272  // this is the prim index for the instance that was chosen to serve
2273  // as the prototype for all other instances. This prim index will not
2274  // have the same path as the prim's path.
2275  //
2276  // This is a private helper but is also wrapped out to Python
2277  // for testing and debugging purposes.
2278  const PcpPrimIndex &_GetSourcePrimIndex() const
2279  { return _Prim()->GetSourcePrimIndex(); }
2280 
2281  // Helper function for MakeResolveTargetUpToEditTarget and
2282  // MakeResolveTargetStrongerThanEditTarget.
2284  _MakeResolveTargetFromEditTarget(
2285  const UsdEditTarget &editTarget,
2286  bool makeAsStrongerThan) const;
2287 
2288  _ProtoToInstancePathMap _GetProtoToInstancePathMap() const;
2289 };
2290 
2291 /// Forward traversal iterator of sibling ::UsdPrim s. This is a
2292 /// standard-compliant iterator that may be used with STL algorithms, etc.
2293 /// Filters according to a supplied predicate.
2295  using _UnderlyingIterator = const Usd_PrimData*;
2296  class _PtrProxy {
2297  public:
2298  UsdPrim* operator->() { return &_prim; }
2299  private:
2300  friend class UsdPrimSiblingIterator;
2301  explicit _PtrProxy(const UsdPrim& prim) : _prim(prim) {}
2302  UsdPrim _prim;
2303  };
2304 public:
2305  using iterator_category = std::forward_iterator_tag;
2308  using pointer = _PtrProxy;
2309  using difference_type = std::ptrdiff_t;
2310 
2311  // Default ctor.
2312  UsdPrimSiblingIterator() = default;
2313 
2314  /// Dereference.
2315  reference operator*() const { return dereference(); }
2316 
2317  /// Indirection.
2318  pointer operator->() const { return pointer(dereference()); }
2319 
2320  /// Preincrement.
2322  increment();
2323  return *this;
2324  }
2325 
2326  /// Postincrement.
2329  increment();
2330  return result;
2331  }
2332 
2333  bool operator==(const UsdPrimSiblingIterator& other) const {
2334  return equal(other);
2335  }
2336 
2337  bool operator!=(const UsdPrimSiblingIterator& other) const {
2338  return !equal(other);
2339  }
2340 
2341 private:
2342  friend class UsdPrim;
2343 
2344  // Constructor used by Prim.
2346  const SdfPath& proxyPrimPath,
2347  const Usd_PrimFlagsPredicate &predicate)
2348  : _underlyingIterator(i)
2349  , _proxyPrimPath(proxyPrimPath)
2350  , _predicate(predicate) {
2351  // Need to advance iterator to first matching element.
2352  if (_underlyingIterator &&
2353  !Usd_EvalPredicate(_predicate, _underlyingIterator,
2354  _proxyPrimPath))
2355  increment();
2356  }
2357 
2358  bool equal(const UsdPrimSiblingIterator &other) const {
2359  return _underlyingIterator == other._underlyingIterator &&
2360  _proxyPrimPath == other._proxyPrimPath &&
2361  _predicate == other._predicate;
2362  }
2363 
2364  void increment() {
2365  if (Usd_MoveToNextSiblingOrParent(_underlyingIterator, _proxyPrimPath,
2366  _predicate)) {
2367  _underlyingIterator = nullptr;
2368  _proxyPrimPath = SdfPath();
2369  }
2370  }
2371 
2372  reference dereference() const {
2373  return UsdPrim(_underlyingIterator, _proxyPrimPath);
2374  }
2375 
2376  _UnderlyingIterator _underlyingIterator = nullptr;
2377  SdfPath _proxyPrimPath;
2378  Usd_PrimFlagsPredicate _predicate;
2379 };
2380 
2381 /// Forward iterator range of sibling ::UsdPrim s. This range type contains a
2382 /// pair of UsdPrimSiblingIterator s, denoting a half-open range of UsdPrim
2383 /// siblings. It provides a subset of container-like API, such as begin(),
2384 /// end(), front(), empty(), etc.
2386 public:
2387  /// Iterator type.
2389  /// Const iterator type.
2391  /// Iterator difference type.
2392  typedef std::ptrdiff_t difference_type;
2393  /// Iterator value_type.
2395  /// Iterator reference_type.
2397 
2398  UsdPrimSiblingRange() = default;
2399 
2400  /// Construct with a pair of iterators.
2402  UsdPrimSiblingIterator end) : _begin(begin),
2403  _end(end) {}
2404 
2405  /// First iterator.
2406  iterator begin() const { return _begin; }
2407 
2408  /// First iterator.
2409  const_iterator cbegin() const { return _begin; }
2410 
2411  /// Past-the-end iterator.
2412  iterator end() const { return _end; }
2413 
2414  /// Past-the-end iterator.
2415  const_iterator cend() const { return _end; }
2416 
2417  /// Return !empty().
2418  explicit operator bool() const { return !empty(); }
2419 
2420  /// Equality compare.
2421  bool equal(const UsdPrimSiblingRange& other) const {
2422  return _begin == other._begin && _end == other._end;
2423  }
2424 
2425  /// Return *begin(). This range must not be empty.
2426  reference front() const {
2427  TF_DEV_AXIOM(!empty());
2428  return *begin();
2429  }
2430 
2431  /// Advance this range's begin iterator.
2433  std::advance(_begin, n);
2434  return *this;
2435  }
2436 
2437  /// Advance this range's end iterator.
2439  std::advance(_end, n);
2440  return *this;
2441  }
2442 
2443  /// Return begin() == end().
2444  bool empty() const { return begin() == end(); }
2445 
2446 private:
2447  /// Equality comparison.
2448  friend bool operator==(const UsdPrimSiblingRange &lhs,
2449  const UsdPrimSiblingRange &rhs) {
2450  return lhs.equal(rhs);
2451  }
2452 
2453  /// Equality comparison.
2454  template <class ForwardRange>
2455  friend bool operator==(const UsdPrimSiblingRange& lhs,
2456  const ForwardRange& rhs) {
2457  static_assert(
2458  std::is_same<typename decltype(std::cbegin(rhs))::iterator_category,
2459  std::forward_iterator_tag>::value,
2460  "rhs must be a forward iterator."
2461  );
2462  return (std::distance(std::cbegin(lhs), std::cend(lhs)) ==
2463  std::distance(std::cbegin(rhs), std::cend(rhs))) &&
2464  std::equal(std::cbegin(lhs), std::cend(lhs), std::cbegin(rhs));
2465  }
2466 
2467  /// Equality comparison.
2468  template <class ForwardRange>
2469  friend bool operator==(const ForwardRange& lhs,
2470  const UsdPrimSiblingRange& rhs) {
2471  return rhs == lhs;
2472  }
2473 
2474  /// Inequality comparison.
2475  friend bool operator!=(const UsdPrimSiblingRange &lhs,
2476  const UsdPrimSiblingRange &rhs) {
2477  return !lhs.equal(rhs);
2478  }
2479 
2480  /// Inequality comparison.
2481  template <class ForwardRange>
2482  friend bool operator!=(const ForwardRange& lhs,
2483  const UsdPrimSiblingRange& rhs) {
2484  return !(lhs == rhs);
2485  }
2486 
2487  /// Inequality comparison.
2488  template <class ForwardRange>
2489  friend bool operator!=(const UsdPrimSiblingRange& lhs,
2490  const ForwardRange& rhs) {
2491  return !(lhs == rhs);
2492  }
2493 
2494  iterator _begin;
2495  iterator _end;
2496 };
2497 
2498 // Inform TfIterator it should feel free to make copies of the range type.
2499 template <>
2501  UsdPrimSiblingRange> : std::true_type {};
2502 template <>
2504  const UsdPrimSiblingRange> : std::true_type {};
2505 
2508 {
2509  return _MakeSiblingRange(
2511 }
2512 
2515 {
2517 }
2518 
2521 {
2523 }
2524 
2525 // Helper to make a sibling range.
2527 UsdPrim::_MakeSiblingRange(const Usd_PrimFlagsPredicate &pred) const {
2528  Usd_PrimDataConstPtr firstChild = get_pointer(_Prim());
2529  SdfPath firstChildPath = _ProxyPrimPath();
2530  if (!Usd_MoveToChild(firstChild, firstChildPath, pred)) {
2531  firstChild = nullptr;
2532  firstChildPath = SdfPath();
2533  }
2534 
2535  return SiblingRange(
2536  SiblingIterator(firstChild, firstChildPath, pred),
2537  SiblingIterator(nullptr, SdfPath(), pred));
2538 }
2539 
2540 /// Forward traversal iterator of sibling ::UsdPrim s. This is a
2541 /// standard-compliant iterator that may be used with STL algorithms, etc.
2542 /// Filters according to a supplied predicate.
2545  class _PtrProxy {
2546  public:
2547  UsdPrim* operator->() { return &_prim; }
2548  private:
2549  friend class UsdPrimSubtreeIterator;
2550  explicit _PtrProxy(const UsdPrim& prim) : _prim(prim) {}
2551  UsdPrim _prim;
2552  };
2553 public:
2554  using iterator_category = std::forward_iterator_tag;
2557  using pointer = _PtrProxy;
2558  using difference_type = std::ptrdiff_t;
2559 
2560  // Default ctor.
2561  UsdPrimSubtreeIterator() = default;
2562 
2563  /// Dereference.
2564  reference operator*() const { return dereference(); }
2565  /// Indirection.
2566  pointer operator->() const { return pointer(dereference()); }
2567 
2568  /// Preincrement.
2570  increment();
2571  return *this;
2572  }
2573 
2574  /// Postincrement.
2577  increment();
2578  return result;
2579  }
2580 
2581  /// Equality.
2582  bool operator==(const UsdPrimSubtreeIterator &other) const {
2583  return equal(other);
2584  }
2585 
2586  /// Inequality.
2587  bool operator!=(const UsdPrimSubtreeIterator &other) const {
2588  return !equal(other);
2589  }
2590 
2591 
2592 private:
2593  friend class UsdPrim;
2594 
2595  // Constructor used by Prim.
2597  const SdfPath &proxyPrimPath,
2598  const Usd_PrimFlagsPredicate &predicate)
2599  : _underlyingIterator(i)
2600  , _proxyPrimPath(proxyPrimPath)
2601  , _predicate(predicate) {
2602  // Need to advance iterator to first matching element.
2603  if (_underlyingIterator &&
2604  !Usd_EvalPredicate(_predicate, _underlyingIterator,
2605  _proxyPrimPath)) {
2606  if (Usd_MoveToNextSiblingOrParent(_underlyingIterator,
2607  _proxyPrimPath, _predicate)) {
2608  _underlyingIterator = nullptr;
2609  _proxyPrimPath = SdfPath();
2610  }
2611  }
2612  }
2613 
2614  bool equal(const UsdPrimSubtreeIterator &other) const {
2615  return _underlyingIterator == other._underlyingIterator &&
2616  _proxyPrimPath == other._proxyPrimPath &&
2617  _predicate == other._predicate;
2618  }
2619 
2620  void increment() {
2621  if (!Usd_MoveToChild(_underlyingIterator, _proxyPrimPath,
2622  _predicate)) {
2623  while (Usd_MoveToNextSiblingOrParent(_underlyingIterator,
2624  _proxyPrimPath,
2625  _predicate)) {}
2626  }
2627  }
2628 
2629  reference dereference() const {
2630  return UsdPrim(_underlyingIterator, _proxyPrimPath);
2631  }
2632 
2633  _UnderlyingIterator _underlyingIterator = nullptr;
2634  SdfPath _proxyPrimPath;
2635  Usd_PrimFlagsPredicate _predicate;
2636 };
2637 
2638 /// Forward iterator range of sibling ::UsdPrim s. This range type contains a
2639 /// pair of UsdPrimSubtreeIterator s, denoting a half-open range of UsdPrim
2640 /// siblings. It provides a subset of container-like API, such as begin(),
2641 /// end(), front(), empty(), etc.
2643 public:
2644  /// Iterator type.
2646  /// Const iterator type.
2648  /// Iterator difference type.
2649  typedef std::ptrdiff_t difference_type;
2650  /// Iterator value_type.
2652  /// Iterator reference_type.
2654 
2655  UsdPrimSubtreeRange() = default;
2656 
2657  /// Construct with a pair of iterators.
2659  UsdPrimSubtreeIterator end) : _begin(begin),
2660  _end(end) {}
2661 
2662  /// First iterator.
2663  iterator begin() const { return _begin; }
2664 
2665  /// First iterator.
2666  const_iterator cbegin() const { return _begin; }
2667 
2668  /// Past-the-end iterator.
2669  iterator end() const { return _end; }
2670 
2671  /// Past-the-end iterator.
2672  const_iterator cend() const { return _end; }
2673 
2674  /// Return !empty().
2675  explicit operator bool() const {
2676  return !empty();
2677  }
2678 
2679  /// Equality compare.
2680  bool equal(const UsdPrimSubtreeRange& other) const {
2681  return _begin == other._begin && _end == other._end;
2682  }
2683 
2684  /// Return *begin(). This range must not be empty.
2685  reference front() const {
2686  TF_DEV_AXIOM(!empty());
2687  return *begin();
2688  }
2689 
2690  /// Advance this range's begin iterator.
2692  std::advance(_begin, n);
2693  return *this;
2694  }
2695 
2696  /// Advance this range's end iterator.
2698  std::advance(_end, n);
2699  return *this;
2700  }
2701 
2702  /// Return begin() == end().
2703  bool empty() const { return begin() == end(); }
2704 
2705 private:
2706  /// Equality comparison.
2707  friend bool operator==(const UsdPrimSubtreeRange &lhs,
2708  const UsdPrimSubtreeRange &rhs) {
2709  return lhs.equal(rhs);
2710  }
2711 
2712  /// Equality comparison.
2713  template <class ForwardRange>
2714  friend bool operator==(const UsdPrimSubtreeRange& lhs,
2715  const ForwardRange& rhs) {
2716  static_assert(
2717  std::is_convertible<
2718  typename decltype(std::cbegin(rhs))::iterator_category,
2719  std::forward_iterator_tag>::value,
2720  "rhs must be a forward iterator."
2721  );
2722  return (std::distance(std::cbegin(lhs), std::cend(lhs)) ==
2723  std::distance(std::cbegin(rhs), std::cend(rhs))) &&
2724  std::equal(std::cbegin(lhs), std::cend(lhs), std::cbegin(rhs));
2725  }
2726 
2727  /// Equality comparison.
2728  template <class ForwardRange>
2729  friend bool operator==(const ForwardRange& lhs,
2730  const UsdPrimSubtreeRange& rhs) {
2731  return rhs == lhs;
2732  }
2733 
2734  /// Inequality comparison.
2735  friend bool operator!=(const UsdPrimSubtreeRange &lhs,
2736  const UsdPrimSubtreeRange &rhs) {
2737  return !lhs.equal(rhs);
2738  }
2739 
2740  /// Inequality comparison.
2741  template <class ForwardRange>
2742  friend bool operator!=(const ForwardRange& lhs,
2743  const UsdPrimSubtreeRange& rhs) {
2744  return !(lhs == rhs);
2745  }
2746 
2747  /// Inequality comparison.
2748  template <class ForwardRange>
2749  friend bool operator!=(const UsdPrimSubtreeRange& lhs,
2750  const ForwardRange& rhs) {
2751  return !(lhs == rhs);
2752  }
2753 
2754  iterator _begin;
2755  iterator _end;
2756 };
2757 
2758 // Inform TfIterator it should feel free to make copies of the range type.
2759 template <>
2761  UsdPrimSubtreeRange> : std::true_type {};
2762 template <>
2764  const UsdPrimSubtreeRange> : std::true_type {};
2765 
2768 {
2769  return _MakeDescendantsRange(
2771 }
2772 
2775 {
2777 }
2778 
2781 {
2783 }
2784 
2785 // Helper to make a sibling range.
2787 UsdPrim::_MakeDescendantsRange(const Usd_PrimFlagsPredicate &pred) const {
2788  Usd_PrimDataConstPtr firstChild = get_pointer(_Prim());
2789  SdfPath firstChildPath = _ProxyPrimPath();
2790  Usd_PrimDataConstPtr endChild = firstChild;
2791  SdfPath endChildPath = firstChildPath;
2792  if (Usd_MoveToChild(firstChild, firstChildPath, pred)) {
2793  while (Usd_MoveToNextSiblingOrParent(endChild, endChildPath, pred)) {}
2794  }
2795 
2796  return SubtreeRange(
2797  SubtreeIterator(firstChild, firstChildPath, pred),
2798  SubtreeIterator(endChild, endChildPath, pred));
2799 }
2800 
2801 
2802 ////////////////////////////////////////////////////////////////////////
2803 // UsdObject methods that require UsdPrim be a complete type.
2804 
2805 inline UsdPrim
2807 {
2808  return UsdPrim(_prim, _proxyPrimPath);
2809 }
2810 
2812 
2813 #endif // PXR_USD_USD_PRIM_H
2814 
UsdPrimSubtreeIterator iterator
Iterator type.
Definition: prim.h:2645
USD_API bool IsSubComponent() const
bool HasAPIInFamily(UsdSchemaRegistry::VersionPolicy versionPolicy, const TfToken &instanceName) const
Definition: prim.h:891
std::ptrdiff_t difference_type
Iterator difference type.
Definition: prim.h:2392
USD_API SdfPrimSpecHandleVector GetPrimStack() const
UsdLoadPolicy
Definition: common.h:99
bool IsDefined() const
Definition: primData.h:120
bool IsModel() const
Definition: primData.h:103
void Usd_MoveToParent(PrimDataPtr &p, SdfPath &proxyPrimPath)
Definition: primData.h:504
friend class UsdPrim
Definition: prim.h:2342
bool HasAPI() const
Definition: prim.h:743
UsdPrimSubtreeIterator const_iterator
Const iterator type.
Definition: prim.h:2647
UsdPrimSubtreeIterator operator++(int)
Postincrement.
Definition: prim.h:2575
USD_API const class PcpPrimIndex & GetPrimIndex() const
iterator::value_type value_type
Iterator value_type.
Definition: prim.h:2651
USD_API UsdResolveTarget MakeResolveTargetStrongerThanEditTarget(const UsdEditTarget &editTarget) const
pointer operator->() const
Indirection.
Definition: prim.h:2566
reference operator*() const
Dereference.
Definition: prim.h:2564
Usd_PrimFlagsPredicate Usd_CreatePredicateForTraversal(const PrimDataPtr &p, const SdfPath &proxyPrimPath, Usd_PrimFlagsPredicate pred)
Definition: primData.h:484
#define USD_API
Definition: api.h:23
USD_API bool HasAuthoredPayloads() const
Return true if this prim has any authored payloads.
std::ptrdiff_t difference_type
Definition: prim.h:2558
iterator begin() const
First iterator.
Definition: prim.h:2663
UsdPrim GetPrimInPrototype() const
Definition: prim.h:2109
friend bool operator==(const UsdPrimSiblingRange &lhs, const ForwardRange &rhs)
Equality comparison.
Definition: prim.h:2455
bool HasClassSpecifier() const
Return true if this prim has the specifier SdfSpecifierClass.
Definition: prim.h:287
USD_API UsdVariantSet GetVariantSet(const std::string &variantSetName) const
USD_API std::vector< UsdAttribute > GetAuthoredAttributes() const
_PtrProxy pointer
Definition: prim.h:2308
Single Apply API schema.
bool CanApplyAPI(std::string *whyNot=nullptr) const
Definition: prim.h:1012
friend bool operator!=(const UsdPrimSiblingRange &lhs, const UsdPrimSiblingRange &rhs)
Inequality comparison.
Definition: prim.h:2475
SiblingRange GetChildren() const
Definition: prim.h:2520
USD_API bool HasAuthoredInherits() const
Return true if this prim has any authored inherits.
USD_API bool HasAuthoredMetadata(const TfToken &key) const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
SdfSpecifier GetSpecifier() const
Return this prim's composed specifier.
Definition: prim.h:152
bool HasAuthoredInstanceable() const
Definition: prim.h:2051
pointer operator->() const
Indirection.
Definition: prim.h:2318
USD_API SdfPathVector FindAllRelationshipTargetPaths(Usd_PrimFlagsPredicate const &traversalPredicate, std::function< bool(UsdRelationship const &)> const &pred=nullptr, bool recurseOnTargets=false) const
USD_API bool IsInFamily(const TfToken &schemaFamily) const
UsdPrimSiblingRange SiblingRange
Definition: prim.h:121
void ClearPropertyOrder() const
Definition: prim.h:472
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API UsdRelationship CreateRelationship(const TfToken &relName, bool custom=true) const
#define TF_CODING_ERROR
static USD_API bool IsPathInPrototype(const SdfPath &path)
SiblingRange GetAllChildren() const
Return all this prim's children as an iterable range.
Definition: prim.h:2514
const UsdPrimTypeInfo & GetPrimTypeInfo() const
Definition: prim.h:140
USD_API UsdAttribute CreateAttribute(const TfToken &name, const SdfValueTypeName &typeName, bool custom, SdfVariability variability=SdfVariabilityVarying) const
USD_API SdfPathVector FindAllAttributeConnectionPaths(Usd_PrimFlagsPredicate const &traversalPredicate, std::function< bool(UsdAttribute const &)> const &pred=nullptr, bool recurseOnSources=false) const
bool IsInstanceProxy() const
Definition: prim.h:2065
SubtreeRange GetAllDescendants() const
Definition: prim.h:2774
USD_API TfTokenVector GetAllChildrenNames() const
USD_API SdfSpecifier GetSpecifier() const
Return this prim's composed specifier.
USD_API bool HasAuthoredReferences() const
Return true if this prim has any authored references.
void ClearChildrenReorder() const
Definition: prim.h:1537
friend bool operator==(const UsdPrimSubtreeRange &lhs, const ForwardRange &rhs)
Equality comparison.
Definition: prim.h:2714
USD_API bool SetMetadata(const TfToken &key, VtValueRef value) const
UsdPrimSiblingRange(UsdPrimSiblingIterator begin, UsdPrimSiblingIterator end)
Construct with a pair of iterators.
Definition: prim.h:2401
const UsdPrimDefinition & GetPrimDefinition() const
Definition: prim.h:147
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
Definition: ImathFun.h:105
friend bool operator==(const UsdPrimSiblingRange &lhs, const UsdPrimSiblingRange &rhs)
Equality comparison.
Definition: prim.h:2448
USD_API UsdProperty GetPropertyAtPath(const SdfPath &path) const
UsdObjType
Definition: object.h:35
bool operator==(const UsdPrimSiblingIterator &other) const
Definition: prim.h:2333
USD_API UsdPrim GetPrimAtPath(const SdfPath &path) const
USD_API bool GetVersionIfHasAPIInFamily(const TfToken &schemaFamily, UsdSchemaVersion *schemaVersion) const
friend bool operator!=(const UsdPrimSubtreeRange &lhs, const UsdPrimSubtreeRange &rhs)
Inequality comparison.
Definition: prim.h:2735
**But if you need a result
Definition: thread.h:622
USD_API bool HasProperty(const TfToken &propName) const
USD_API void Load(UsdLoadPolicy policy=UsdLoadWithDescendants) const
USD_API bool RemoveProperty(const TfToken &propName)
bool GetMetadata(const TfToken &key, T *value) const
Definition: object.h:739
USD_API bool ClearMetadata(const TfToken &key) const
USD_API bool RemoveAppliedSchema(const TfToken &appliedSchemaName) const
OutGridT const XformOp bool bool
USD_API std::vector< UsdProperty > GetAuthoredProperties(const PropertyPredicateFunc &predicate={}) const
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
Definition: weakPtrFacade.h:63
bool HasAPI(const TfToken &instanceName) const
Definition: prim.h:763
USD_API UsdPrim GetPrototype() const
bool IsDefined() const
Definition: prim.h:284
UsdPrimSiblingIterator & operator++()
Preincrement.
Definition: prim.h:2321
USD_API TfTokenVector GetPropertyNames(const PropertyPredicateFunc &predicate={}) const
USD_API std::vector< UsdProperty > GetProperties(const PropertyPredicateFunc &predicate={}) const
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
friend struct UsdPrim_AttrConnectionFinder
Definition: prim.h:2223
bool IsLoaded() const
Definition: prim.h:251
bool IsActive() const
Definition: prim.h:221
unsigned int UsdSchemaVersion
Schema versions are specified as a single unsigned integer value.
bool equal(const UsdPrimSiblingRange &other) const
Equality compare.
Definition: prim.h:2421
USD_API bool ClearPayload() const
bool IsGroup() const
Definition: primData.h:108
UsdPrimSiblingRange & advance_begin(difference_type n)
Advance this range's begin iterator.
Definition: prim.h:2432
const_iterator cbegin() const
First iterator.
Definition: prim.h:2409
UsdPrimSiblingRange & advance_end(difference_type n)
Advance this range's end iterator.
Definition: prim.h:2438
bool IsA() const
Definition: prim.h:593
friend bool operator!=(const UsdPrimSubtreeRange &lhs, const ForwardRange &rhs)
Inequality comparison.
Definition: prim.h:2749
bool IsInFamily(UsdSchemaRegistry::VersionPolicy versionPolicy) const
Definition: prim.h:639
bool IsPrototype() const
Return true if this prim is a shared prototype prim, false otherwise.
Definition: primData.h:234
iterator end() const
Past-the-end iterator.
Definition: prim.h:2669
GLdouble n
Definition: glcorearb.h:2008
bool RemoveAPI(const TfToken &instanceName) const
Definition: prim.h:1297
#define TF_DEV_AXIOM(cond)
friend bool operator!=(const ForwardRange &lhs, const UsdPrimSiblingRange &rhs)
Inequality comparison.
Definition: prim.h:2482
Definition: token.h:70
USD_API UsdProperty GetProperty(const TfToken &propName) const
reference front() const
Return *begin(). This range must not be empty.
Definition: prim.h:2685
friend bool operator!=(const UsdPrimSiblingRange &lhs, const ForwardRange &rhs)
Inequality comparison.
Definition: prim.h:2489
USD_API bool IsSubComponent() const
Definition: prim.h:277
USD_API const class PcpPrimIndex & GetSourcePrimIndex() const
reference operator*() const
Dereference.
Definition: prim.h:2315
bool IsGroup() const
Definition: prim.h:263
static USD_API void ApplyPropertyOrder(const TfTokenVector &order, TfTokenVector *names)
bool IsInstance() const
Definition: primData.h:231
USD_API bool HasAttribute(const TfToken &attrName) const
USD_API bool HasRelationship(const TfToken &relName) const
USD_API void Unload() const
std::vector< class SdfPath > SdfPathVector
USD_API TfTokenVector GetFilteredChildrenNames(const Usd_PrimFlagsPredicate &predicate) const
UsdPrimSiblingIterator iterator
Iterator type.
Definition: prim.h:2388
bool Usd_IsInstanceProxy(const PrimDataPtr &p, const SdfPath &proxyPrimPath)
Definition: primData.h:470
USD_API bool HasAuthoredSpecializes() const
Returns true if this prim has any authored specializes.
GLuint GLuint end
Definition: glcorearb.h:475
USD_API UsdReferences GetReferences() const
bool HasClassSpecifier() const
Return true if this prim has the specifier SdfSpecifierClass.
Definition: primData.h:129
const SdfPath & GetPrimPath() const
Definition: object.h:202
bool SetInstanceable(bool instanceable) const
Definition: prim.h:2039
USD_API UsdAttribute GetAttributeAtPath(const SdfPath &path) const
bool HasAuthoredActive() const
Definition: prim.h:244
bool operator==(const UsdPrimSubtreeIterator &other) const
Equality.
Definition: prim.h:2582
const_iterator cend() const
Past-the-end iterator.
Definition: prim.h:2672
const UsdPrimDefinition & GetPrimDefinition() const
Returns the prim definition for this prim.
Definition: primData.h:74
static USD_API bool IsPrototypePath(const SdfPath &path)
void SetPropertyOrder(const TfTokenVector &order) const
Definition: prim.h:458
USD_API bool AddAppliedSchema(const TfToken &appliedSchemaName) const
UsdPrimSiblingIterator const_iterator
Const iterator type.
Definition: prim.h:2390
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
USD_API bool SetPayload(const SdfPayload &payload) const
Definition: prim.h:116
bool ApplyAPI(const TfToken &instanceName) const
Definition: prim.h:1176
std::forward_iterator_tag iterator_category
Definition: prim.h:2305
std::function< bool(const TfToken &propertyName)> PropertyPredicateFunc
Definition: prim.h:312
SdfSpecifier
Definition: types.h:103
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
friend bool operator==(const ForwardRange &lhs, const UsdPrimSubtreeRange &rhs)
Equality comparison.
Definition: prim.h:2729
friend struct UsdPrim_RelTargetFinder
Definition: prim.h:2222
friend bool operator==(const UsdPrimSubtreeRange &lhs, const UsdPrimSubtreeRange &rhs)
Equality comparison.
Definition: prim.h:2707
const SdfPath & _ProxyPrimPath() const
Definition: object.h:717
bool IsAbstract() const
Return true if this prim or any of its ancestors is a class.
Definition: prim.h:280
bool HasDefiningSpecifier() const
Definition: primData.h:124
friend bool operator==(const ForwardRange &lhs, const UsdPrimSiblingRange &rhs)
Equality comparison.
Definition: prim.h:2469
GLuint const GLchar * name
Definition: glcorearb.h:786
USD_API const TfTokenVector & GetAppliedSchemas() const
Definition: path.h:280
bool IsPrototype() const
Definition: prim.h:2090
USD_API PcpPrimIndex ComputeExpandedPrimIndex() const
bool HasAuthoredTypeName() const
Return true if a typeName has been authored.
Definition: prim.h:213
USD_API UsdRelationship GetRelationshipAtPath(const SdfPath &path) const
bool ClearInstanceable() const
Definition: prim.h:2045
void SetChildrenReorder(const TfTokenVector &order) const
Definition: prim.h:1531
UsdPrim GetParent() const
Definition: prim.h:1548
USD_API UsdPayloads GetPayloads() const
bool ClearTypeName() const
Definition: prim.h:208
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
bool Usd_MoveToChild(PrimDataPtr &p, SdfPath &proxyPrimPath, PrimDataPtr end, const Usd_PrimFlagsPredicate &pred)
Definition: primData.h:591
USD_API TfTokenVector GetAuthoredPropertyNames(const PropertyPredicateFunc &predicate={}) const
const Usd_PrimData * Usd_PrimDataConstPtr
bool IsAbstract() const
Return true if this prim or any of its ancestors is a class.
Definition: primData.h:116
USD_API UsdInherits GetInherits() const
bool RemoveAPI() const
Definition: prim.h:1255
USD_API UsdPrim GetNextSibling() const
UsdPrimSubtreeRange & advance_end(difference_type n)
Advance this range's end iterator.
Definition: prim.h:2697
SdfVariability
Definition: types.h:159
iterator end() const
Past-the-end iterator.
Definition: prim.h:2412
USD_API UsdVariantSets GetVariantSets() const
friend class UsdPrim
Definition: prim.h:2593
friend struct Usd_StageImplAccess
Definition: prim.h:2221
UsdPrimSiblingIterator operator++(int)
Postincrement.
Definition: prim.h:2327
const Usd_PrimDataHandle & _Prim() const
Definition: object.h:711
UsdPrim GetPrim() const
Definition: prim.h:2806
SubtreeRange GetDescendants() const
Definition: prim.h:2780
reference front() const
Return *begin(). This range must not be empty.
Definition: prim.h:2426
bool operator!=(const UsdPrimSubtreeIterator &other) const
Inequality.
Definition: prim.h:2587
USD_API std::vector< UsdRelationship > GetRelationships() const
Like GetProperties(), but exclude all attributes from the result.
UsdPrimSubtreeRange()=default
bool IsInstance() const
Definition: prim.h:2060
SubtreeRange GetFilteredDescendants(const Usd_PrimFlagsPredicate &predicate) const
Definition: prim.h:2767
USD_API UsdResolveTarget MakeResolveTargetUpToEditTarget(const UsdEditTarget &editTarget) const
USD_API const Usd_PrimFlagsConjunction UsdPrimDefaultPredicate
bool IsComponent() const
Definition: prim.h:268
bool equal(const UsdPrimSubtreeRange &other) const
Equality compare.
Definition: prim.h:2680
iterator::value_type value_type
Iterator value_type.
Definition: prim.h:2394
bool ClearActive() const
Definition: prim.h:236
bool ApplyAPI() const
Definition: prim.h:1135
USD_API const Usd_PrimFlagsPredicate UsdPrimAllPrimsPredicate
bool Usd_MoveToNextSiblingOrParent(PrimDataPtr &p, SdfPath &proxyPrimPath, PrimDataPtr end, const Usd_PrimFlagsPredicate &pred)
Definition: primData.h:534
iterator::reference reference
Iterator reference_type.
Definition: prim.h:2396
const PcpPrimIndex & GetPrimIndex() const
Definition: prim.h:2152
USD_API std::vector< UsdProperty > GetAuthoredPropertiesInNamespace(const std::vector< std::string > &namespaces) const
bool IsModel() const
Definition: prim.h:255
USD_API TfTokenVector GetPropertyOrder() const
Return the strongest propertyOrder metadata value authored on this prim.
bool IsInstanceable() const
Definition: prim.h:2031
UsdPrimSubtreeIterator SubtreeIterator
Convenience typedefs.
Definition: prim.h:124
USD_API UsdObject GetObjectAtPath(const SdfPath &path) const
USD_API std::vector< UsdRelationship > GetAuthoredRelationships() const
UsdPrimSubtreeIterator()=default
bool HasAPIInFamily(UsdSchemaRegistry::VersionPolicy versionPolicy) const
Definition: prim.h:869
USD_API TfTokenVector GetChildrenNames() const
bool empty() const
Return begin() == end().
Definition: prim.h:2444
USD_API UsdSpecializes GetSpecializes() const
const_iterator cend() const
Past-the-end iterator.
Definition: prim.h:2415
bool IsComponent() const
Definition: primData.h:110
const TfToken & GetTypeName() const
Definition: prim.h:199
USD_API std::vector< std::pair< SdfPrimSpecHandle, SdfLayerOffset > > GetPrimStackWithLayerOffsets() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API TfTokenVector GetChildrenReorder() const
USD_API UsdRelationship GetRelationship(const TfToken &relName) const
std::ptrdiff_t difference_type
Iterator difference type.
Definition: prim.h:2649
Definition: type.h:47
bool IsLoaded() const
Definition: primData.h:99
USD_API UsdPrim GetChild(const TfToken &name) const
USD_API bool HasVariantSets() const
bool CanApplyAPI(const TfToken &instanceName, std::string *whyNot=nullptr) const
Definition: prim.h:1046
USD_API bool HasAPIInFamily(const TfToken &schemaFamily) const
OIIO_UTIL_API const char * c_str(string_view str)
USD_API std::vector< UsdAttribute > GetAttributes() const
Like GetProperties(), but exclude all relationships from the result.
const TfToken & GetTypeName() const
Definition: primData.h:80
USD_API std::vector< UsdPrim > GetInstances() const
bool SetTypeName(const TfToken &typeName) const
Author this Prim's typeName at the current EditTarget.
Definition: prim.h:202
bool IsActive() const
Definition: primData.h:94
bool SetSpecifier(SdfSpecifier specifier) const
Definition: prim.h:188
USD_API UsdPrim GetFilteredNextSibling(const Usd_PrimFlagsPredicate &predicate) const
friend bool operator!=(const ForwardRange &lhs, const UsdPrimSubtreeRange &rhs)
Inequality comparison.
Definition: prim.h:2742
SIM_API const UT_StringHolder distance
USD_API bool GetVersionIfIsInFamily(const TfToken &schemaFamily, UsdSchemaVersion *schemaVersion) const
UsdPrimSiblingRange()=default
bool empty() const
Return begin() == end().
Definition: prim.h:2703
UsdPrimSubtreeRange & advance_begin(difference_type n)
Advance this range's begin iterator.
Definition: prim.h:2691
UsdPrim()
Construct an invalid prim.
Definition: prim.h:128
UsdPrimSubtreeIterator & operator++()
Preincrement.
Definition: prim.h:2569
bool SetActive(bool active) const
Definition: prim.h:227
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
bool HasDefiningSpecifier() const
Definition: prim.h:293
USD_API bool GetKind(TfToken *kind) const
USD_API std::vector< UsdProperty > GetPropertiesInNamespace(const std::vector< std::string > &namespaces) const
UsdPrimSubtreeRange SubtreeRange
Definition: prim.h:125
bool operator!=(const UsdPrimSiblingIterator &other) const
Definition: prim.h:2337
const_iterator cbegin() const
First iterator.
Definition: prim.h:2666
UsdSchemaVersion version
The version number of the schema within its schema family.
iterator::reference reference
Iterator reference_type.
Definition: prim.h:2653
USD_API bool HasPayload() const
UsdPrimSiblingIterator SiblingIterator
Convenience typedefs.
Definition: prim.h:120
Multiple Apply API Schema.
iterator begin() const
First iterator.
Definition: prim.h:2406
std::ptrdiff_t difference_type
Definition: prim.h:2309
const UsdPrimTypeInfo & GetPrimTypeInfo() const
Returns the full type info for the prim.
Definition: primData.h:85
Load a prim plus all its descendants.
Definition: common.h:101
USD_API bool SetKind(const TfToken &kind) const
bool IsInPrototype() const
Definition: prim.h:2096
SiblingRange GetFilteredChildren(const Usd_PrimFlagsPredicate &predicate) const
Definition: prim.h:2507
UsdPrimSiblingIterator()=default
_PtrProxy pointer
Definition: prim.h:2557
friend const PcpPrimIndex & Usd_PrimGetSourcePrimIndex(const UsdPrim &)
std::forward_iterator_tag iterator_category
Definition: prim.h:2554
USD_API bool IsPseudoRoot() const
UsdPrimSubtreeRange(UsdPrimSubtreeIterator begin, UsdPrimSubtreeIterator end)
Construct with a pair of iterators.
Definition: prim.h:2658