HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
identity.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_SDF_IDENTITY_H
8 #define PXR_USD_SDF_IDENTITY_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/api.h"
13 #include "pxr/usd/sdf/path.h"
14 
15 #include <memory>
16 
18 
20 class Sdf_IdRegistryImpl;
21 
23 
24 /// \class Sdf_Identity
25 ///
26 /// Identifies the logical object behind an SdfSpec.
27 ///
28 /// This is simply the layer the spec belongs to and the path to the spec.
29 ///
30 class Sdf_Identity {
31  Sdf_Identity(Sdf_Identity const &) = delete;
32  Sdf_Identity &operator=(Sdf_Identity const &) = delete;
33 public:
34  /// Returns the layer that this identity refers to.
35  SDF_API
36  const SdfLayerHandle &GetLayer() const;
37 
38  /// Returns the path that this identity refers to.
39  const SdfPath &GetPath() const {
40  return _path;
41  }
42 
43 private:
44  // Ref-counting ops manage _refCount.
46  friend void TfDelegatedCountDecrement(Sdf_Identity*) noexcept;
47 
50 
51  Sdf_Identity(Sdf_IdRegistryImpl *regImpl, const SdfPath &path)
52  : _refCount(0), _path(path), _regImpl(regImpl) {}
53 
54  SDF_API
55  static void _UnregisterOrDelete(Sdf_IdRegistryImpl *reg, Sdf_Identity *id)
56  noexcept;
57  void _Forget();
58 
59  mutable std::atomic_int _refCount;
60  SdfPath _path;
61  Sdf_IdRegistryImpl *_regImpl;
62 };
63 
64 // Specialize TfDelegatedCountPtr operations.
65 inline void TfDelegatedCountIncrement(PXR_NS::Sdf_Identity* p) {
66  ++p->_refCount;
67 }
68 inline void TfDelegatedCountDecrement(PXR_NS::Sdf_Identity* p) noexcept {
69  // Once the count hits zero, p is liable to be destroyed at any point,
70  // concurrently, by its owning registry if it happens to be doing a cleanup
71  // pass. Cache 'this' and the impl ptr in local variables so we have them
72  // before decrementing the count.
73  Sdf_Identity *self = p;
74  Sdf_IdRegistryImpl *reg = p->_regImpl;
75  if (--p->_refCount == 0) {
76  // Cannot use 'p' anymore here.
77  Sdf_Identity::_UnregisterOrDelete(reg, self);
78  }
79 }
80 
83  Sdf_IdentityRegistry& operator=(const Sdf_IdentityRegistry&) = delete;
84 public:
85  Sdf_IdentityRegistry(const SdfLayerHandle &layer);
87 
88  /// Returns the layer that owns this registry.
89  const SdfLayerHandle &GetLayer() const {
90  return _layer;
91  }
92 
93  /// Return the identity associated with \a path, issuing a new
94  /// one if necessary. The registry will track the identity
95  /// and update it if the logical object it represents moves
96  /// in namespace.
98 
99  /// Update identity in response to a namespace edit.
100  void MoveIdentity(const SdfPath &oldPath, const SdfPath &newPath);
101 
102 private:
103  friend class Sdf_Identity;
104 
105  friend class Sdf_IdRegistryImpl;
106 
107  // Remove the identity mapping for \a path to \a id from the registry. This
108  // is invoked when an identity's refcount hits zero.
109  SDF_API
110  void _UnregisterOrDelete();
111 
112  /// The layer that owns this registry, and on behalf of which
113  /// this registry tracks identities.
114  const SdfLayerHandle _layer;
115 
116  // Private implementation.
117  const std::unique_ptr<Sdf_IdRegistryImpl> _impl;
118 };
119 
121 
122 #endif // PXR_USD_SDF_IDENTITY_H
Definition: layer.h:81
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
atomic< int > atomic_int
Definition: atomic.h:25
Sdf_IdentityRefPtr Identify(const SdfPath &path)
SDF_API const SdfLayerHandle & GetLayer() const
Returns the layer that this identity refers to.
void MoveIdentity(const SdfPath &oldPath, const SdfPath &newPath)
Update identity in response to a namespace edit.
const SdfLayerHandle & GetLayer() const
Returns the layer that owns this registry.
Definition: identity.h:89
friend void TfDelegatedCountDecrement(Sdf_Identity *) noexcept
friend void TfDelegatedCountIncrement(Sdf_Identity *)
Definition: path.h:273
void TfDelegatedCountDecrement(PXR_NS::Sdf_Identity *p) noexcept
Definition: identity.h:68
friend class Sdf_IdRegistryImpl
Definition: identity.h:105
#define SDF_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
SDF_DECLARE_HANDLES(SdfLayer)
const SdfPath & GetPath() const
Returns the path that this identity refers to.
Definition: identity.h:39
void TfDelegatedCountIncrement(PXR_NS::Sdf_Identity *p)
Definition: identity.h:65
friend class Sdf_IdRegistryImpl
Definition: identity.h:49