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