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 
35 #define UTstatic_pointer_cast std::static_pointer_cast
36 #define UTdynamic_pointer_cast std::dynamic_pointer_cast
37 #define UTconst_pointer_cast std::const_pointer_cast
38 #define UTreinterpret_pointer_cast std::reinterpret_pointer_cast
39 
40 /// Return a UT_SharedPtr<T> that points to an array of T[len] buffer.
41 /// Only needed until we have proper support in C++20.
42 template <typename T>
43 inline UT_SharedPtr<T>
45 {
46  return UT_SharedPtr<T>(new T[len], [](T* p) { delete [] p; });
47 }
48 
49 // For UT::ArraySet.
50 namespace UT
51 {
52 template <typename T>
53 struct DefaultClearer;
54 
55 template <typename T>
57 {
58  static void clear(UT_SharedPtr<T> &v) { v = UT_SharedPtr<T>(); }
59  static bool isClear(const UT_SharedPtr<T> &v) { return v.get() == nullptr; }
61  {
62  new ((void *)p) UT_SharedPtr<T>(nullptr);
63  }
64  static const bool clearNeedsDestruction = false;
65 };
66 } // namespace UT
67 
68 #endif // __UT_SHAREDPTR_H_INCLUDED__
UT_SharedPtr< T > UTmakeSharedArrayPtr(size_t len)
Definition: UT_SharedPtr.h:44
static void clearConstruct(UT_SharedPtr< T > *p)
Definition: UT_SharedPtr.h:60
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:59
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:58
GLenum GLsizei len
Definition: glew.h:7752