UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
COMPointer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include <Unknwn.h>
7
8#ifdef TEXT_PASTE
9 #undef TEXT
10 #define TEXT(x) TEXT_PASTE(x)
11#endif
12
13
17template<typename T>
19{
20public:
21
22 typedef T PointerType;
23
24public:
25
28 : RawPointer(NULL)
29 { }
30
37 : RawPointer(Object)
38 {
39 if (RawPointer)
40 {
41 RawPointer->AddRef();
42 }
43 }
44
51 : RawPointer(Other.RawPointer)
52 {
53 if (RawPointer)
54 {
55 RawPointer->AddRef();
56 }
57 }
58
65 : RawPointer(Other.RawPointer)
66 {
67 Other.RawPointer = NULL;
68 }
69
76 {
77 if (RawPointer != Object)
78 {
79 if (Object)
80 {
81 Object->AddRef();
82 }
83
84 if (RawPointer)
85 {
86 RawPointer->Release();
87 }
88
89 RawPointer = Object;
90 }
91
92 return *this;
93 }
94
101 {
102 if (RawPointer != Other.RawPointer)
103 {
104 if (Other.RawPointer)
105 {
106 Other->AddRef();
107 }
108
109 if (RawPointer)
110 {
111 RawPointer->Release();
112 }
113
114 RawPointer = Other.RawPointer;
115 }
116
117 return *this;
118 }
119
126 {
127 if (RawPointer != Other.RawPointer)
128 {
129 if (RawPointer)
130 {
131 RawPointer->Release();
132 }
133
134 RawPointer = Other.RawPointer;
135 Other.RawPointer = NULL;
136 }
137
138 return *this;
139 }
140
143 {
144 if (RawPointer)
145 {
146 RawPointer->Release();
147 }
148 }
149
150public:
151
153 {
154 return &(RawPointer);
155 }
156
157 inline PointerType* operator->() const
158 {
159 check(RawPointer != NULL);
160 return RawPointer;
161 }
162
164 {
165 return RawPointer == Object;
166 }
167
169 {
170 return RawPointer != Object;
171 }
172
174 {
175 return RawPointer;
176 }
177
178public:
179
187 {
188 if (RawPointer)
189 {
190 RawPointer->Release();
191 }
192
193 RawPointer = Object;
194 }
195
201 void Detach()
202 {
203 RawPointer = NULL;
204 }
205
214 {
215 if (RawPointer)
216 {
217 RawPointer->Release();
218 RawPointer = NULL;
219 }
220
221 return Unknown->QueryInterface(Riid, reinterpret_cast<void**>(&(RawPointer)));
222 }
223
231 {
232 return RawPointer;
233 }
234
241 UE_FORCEINLINE_HINT const bool IsValid() const
242 {
243 return (RawPointer != NULL);
244 }
245
247 void Reset()
248 {
249 if (RawPointer)
250 {
251 RawPointer->Release();
252 RawPointer = NULL;
253 }
254 }
255
256private:
257
259 PointerType* RawPointer;
260
262 {
263 return GetTypeHash(InObjectPtr.RawPointer);
264 }
265};
#define NULL
Definition oodle2base.h:134
#define check(expr)
Definition AssertionMacros.h:314
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition COMPointer.h:19
TComPtr< PointerType > & operator=(const TComPtr< PointerType > &Other)
Definition COMPointer.h:100
TComPtr(TComPtr< PointerType > &&Other)
Definition COMPointer.h:64
PointerType * operator->() const
Definition COMPointer.h:157
UE_FORCEINLINE_HINT PointerType * Get() const
Definition COMPointer.h:230
TComPtr(const TComPtr< PointerType > &Other)
Definition COMPointer.h:50
~TComPtr()
Definition COMPointer.h:142
TComPtr< PointerType > & operator=(TComPtr< PointerType > &&Other)
Definition COMPointer.h:125
void Detach()
Definition COMPointer.h:201
T PointerType
Definition COMPointer.h:22
void Reset()
Definition COMPointer.h:247
TComPtr(PointerType *const Object)
Definition COMPointer.h:36
UE_FORCEINLINE_HINT PointerType ** operator&()
Definition COMPointer.h:152
friend UE_FORCEINLINE_HINT uint32 GetTypeHash(const TComPtr< T > &InObjectPtr)
Definition COMPointer.h:261
UE_FORCEINLINE_HINT bool operator==(PointerType *const Object) const
Definition COMPointer.h:163
TComPtr< PointerType > & operator=(PointerType *const Object)
Definition COMPointer.h:75
void Attach(PointerType *Object)
Definition COMPointer.h:186
TComPtr()
Definition COMPointer.h:27
UE_FORCEINLINE_HINT bool operator!=(PointerType *const Object) const
Definition COMPointer.h:168
UE_FORCEINLINE_HINT const bool IsValid() const
Definition COMPointer.h:241
HRESULT FromQueryInterface(REFIID Riid, IUnknown *Unknown)
Definition COMPointer.h:213