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