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