HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primDataHandle.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_DATA_HANDLE_H
25 #define PXR_USD_USD_PRIM_DATA_HANDLE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include <hboost/functional/hash.hpp>
30 #include <hboost/intrusive_ptr.hpp>
31 
33 
34 class SdfPath;
35 
36 // To start we always validate.
37 #define USD_CHECK_ALL_PRIM_ACCESSES
38 
39 // Forward declare hboost::intrusive_ptr requirements. Defined in primData.h.
40 void intrusive_ptr_add_ref(const class Usd_PrimData *prim);
41 void intrusive_ptr_release(const class Usd_PrimData *prim);
42 
43 // Forward declarations for Usd_PrimDataHandle's use. Defined in primData.h.
44 USD_API
46 bool Usd_IsDead(Usd_PrimData const *p);
47 
48 // convenience typedefs for raw ptrs.
51 
52 // convenience typedefs for intrusive_ptr.
53 typedef hboost::intrusive_ptr<Usd_PrimData> Usd_PrimDataIPtr;
54 typedef hboost::intrusive_ptr<const Usd_PrimData> Usd_PrimDataConstIPtr;
55 
56 // Private helper class that holds a reference to prim data. UsdObject (and by
57 // inheritance its subclasses) hold an instance of this class. It lets
58 // UsdObject detect prim expiry, and provides access to cached prim data.
60 {
61 public:
62  // smart ptr element_type typedef.
63  typedef Usd_PrimDataConstIPtr::element_type element_type;
64 
65  // Construct a null handle.
67  // Convert/construct a handle from a prim data intrusive ptr.
69  : _p(primData) {}
70  // Convert/construct a handle from a prim data intrusive ptr.
72  : _p(primData) {}
73  // Convert/construct a handle from a prim data raw ptr.
75  : _p(Usd_PrimDataConstIPtr(primData)) {}
76  // Convert/construct a handle from a prim data raw ptr.
78  : _p(Usd_PrimDataConstIPtr(primData)) {}
79 
80  // Reset this handle to null.
81  void reset() { _p.reset(); }
82 
83  // Swap this handle with \p other.
84  void swap(Usd_PrimDataHandle &other) { _p.swap(other._p); }
85 
86  // Dereference this handle. If USD_CHECK_ALL_PRIM_ACCESSES is defined, this
87  // will issue a fatal error if the handle is invalid.
89  element_type *p = _p.get();
90 #ifdef USD_CHECK_ALL_PRIM_ACCESSES
91  if (!p || Usd_IsDead(p))
93 #endif
94  return p;
95  }
96 
97  // Explicit bool conversion operator. Returns \c true if this handle points
98  // to a valid prim instance that is not marked dead, \c false otherwise.
99  explicit operator bool() const {
100  element_type *p = _p.get();
101  return p && !Usd_IsDead(p);
102  }
103 
104  // Return a text description of this prim data, used primarily for
105  // diagnostic purposes.
106  std::string GetDescription(SdfPath const &proxyPrimPath) const;
107 
108 private:
109  // Equality comparison.
110  friend bool operator==(const Usd_PrimDataHandle &lhs,
111  const Usd_PrimDataHandle &rhs) {
112  return lhs._p == rhs._p;
113  }
114 
115  // Inequality comparison.
116  friend bool operator!=(const Usd_PrimDataHandle &lhs,
117  const Usd_PrimDataHandle &rhs) {
118  return !(lhs == rhs);
119  }
120 
121  // Swap \p lhs and \p rhs.
122  friend void swap(Usd_PrimDataHandle &lhs, Usd_PrimDataHandle &rhs) {
123  lhs.swap(rhs);
124  }
125 
126  // Provide hash_value.
127  friend size_t hash_value(const Usd_PrimDataHandle &h) {
128  return hboost::hash_value(h._p.get());
129  }
130 
132  return h._p.get();
133  }
134 
136 };
137 
138 
140 
141 #endif // PXR_USD_USD_PRIM_DATA_HANDLE_H
#define USD_API
Definition: api.h:40
Usd_PrimDataHandle(const Usd_PrimDataIPtr &primData)
friend element_type * get_pointer(const Usd_PrimDataHandle &h)
friend bool operator==(const Usd_PrimDataHandle &lhs, const Usd_PrimDataHandle &rhs)
Usd_PrimDataHandle(const Usd_PrimDataConstIPtr &primData)
Usd_PrimDataHandle(Usd_PrimDataConstPtr primData)
friend size_t hash_value(const Usd_PrimDataHandle &h)
hboost::intrusive_ptr< Usd_PrimData > Usd_PrimDataIPtr
void intrusive_ptr_release(const class Usd_PrimData *prim)
void swap(Usd_PrimDataHandle &other)
hboost::intrusive_ptr< const Usd_PrimData > Usd_PrimDataConstIPtr
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Usd_PrimDataConstIPtr::element_type element_type
std::string GetDescription(SdfPath const &proxyPrimPath) const
bool Usd_IsDead(Usd_PrimData const *p)
Definition: primData.h:347
GLfloat GLfloat p
Definition: glew.h:16656
Definition: path.h:288
Usd_PrimDataHandle(Usd_PrimDataPtr primData)
Usd_PrimData * Usd_PrimDataPtr
void intrusive_ptr_add_ref(const class Usd_PrimData *prim)
const Usd_PrimData * Usd_PrimDataConstPtr
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
friend bool operator!=(const Usd_PrimDataHandle &lhs, const Usd_PrimDataHandle &rhs)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USD_API void Usd_IssueFatalPrimAccessError(Usd_PrimData const *p)
friend void swap(Usd_PrimDataHandle &lhs, Usd_PrimDataHandle &rhs)
element_type * operator->() const
size_t hash_value(const CH_ChannelRef &ref)