HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
object.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_OBJECT_H
8 #define PXR_USD_USD_OBJECT_H
9 
10 /// \file usd/object.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/usd/common.h"
15 #include "pxr/usd/usd/primData.h"
16 #include "pxr/usd/usd/stage.h"
17 
19 #include "pxr/usd/sdf/path.h"
20 
21 #include "pxr/base/tf/hash.h"
22 #include "pxr/base/vt/valueRef.h"
23 
24 #include <type_traits>
25 
27 
28 
30 
31 /// \enum UsdObjType
32 ///
33 /// Enum values to represent the various Usd object types.
34 ///
36 {
37  // Value order matters in this enum.
43 
45 };
46 
47 
48 namespace _Detail {
49 
50 // A metafunction that takes a UsdObject class like UsdObject, UsdPrim,
51 // UsdProperty, etc, and gives its corresponding UsdObjType, e.g. UsdTypeObject,
52 // UsdTypePrim, UsdTypeProperty, etc. Usage: GetObjType<UsdPrim>::Value.
53 template <UsdObjType Type>
54 struct Const { static const UsdObjType Value = Type; };
55 template <class T> struct GetObjType {
57  "Type T must be a subclass of UsdObject.");
58 };
59 template <> struct GetObjType<UsdObject> : Const<UsdTypeObject> {};
60 template <> struct GetObjType<UsdPrim> : Const<UsdTypePrim> {};
61 template <> struct GetObjType<UsdProperty> : Const<UsdTypeProperty> {};
62 template <> struct GetObjType<UsdAttribute> : Const<UsdTypeAttribute> {};
63 template <> struct GetObjType<UsdRelationship> : Const<UsdTypeRelationship> {};
64 
65 } // _Detail
66 
67 /// Return true if \a subType is the same as or a subtype of \a baseType, false
68 /// otherwise.
69 inline bool
70 UsdIsSubtype(UsdObjType baseType, UsdObjType subType) {
71  return (baseType == UsdTypeObject) || (baseType == subType) ||
72  (baseType == UsdTypeProperty && subType > UsdTypeProperty);
73 }
74 
75 /// Return true if \a from is convertible to \a to, false otherwise. Equivalent
76 /// to UsdIsSubtype(to, from).
77 inline bool
79  return UsdIsSubtype(to, from);
80 }
81 
82 /// Return true if \a type is a concrete object type, namely one of Prim,
83 /// Attribute, or Relationship.
84 inline bool
86  return type == UsdTypePrim ||
87  type == UsdTypeAttribute ||
88  type == UsdTypeRelationship;
89 }
90 
91 /// \class UsdObject
92 ///
93 /// Base class for Usd scenegraph objects, providing common API.
94 ///
95 /// The commonality between the three types of scenegraph objects in Usd
96 /// (\ref UsdPrim, \ref UsdAttribute, \ref UsdRelationship) is that they can
97 /// all have metadata. Other objects in the API (\ref UsdReferences,
98 /// \ref UsdVariantSets, etc.) simply \em are kinds of metadata.
99 ///
100 /// UsdObject's API primarily provides schema for interacting with the metadata
101 /// common to all the scenegraph objects, as well as generic access to metadata.
102 ///
103 /// section Usd_UsdObject_Lifetime Lifetime Management and Object Validity
104 ///
105 /// Every derived class of UsdObject supports explicit detection of object
106 /// validity through an \em explicit-bool operator, so client code should always
107 /// be able use objects safely, even across edits to the owning UsdStage.
108 /// UsdObject classes also perform some level of validity checking upon every
109 /// use, in order to facilitate debugging of unsafe code, although we reserve
110 /// the right to activate that behavior only in debug builds, if it becomes
111 /// compelling to do so for performance reasons. This per-use checking will
112 /// cause a fatal error upon failing the inline validity check, with an error
113 /// message describing the namespace location of the dereferenced object on its
114 /// owning UsdStage.
115 ///
116 class UsdObject {
117 public:
118  /// Default constructor produces an invalid object.
119  UsdObject() : _type(UsdTypeObject) {}
120 
121  // --------------------------------------------------------------------- //
122  /// \name Structural and Integrity Info about the Object itself
123  /// @{
124  // --------------------------------------------------------------------- //
125 
126  /// Return true if this is a valid object, false otherwise.
127  bool IsValid() const {
128  if (!UsdIsConcrete(_type) || !_prim)
129  return false;
130  if (_type == UsdTypePrim)
131  return true;
132  SdfSpecType specType = _GetDefiningSpecType();
133  return (_type == UsdTypeAttribute &&
134  specType == SdfSpecTypeAttribute) ||
135  (_type == UsdTypeRelationship &&
136  specType == SdfSpecTypeRelationship);
137  }
138 
139  /// Returns \c true if this object is valid, \c false otherwise.
140  explicit operator bool() const {
141  return IsValid();
142  }
143 
144 public:
145 
146  /// Equality comparison. Return true if \a lhs and \a rhs represent the
147  /// same UsdObject, false otherwise.
148  friend bool operator==(const UsdObject &lhs, const UsdObject &rhs) {
149  return lhs._type == rhs._type &&
150  lhs._prim == rhs._prim &&
151  lhs._proxyPrimPath == rhs._proxyPrimPath &&
152  lhs._propName == rhs._propName;
153  }
154 
155  /// Inequality comparison. Return false if \a lhs and \a rhs represent the
156  /// same UsdObject, true otherwise.
157  friend bool operator!=(const UsdObject &lhs, const UsdObject &rhs) {
158  return !(lhs == rhs);
159  }
160 
161  /// Less-than operator. Returns true if \a lhs < \a rhs.
162  ///
163  /// This simply compares the paths of the objects.
164  friend bool operator<(const UsdObject &lhs, const UsdObject &rhs) {
165  return lhs.GetPath() < rhs.GetPath();
166  }
167 
168  // hash_value overload for std/boost hash.
169  friend size_t hash_value(const UsdObject &obj) {
170  return TfHash()(obj);
171  }
172 
173  // TfHash support
174  template <class HashState>
175  friend void TfHashAppend(HashState &h, const UsdObject &obj) {
176  h.Append(obj._type, obj._prim, obj._proxyPrimPath, obj._propName);
177  }
178 
179  /// Return the stage that owns the object, and to whose state and lifetime
180  /// this object's validity is tied.
181  USD_API
182  UsdStageWeakPtr GetStage() const;
183 
184  /// Return the complete scene path to this object on its UsdStage,
185  /// which may (UsdPrim) or may not (all other subclasses) return a
186  /// cached result
187  SdfPath GetPath() const {
188  // Allow getting expired object paths.
189  if (!_proxyPrimPath.IsEmpty()) {
190  return _type == UsdTypePrim ?
191  _proxyPrimPath : _proxyPrimPath.AppendProperty(_propName);
192  }
193  else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
194  return _type == UsdTypePrim ?
195  p->GetPath() : p->GetPath().AppendProperty(_propName);
196  }
197  return SdfPath();
198  }
199 
200  /// Return this object's path if this object is a prim, otherwise this
201  /// object's nearest owning prim's path. Equivalent to GetPrim().GetPath().
202  const SdfPath &GetPrimPath() const {
203  // Allow getting expired object paths.
204  if (!_proxyPrimPath.IsEmpty()) {
205  return _proxyPrimPath;
206  }
207  else if (Usd_PrimDataConstPtr p = get_pointer(_prim)) {
208  return p->GetPath();
209  }
210  return SdfPath::EmptyPath();
211  }
212 
213  /// Return this object if it is a prim, otherwise return this object's
214  /// nearest owning prim.
215  inline UsdPrim GetPrim() const;
216 
217  /// Return the full name of this object, i.e. the last component of its
218  /// SdfPath in namespace.
219  ///
220  /// This is equivalent to, but generally cheaper than,
221  /// GetPath().GetNameToken()
222  const TfToken &GetName() const {
223  return _type == UsdTypePrim ? GetPrimPath().GetNameToken() : _propName;
224  }
225 
226  /// Convert this UsdObject to another object type \p T if possible. Return
227  /// an invalid \p T instance if this object's dynamic type is not
228  /// convertible to \p T or if this object is invalid.
229  template <class T>
230  T As() const {
231  // compile-time type assertion provided by invoking Is<T>().
232  return Is<T>() ? T(_type, _prim, _proxyPrimPath, _propName) : T();
233  }
234 
235  /// Return true if this object is convertible to \p T. This is equivalent
236  /// to but cheaper than:
237  /// \code
238  /// bool(obj.As<T>())
239  /// \endcode
240  template <class T>
241  bool Is() const {
243  "Provided type T must derive from or be UsdObject");
245  }
246 
247  /// Return a string that provides a brief summary description of the
248  /// object. This method, along with IsValid()/bool_operator,
249  /// is always safe to call on a possibly-expired object, and the
250  /// description will specify whether the object is valid or expired,
251  /// along with a few other bits of data.
252  USD_API
253  std::string GetDescription() const;
254 
255  // --------------------------------------------------------------------- //
256  /// @}
257  // --------------------------------------------------------------------- //
258 
259 
260  // --------------------------------------------------------------------- //
261  /// \name Generic Metadata Access
262  /// @{
263  // --------------------------------------------------------------------- //
264 
265  /// Resolve the requested metadatum named \p key into \p value,
266  /// returning true on success.
267  ///
268  /// \return false if \p key was not resolvable, or if \p value's
269  /// type \c T differed from that of the resolved metadatum.
270  ///
271  /// \note For any composition-related metadata, as enumerated in
272  /// GetAllMetadata(), this method will return only the strongest
273  /// opinion found, not applying the composition rules used by Pcp
274  /// to process the data. For more processed/composed views of
275  /// composition data, please refer to the specific interface classes,
276  /// such as UsdReferences, UsdInherits, UsdVariantSets, etc.
277  ///
278  /// \sa \ref Usd_OM_Metadata
279  template<typename T>
280  bool GetMetadata(const TfToken& key, T* value) const;
281  /// \overload
282  ///
283  /// Type-erased access
284  USD_API
285  bool GetMetadata(const TfToken& key, VtValue* value) const;
286 
287  /// Set metadatum \p key's value to \p value.
288  ///
289  /// \return false if \p value's type does not match the schema type
290  /// for \p key.
291  ///
292  /// \sa \ref Usd_OM_Metadata
293  USD_API
294  bool SetMetadata(const TfToken& key, VtValueRef value) const;
295 
296  /// Clears the authored \a key's value at the current EditTarget,
297  /// returning false on error.
298  ///
299  /// If no value is present, this method is a no-op and returns true. It is
300  /// considered an error to call ClearMetadata when no spec is present for
301  /// this UsdObject, i.e. if the object has no presence in the
302  /// current UsdEditTarget.
303  ///
304  /// \sa \ref Usd_OM_Metadata
305  USD_API
306  bool ClearMetadata(const TfToken& key) const;
307 
308  /// Returns true if the \a key has a meaningful value, that is, if
309  /// GetMetadata() will provide a value, either because it was authored
310  /// or because a prim's metadata fallback will be provided.
311  USD_API
312  bool HasMetadata(const TfToken& key) const;
313 
314  /// Returns true if the \a key has an authored value, false if no
315  /// value was authored or the only value available is a prim's metadata
316  /// fallback.
317  USD_API
318  bool HasAuthoredMetadata(const TfToken& key) const;
319 
320  /// Resolve the requested dictionary sub-element \p keyPath of
321  /// dictionary-valued metadatum named \p key into \p value,
322  /// returning true on success.
323  ///
324  /// If you know you neeed just a small number of elements from a dictionary,
325  /// accessing them element-wise using this method can be much less
326  /// expensive than fetching the entire dictionary with GetMetadata(key).
327  ///
328  /// \return false if \p key was not resolvable, or if \p value's
329  /// type \c T differed from that of the resolved metadatum.
330  ///
331  /// The \p keyPath is a ':'-separated path addressing an element
332  /// in subdictionaries.
333  ///
334  /// \sa \ref Usd_Dictionary_Type
335  template <class T>
337  const TfToken& key, const TfToken &keyPath, T *value) const;
338  /// \overload
339  USD_API
341  const TfToken& key, const TfToken &keyPath, VtValue *value) const;
342 
343  /// Author \p value to the field identified by \p key and \p keyPath
344  /// at the current EditTarget. The \p keyPath is a ':'-separated path
345  /// identifying a value in subdictionaries stored in the metadata field at
346  /// \p key. Return true if the value is authored successfully, false
347  /// otherwise.
348  ///
349  /// \sa \ref Usd_Dictionary_Type
350  USD_API
352  const TfToken& key, const TfToken &keyPath, VtValueRef value) const;
353 
354  /// Clear any authored value identified by \p key and \p keyPath
355  /// at the current EditTarget. The \p keyPath is a ':'-separated path
356  /// identifying a path in subdictionaries stored in the metadata field at
357  /// \p key. Return true if the value is cleared successfully, false
358  /// otherwise.
359  ///
360  /// \sa \ref Usd_Dictionary_Type
361  USD_API
363  const TfToken& key, const TfToken& keyPath) const;
364 
365  /// Return true if there exists any authored or fallback opinion for
366  /// \p key and \p keyPath. The \p keyPath is a ':'-separated path
367  /// identifying a value in subdictionaries stored in the metadata field at
368  /// \p key.
369  ///
370  /// \sa \ref Usd_Dictionary_Type
371  USD_API
372  bool HasMetadataDictKey(
373  const TfToken& key, const TfToken &keyPath) const;
374 
375  /// Return true if there exists any authored opinion (excluding
376  /// fallbacks) for \p key and \p keyPath. The \p keyPath is a ':'-separated
377  /// path identifying a value in subdictionaries stored in the metadata field
378  /// at \p key.
379  ///
380  /// \sa \ref Usd_Dictionary_Type
381  USD_API
383  const TfToken& key, const TfToken &keyPath) const;
384 
385  /// Resolve and return all metadata (including both authored and
386  /// fallback values) on this object, sorted lexicographically.
387  ///
388  /// \note This method does not return field keys for composition arcs, such
389  /// as references, inherits, payloads, sublayers, variants, or primChildren,
390  /// nor does it return the default value, timeSamples, or spline.
391  USD_API
393 
394  /// Resolve and return all user-authored metadata on this object,
395  /// sorted lexicographically.
396  ///
397  /// \note This method does not return field keys for composition arcs, such
398  /// as references, inherits, payloads, sublayers, variants, or primChildren,
399  /// nor does it return the default value, timeSamples, or spline.
400  USD_API
402 
403  // --------------------------------------------------------------------- //
404  /// @}
405  // --------------------------------------------------------------------- //
406 
407  // --------------------------------------------------------------------- //
408  /// \name Core metadata fields
409  /// @{
410  // --------------------------------------------------------------------- //
411 
412  /// Gets the value of the 'hidden' metadata field, false if not
413  /// authored.
414  ///
415  /// When an object is marked as hidden, it is an indicator to clients who
416  /// generically display objects (such as GUI widgets) that this object
417  /// should not be included, unless explicitly asked for. Although this
418  /// is just a hint and thus up to each application to interpret, we
419  /// use it primarily as a way of simplifying hierarchy displays, by
420  /// hiding \em only the representation of the object itself, \em not its
421  /// subtree, instead "pulling up" everything below it one level in the
422  /// hierarchical nesting.
423  ///
424  /// Note again that this is a hint for UI only - it should not be
425  /// interpreted by any renderer as making a prim invisible to drawing.
426  USD_API
427  bool IsHidden() const;
428 
429  /// Sets the value of the 'hidden' metadata field. See IsHidden()
430  /// for details.
431  USD_API
432  bool SetHidden(bool hidden) const;
433 
434  /// Clears the opinion for "Hidden" at the current EditTarget.
435  USD_API
436  bool ClearHidden() const;
437 
438  /// Returns true if hidden was explicitly authored and GetMetadata()
439  /// will return a meaningful value for Hidden.
440  ///
441  /// Note that IsHidden returns a fallback value (false) when hidden is not
442  /// authored.
443  USD_API
444  bool HasAuthoredHidden() const;
445 
446  /// Return this object's composed customData dictionary.
447  ///
448  /// CustomData is "custom metadata", a place for applications and users
449  /// to put uniform data that is entirely dynamic and subject to no schema
450  /// known to Usd. Unlike metadata like 'hidden', 'displayName' etc,
451  /// which must be declared in code or a data file that is considered part
452  /// of one's Usd distribution (e.g. a plugInfo.json file) to be used,
453  /// customData keys and the datatypes of their corresponding values are
454  /// ad hoc. No validation will ever be performed that values for the
455  /// same key in different layers are of the same type - strongest simply
456  /// wins.
457  ///
458  /// Dictionaries like customData are composed element-wise, and are
459  /// nestable.
460  ///
461  /// There is no means to query a customData field's valuetype other
462  /// than fetching the value and interrogating it.
463  /// \sa GetCustomDataByKey()
464  USD_API
465  VtDictionary GetCustomData() const;
466 
467  /// Return the element identified by \p keyPath in this object's
468  /// composed customData dictionary. The \p keyPath is a ':'-separated path
469  /// identifying a value in subdictionaries. This is in general more
470  /// efficient than composing the entire customData dictionary and then
471  /// pulling out one sub-element.
472  USD_API
473  VtValue GetCustomDataByKey(const TfToken &keyPath) const;
474 
475  /// Author this object's customData dictionary to \p customData at
476  /// the current EditTarget.
477  USD_API
478  void SetCustomData(const VtDictionary &customData) const;
479 
480  /// Author the element identified by \p keyPath in this object's
481  /// customData dictionary at the current EditTarget. The \p keyPath is a
482  /// ':'-separated path identifying a value in subdictionaries.
483  USD_API
484  void SetCustomDataByKey(const TfToken &keyPath, const VtValue &value) const;
485 
486  /// Clear the authored opinion for this object's customData
487  /// dictionary at the current EditTarget. Do nothing if there is no such
488  /// authored opinion.
489  USD_API
490  void ClearCustomData() const;
491 
492  /// Clear the authored opinion identified by \p keyPath in this
493  /// object's customData dictionary at the current EditTarget. The \p
494  /// keyPath is a ':'-separated path identifying a value in subdictionaries.
495  /// Do nothing if there is no such authored opinion.
496  USD_API
497  void ClearCustomDataByKey(const TfToken &keyPath) const;
498 
499  /// Return true if there are any authored or fallback opinions for
500  /// this object's customData dictionary, false otherwise.
501  USD_API
502  bool HasCustomData() const;
503 
504  /// Return true if there are any authored or fallback opinions for
505  /// the element identified by \p keyPath in this object's customData
506  /// dictionary, false otherwise. The \p keyPath is a ':'-separated path
507  /// identifying a value in subdictionaries.
508  USD_API
509  bool HasCustomDataKey(const TfToken &keyPath) const;
510 
511  /// Return true if there are any authored opinions (excluding
512  /// fallback) for this object's customData dictionary, false otherwise.
513  USD_API
514  bool HasAuthoredCustomData() const;
515 
516  /// Return true if there are any authored opinions (excluding
517  /// fallback) for the element identified by \p keyPath in this object's
518  /// customData dictionary, false otherwise. The \p keyPath is a
519  /// ':'-separated path identifying a value in subdictionaries.
520  USD_API
521  bool HasAuthoredCustomDataKey(const TfToken &keyPath) const;
522 
523  /// Return this object's composed assetInfo dictionary.
524  ///
525  /// The asset info dictionary is used to annotate objects representing the
526  /// root-prims of assets (generally organized as models) with various
527  /// data related to asset management. For example, asset name, root layer
528  /// identifier, asset version etc.
529  ///
530  /// The elements of this dictionary are composed element-wise, and are
531  /// nestable.
532  ///
533  /// There is no means to query an assetInfo field's valuetype other
534  /// than fetching the value and interrogating it.
535  /// \sa GetAssetInfoByKey()
536  USD_API
537  VtDictionary GetAssetInfo() const;
538 
539  /// Return the element identified by \p keyPath in this object's
540  /// composed assetInfo dictionary. The \p keyPath is a ':'-separated path
541  /// identifying a value in subdictionaries. This is in general more
542  /// efficient than composing the entire assetInfo dictionary than
543  /// pulling out one sub-element.
544  USD_API
545  VtValue GetAssetInfoByKey(const TfToken &keyPath) const;
546 
547  /// Author this object's assetInfo dictionary to \p assetInfo at
548  /// the current EditTarget.
549  USD_API
550  void SetAssetInfo(const VtDictionary &customData) const;
551 
552  /// Author the element identified by \p keyPath in this object's
553  /// assetInfo dictionary at the current EditTarget. The \p keyPath is a
554  /// ':'-separated path identifying a value in subdictionaries.
555  USD_API
556  void SetAssetInfoByKey(const TfToken &keyPath, const VtValue &value) const;
557 
558  /// Clear the authored opinion for this object's assetInfo
559  /// dictionary at the current EditTarget. Do nothing if there is no such
560  /// authored opinion.
561  USD_API
562  void ClearAssetInfo() const;
563 
564  /// Clear the authored opinion identified by \p keyPath in this
565  /// object's assetInfo dictionary at the current EditTarget. The \p
566  /// keyPath is a ':'-separated path identifying a value in subdictionaries.
567  /// Do nothing if there is no such authored opinion.
568  USD_API
569  void ClearAssetInfoByKey(const TfToken &keyPath) const;
570 
571  /// Return true if there are any authored or fallback opinions for
572  /// this object's assetInfo dictionary, false otherwise.
573  USD_API
574  bool HasAssetInfo() const;
575 
576  /// Return true if there are any authored or fallback opinions for
577  /// the element identified by \p keyPath in this object's assetInfo
578  /// dictionary, false otherwise. The \p keyPath is a ':'-separated path
579  /// identifying a value in subdictionaries.
580  USD_API
581  bool HasAssetInfoKey(const TfToken &keyPath) const;
582 
583  /// Return true if there are any authored opinions (excluding
584  /// fallback) for this object's assetInfo dictionary, false otherwise.
585  USD_API
586  bool HasAuthoredAssetInfo() const;
587 
588  /// Return true if there are any authored opinions (excluding
589  /// fallback) for the element identified by \p keyPath in this object's
590  /// assetInfo dictionary, false otherwise. The \p keyPath is a
591  /// ':'-separated path identifying a value in subdictionaries.
592  USD_API
593  bool HasAuthoredAssetInfoKey(const TfToken &keyPath) const;
594 
595  /// Return this object's documentation (metadata). This returns the
596  /// empty string if no documentation has been set.
597  /// \sa SetDocumentation()
598  USD_API
599  std::string GetDocumentation() const;
600 
601  /// Sets this object's documentation (metadata). Returns true on success.
602  USD_API
603  bool SetDocumentation(const std::string& doc) const;
604 
605  /// Clears this object's documentation (metadata) in the current EditTarget
606  /// (only). Returns true on success.
607  USD_API
608  bool ClearDocumentation() const;
609 
610  /// Returns true if documentation was explicitly authored and GetMetadata()
611  /// will return a meaningful value for documentation.
612  USD_API
613  bool HasAuthoredDocumentation() const;
614 
615  /// Return this object's display name (metadata). This returns the
616  /// empty string if no display name has been set.
617  /// \sa SetDisplayName()
618  ///
619  /// \deprecated
620  /// See UsdUIObjectHints.
621  USD_API
622  std::string GetDisplayName() const;
623 
624  /// Sets this object's display name (metadata). Returns true on success.
625  ///
626  /// DisplayName is meant to be a descriptive label, not necessarily an
627  /// alternate identifier; therefore there is no restriction on which
628  /// characters can appear in it.
629  ///
630  /// \deprecated
631  /// See UsdUIObjectHints.
632  USD_API
633  bool SetDisplayName(const std::string& name) const;
634 
635  /// Clears this object's display name (metadata) in the current EditTarget
636  /// (only). Returns true on success.
637  ///
638  /// \deprecated
639  /// See UsdUIObjectHints.
640  USD_API
641  bool ClearDisplayName() const;
642 
643  /// Returns true if displayName was explicitly authored and GetMetadata()
644  /// will return a meaningful value for displayName.
645  ///
646  /// \deprecated
647  /// See UsdUIObjectHints.
648  USD_API
649  bool HasAuthoredDisplayName() const;
650 
651  // --------------------------------------------------------------------- //
652  /// @}
653  // --------------------------------------------------------------------- //
654 
655  // XXX: This method can and probably should move to UsdProperty
656  static char GetNamespaceDelimiter()
657  { return SdfPathTokens->namespaceDelimiter.GetText()[0]; }
658 
659 private:
660  template <class T>
661  bool _GetMetadataImpl(const TfToken& key,
662  T* value,
663  const TfToken &keyPath=TfToken()) const;
664 
665  bool _GetMetadataImpl(const TfToken& key,
666  VtValue* value,
667  const TfToken &keyPath=TfToken()) const;
668 
669  bool _SetMetadataImpl(const TfToken& key, VtValueRef value,
670  const TfToken &keyPath=TfToken()) const;
671 
672 protected:
673  template <class Derived> struct _Null {};
674 
675  // Private constructor for null dervied types.
676  template <class Derived>
678  : _type(_Detail::GetObjType<Derived>::Value) {}
679 
680  // Private constructor for UsdPrim.
682  const SdfPath &proxyPrimPath)
683  : _type(UsdTypePrim)
684  , _prim(prim)
685  , _proxyPrimPath(proxyPrimPath)
686  {
687  TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
688  }
689 
690  // Private constructor for UsdAttribute/UsdRelationship.
692  const Usd_PrimDataHandle &prim,
693  const SdfPath &proxyPrimPath,
694  const TfToken &propName)
695  : _type(objType)
696  , _prim(prim)
697  , _proxyPrimPath(proxyPrimPath)
698  , _propName(propName)
699  {
700  TF_VERIFY(!_prim || _prim->GetPath() != _proxyPrimPath);
701  }
702 
703  // Return the stage this object belongs to.
704  UsdStage *_GetStage() const { return _prim->GetStage(); }
705 
706  // Return this object's defining spec type.
707  USD_API
709 
710  // Helper for subclasses: return held prim data.
711  const Usd_PrimDataHandle &_Prim() const { return _prim; }
712 
713  // Helper for subclasses: return held property name.
714  const TfToken &_PropName() const { return _propName; }
715 
716  // Helper for subclasses: return held proxy prim path.
717  const SdfPath &_ProxyPrimPath() const { return _proxyPrimPath; }
718 
719 private:
720  // Helper for the above helper, and also for GetDescription()
721  std::string _GetObjectDescription(const std::string &preface) const;
722 
723  friend class UsdStage;
724 
725  friend UsdObjType Usd_GetObjType(const UsdObject &obj) {
726  return obj._type;
727  }
728 
729  UsdObjType _type;
730  Usd_PrimDataHandle _prim;
731  SdfPath _proxyPrimPath;
732  TfToken _propName;
733 
734 };
735 
736 template<typename T>
737 inline
738 bool
739 UsdObject::GetMetadata(const TfToken& key, T* value) const
740 {
741  return _GetMetadataImpl(key, value);
742 }
743 
744 template <typename T>
745 inline
746 bool
748  const TfToken &keyPath,
749  T *value) const
750 {
751  return _GetMetadataImpl(key, value, keyPath);
752 }
753 
754 template <class T>
755 bool
756 UsdObject::_GetMetadataImpl(const TfToken& key,
757  T* value,
758  const TfToken &keyPath) const
759 {
760  return _GetStage()->_GetMetadata(
761  *this, key, keyPath, /*useFallbacks=*/true, value);
762 }
763 
765 
766 #endif //PXR_USD_USD_OBJECT_H
USD_API bool IsHidden() const
USD_API bool ClearDocumentation() const
UsdStage * _GetStage() const
Definition: object.h:704
bool UsdIsConcrete(UsdObjType type)
Definition: object.h:85
USD_API void SetAssetInfoByKey(const TfToken &keyPath, const VtValue &value) const
USD_API void SetCustomData(const VtDictionary &customData) const
#define USD_API
Definition: api.h:23
USD_API bool SetHidden(bool hidden) const
USD_API bool HasAuthoredAssetInfo() const
USD_API void ClearAssetInfoByKey(const TfToken &keyPath) const
USD_API bool HasAuthoredMetadata(const TfToken &key) const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
USD_API VtValue GetCustomDataByKey(const TfToken &keyPath) const
UsdObject()
Default constructor produces an invalid object.
Definition: object.h:119
USD_API void SetCustomDataByKey(const TfToken &keyPath, const VtValue &value) const
USD_API void ClearCustomData() const
static char GetNamespaceDelimiter()
Definition: object.h:656
friend size_t hash_value(const UsdObject &obj)
Definition: object.h:169
friend bool operator<(const UsdObject &lhs, const UsdObject &rhs)
Definition: object.h:164
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:405
USD_API bool SetMetadata(const TfToken &key, VtValueRef value) const
UsdObjType
Definition: object.h:35
UsdObject(_Null< Derived >)
Definition: object.h:677
bool GetMetadata(const TfToken &key, T *value) const
Definition: object.h:739
USD_API bool ClearMetadata(const TfToken &key) const
bool GetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, T *value) const
Definition: object.h:747
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
USD_API bool HasCustomData() const
OutGridT const XformOp bool bool
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
Definition: weakPtrFacade.h:63
USD_API bool HasAuthoredHidden() const
const SdfPath & GetPath() const
Definition: primData.h:67
Definition: hash.h:472
USD_API bool SetDisplayName(const std::string &name) const
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
USD_API VtDictionary GetCustomData() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
USD_API UsdMetadataValueMap GetAllAuthoredMetadata() const
UsdStage * GetStage() const
Definition: primData.h:71
USD_API VtValue GetAssetInfoByKey(const TfToken &keyPath) const
A generic, discriminated value, whose type may be queried dynamically.
Definition: Value.h:45
USD_API bool HasAuthoredMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
USD_API bool HasMetadata(const TfToken &key) const
USD_API void ClearAssetInfo() const
const SdfPath & GetPrimPath() const
Definition: object.h:202
USD_API bool SetMetadataByDictKey(const TfToken &key, const TfToken &keyPath, VtValueRef value) const
Definition: prim.h:116
USD_API void SetAssetInfo(const VtDictionary &customData) const
USD_API bool HasCustomDataKey(const TfToken &keyPath) const
USD_API void ClearCustomDataByKey(const TfToken &keyPath) const
const SdfPath & _ProxyPrimPath() const
Definition: object.h:717
USD_API SdfSpecType _GetDefiningSpecType() const
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:280
std::map< class TfToken, VtValue, TfDictionaryLessThan > UsdMetadataValueMap
Definition: common.h:64
const TfToken & GetName() const
Definition: object.h:222
USD_API VtDictionary GetAssetInfo() const
USD_API bool HasAuthoredAssetInfoKey(const TfToken &keyPath) const
SDF_API const TfToken & GetNameToken() const
UsdObject(const Usd_PrimDataHandle &prim, const SdfPath &proxyPrimPath)
Definition: object.h:681
USD_API bool ClearMetadataByDictKey(const TfToken &key, const TfToken &keyPath) const
USD_API bool HasAssetInfoKey(const TfToken &keyPath) const
USD_API UsdStageWeakPtr GetStage() const
T As() const
Definition: object.h:230
SDF_API SdfPath AppendProperty(TfToken const &propName) const
UsdObject(UsdObjType objType, const Usd_PrimDataHandle &prim, const SdfPath &proxyPrimPath, const TfToken &propName)
Definition: object.h:691
const Usd_PrimDataHandle & _Prim() const
Definition: object.h:711
UsdPrim GetPrim() const
Definition: prim.h:2806
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
SdfPath GetPath() const
Definition: object.h:187
USD_API std::string GetDescription() const
USD_API bool ClearDisplayName() const
bool IsValid() const
Return true if this is a valid object, false otherwise.
Definition: object.h:127
SdfSpecType
Definition: types.h:71
friend UsdObjType Usd_GetObjType(const UsdObject &obj)
Definition: object.h:725
friend bool operator==(const UsdObject &lhs, const UsdObject &rhs)
Definition: object.h:148
friend bool operator!=(const UsdObject &lhs, const UsdObject &rhs)
Definition: object.h:157
bool UsdIsSubtype(UsdObjType baseType, UsdObjType subType)
Definition: object.h:70
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool UsdIsConvertible(UsdObjType from, UsdObjType to)
Definition: object.h:78
USD_API UsdMetadataValueMap GetAllMetadata() const
bool Is() const
Definition: object.h:241
friend void TfHashAppend(HashState &h, const UsdObject &obj)
Definition: object.h:175
USD_API bool HasAssetInfo() const
USD_API bool HasAuthoredDisplayName() const
const TfToken & _PropName() const
Definition: object.h:714
USD_API std::string GetDocumentation() const
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(UsdStage)
USD_API bool SetDocumentation(const std::string &doc) const
Sets this object's documentation (metadata). Returns true on success.
USD_API bool HasAuthoredCustomDataKey(const TfToken &keyPath) const
USD_API bool HasMetadataDictKey(const TfToken &key, const TfToken &keyPath) const
USD_API bool HasAuthoredCustomData() const
USD_API std::string GetDisplayName() const
Definition: value.h:89
USD_API bool ClearHidden() const
Clears the opinion for "Hidden" at the current EditTarget.
USD_API bool HasAuthoredDocumentation() const