HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SharedPtr.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SharedPtr.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_SHAREDPTR_H_INCLUDED__
13 #define __UT_SHAREDPTR_H_INCLUDED__
14 
15 #include <memory>
16 #include <stddef.h>
17 
18 /// @brief Wrapper around std::shared_ptr
19 ///
20 /// An shared pointer takes ownership of the object referenced. The reference
21 /// counting is done outside the object interface, so the size of a
22 /// UT_SharedPtr is larger than a vanilla pointer.
23 ///
24 /// As this is a wrapper around the boost shared pointer template, the type (T)
25 /// must have a <b>Copy Constructor</b> and a valid <b>Assignment Operator</b>
26 /// @see UT_IntrusivePtr
27 template <typename T>
28 using UT_SharedPtr = std::shared_ptr<T>;
29 
30 template <typename T>
31 using UTenable_shared_from_this = std::enable_shared_from_this<T>;
32 
33 #define UTmakeShared std::make_shared
34 #define UTallocateShared std::allocate_shared
35 
36 #define UTstatic_pointer_cast std::static_pointer_cast
37 #define UTdynamic_pointer_cast std::dynamic_pointer_cast
38 #define UTconst_pointer_cast std::const_pointer_cast
39 #define UTreinterpret_pointer_cast std::reinterpret_pointer_cast
40 
41 /// Return a UT_SharedPtr<T> that points to an array of T[len] buffer.
42 /// Only needed until we have proper support in C++20.
43 template <typename T>
44 inline UT_SharedPtr<T>
46 {
47  return UT_SharedPtr<T>(new T[len], [](T* p) { delete [] p; });
48 }
49 
50 // For UT::ArraySet.
51 namespace UT
52 {
53 template <typename T>
54 struct DefaultClearer;
55 
56 template <typename T>
58 {
59  static void clear(UT_SharedPtr<T> &v) { v = UT_SharedPtr<T>(); }
60  static bool isClear(const UT_SharedPtr<T> &v) { return v.get() == nullptr; }
62  {
63  new ((void *)p) UT_SharedPtr<T>(nullptr);
64  }
65  static const bool clearNeedsDestruction = false;
66 };
67 } // namespace UT
68 
69 #endif // __UT_SHAREDPTR_H_INCLUDED__
UT_SharedPtr< T > UTmakeSharedArrayPtr(size_t len)
Definition: UT_SharedPtr.h:45
static void clearConstruct(UT_SharedPtr< T > *p)
Definition: UT_SharedPtr.h:61
const GLdouble * v
Definition: glew.h:1391
std::enable_shared_from_this< T > UTenable_shared_from_this
Definition: UT_SharedPtr.h:31
static bool isClear(const UT_SharedPtr< T > &v)
Definition: UT_SharedPtr.h:60
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
GLfloat GLfloat p
Definition: glew.h:16321
static void clear(UT_SharedPtr< T > &v)
Definition: UT_SharedPtr.h:59
GLenum GLsizei len
Definition: glew.h:7752