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 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_SDF_IDENTITY_H
25 #define PXR_USD_SDF_IDENTITY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/tf/hashmap.h"
29 #include "pxr/usd/sdf/api.h"
31 #include "pxr/usd/sdf/path.h"
32 
33 #include <hboost/intrusive_ptr.hpp>
34 #include <hboost/noncopyable.hpp>
35 #include <tbb/spin_mutex.h>
36 
38 
41 
42 /// \class Sdf_Identity
43 ///
44 /// Identifies the logical object behind an SdfSpec.
45 ///
46 /// This is simply the layer the spec belongs to and the path to the spec.
47 ///
48 class Sdf_Identity : public hboost::noncopyable {
49 public:
50  /// Returns the layer that this identity refers to.
51  SDF_API
52  const SdfLayerHandle &GetLayer() const;
53 
54  /// Returns the path that this identity refers to.
55  const SdfPath &GetPath() const {
56  return _path;
57  }
58 
59 private:
60  // Ref-counting ops manage _refCount.
61  friend void intrusive_ptr_add_ref(Sdf_Identity*);
62  friend void intrusive_ptr_release(Sdf_Identity*);
63 
64  friend class Sdf_IdentityRegistry;
65 
66  SDF_API
67  Sdf_Identity(Sdf_IdentityRegistry *registry, const SdfPath &path);
68  SDF_API
69  ~Sdf_Identity();
70 
71  void _Forget();
72 
73  mutable std::atomic_int _refCount;
74  Sdf_IdentityRegistry *_registry;
75  SdfPath _path;
76 };
77 
78 // Specialize hboost::intrusive_ptr operations.
79 inline void intrusive_ptr_add_ref(PXR_NS::Sdf_Identity* p) {
80  ++p->_refCount;
81 }
82 inline void intrusive_ptr_release(PXR_NS::Sdf_Identity* p) {
83  if (--p->_refCount == 0) {
84  delete p;
85  }
86 }
87 
88 class Sdf_IdentityRegistry : public hboost::noncopyable {
89 public:
90  Sdf_IdentityRegistry(const SdfLayerHandle &layer);
92 
93  /// Returns the layer that owns this registry.
94  const SdfLayerHandle &GetLayer() const {
95  return _layer;
96  }
97 
98  /// Return the identity associated with \a path, issuing a new
99  /// one if necessary. The registry will track the identity
100  /// and update it if the logical object it represents moves
101  /// in namespace.
103 
104  /// Update identity in response to a namespace edit.
105  void MoveIdentity(const SdfPath &oldPath, const SdfPath &newPath);
106 
107 private:
108  // When an identity expires, it will remove itself from the registry.
109  friend class Sdf_Identity;
110 
111  // Remove the identity mapping for \a path to \a id from the registry.
112  // This is only called by Sdf_Identity's destructor.
113  void _Remove(const SdfPath &path, Sdf_Identity *id);
114 
115  /// The layer that owns this registry, and on behalf of which
116  /// this registry tracks identities.
117  const SdfLayerHandle _layer;
118 
119  /// The identities being managed by this registry
121  _IdMap _ids;
122 
123  /// Cache the last fetched identity, it's commonly re-fetched.
124  Sdf_IdentityRefPtr _lastId;
125 
126  // This mutex synchronizes access to _ids.
127  tbb::spin_mutex _idsMutex;
128 };
129 
131 
132 #endif // PXR_USD_SDF_IDENTITY_H
Definition: layer.h:93
void intrusive_ptr_release(PXR_NS::Sdf_Identity *p)
Definition: identity.h:82
hboost::intrusive_ptr< Sdf_Identity > Sdf_IdentityRefPtr
friend void intrusive_ptr_release(Sdf_Identity *)
atomic< int > atomic_int
Definition: atomic.h:51
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.
Sdf_IdentityRegistry(const SdfLayerHandle &layer)
void intrusive_ptr_add_ref(PXR_NS::Sdf_Identity *p)
Definition: identity.h:79
const SdfLayerHandle & GetLayer() const
Returns the layer that owns this registry.
Definition: identity.h:94
Definition: path.h:288
GLsizei const GLchar *const * path
Definition: glew.h:6461
GLfloat GLfloat p
Definition: glew.h:16321
#define SDF_API
Definition: api.h:40
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
GLint GLboolean GLint layer
Definition: glew.h:3601
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
SDF_DECLARE_HANDLES(SdfLayer)
friend void intrusive_ptr_add_ref(Sdf_Identity *)
const SdfPath & GetPath() const
Returns the path that this identity refers to.
Definition: identity.h:55
friend class Sdf_Identity
Definition: identity.h:109