Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
COMPointer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include <Unknwn.h>
6#include "Misc/AssertionMacros.h"
7
8#ifdef TEXT_PASTE
9 #undef TEXT
10 #define TEXT(x) TEXT_PASTE(x)
11#endif
12
13
14/**
15 * Smart COM object pointer.
16 */
17template<typename T>
19{
20public:
21
22 typedef T PointerType;
23
24public:
25
26 /** Default constructor (initialized to null). */
28 : RawPointer(NULL)
29 { }
30
31 /**
32 * Create and initialize a new instance.
33 *
34 * @param Object The object to point to.
35 */
36 TComPtr(PointerType* const Object)
38 {
39 if (RawPointer)
40 {
42 }
43 }
44
45 /**
46 * Copy constructor.
47 *
48 * @param Other The instance to copy.
49 */
52 {
53 if (RawPointer)
54 {
56 }
57 }
58
59 /**
60 * Move constructor.
61 *
62 * @param Other The instance to move.
63 */
66 {
67 Other.RawPointer = NULL;
68 }
69
70 /**
71 * Assignment operator.
72 *
73 * @param Object The object to point to.
74 */
76 {
77 if (RawPointer != Object)
78 {
79 if (Object)
80 {
81 Object->AddRef();
82 }
83
84 if (RawPointer)
85 {
87 }
88
90 }
91
92 return *this;
93 }
94
95 /**
96 * Copy assignment operator.
97 *
98 * @param Other The instance to copy.
99 */
101 {
103 {
104 if (Other.RawPointer)
105 {
106 Other->AddRef();
107 }
108
109 if (RawPointer)
110 {
112 }
113
115 }
116
117 return *this;
118 }
119
120 /**
121 * Move assignment operator.
122 *
123 * @param Other The instance to move.
124 */
126 {
128 {
129 if (RawPointer)
130 {
132 }
133
135 Other.RawPointer = NULL;
136 }
137
138 return *this;
139 }
140
141 /** Destructor. */
143 {
144 if (RawPointer)
145 {
147 }
148 }
149
150public:
151
153 {
154 return &(RawPointer);
155 }
156
158 {
159 check(RawPointer != NULL);
160 return RawPointer;
161 }
162
163 FORCEINLINE bool operator==(PointerType* const Object) const
164 {
165 return RawPointer == Object;
166 }
167
168 FORCEINLINE bool operator!=(PointerType* const Object) const
169 {
170 return RawPointer != Object;
171 }
172
174 {
175 return RawPointer;
176 }
177
178public:
179
180 /**
181 * Set the pointer without adding a reference.
182 *
183 * @param InRawPointer The object to point to.
184 * @see Detach
185 */
186 void Attach(PointerType* Object)
187 {
188 if (RawPointer)
189 {
191 }
192
194 }
195
196 /**
197 * Reset the pointer without releasing a reference.
198 *
199 * @see Attach
200 */
201 void Detach()
202 {
203 RawPointer = NULL;
204 }
205
206 /**
207 * Initialize this pointer from a COM interface to be queried.
208 *
209 * @param Riid The ID of the interface to be queried.
210 * @param Unknown The object to query the interface from.
211 * @return The result code of the query.
212 */
213 HRESULT FromQueryInterface(REFIID Riid, IUnknown* Unknown)
214 {
215 if (RawPointer)
216 {
218 RawPointer = NULL;
219 }
220
221 return Unknown->QueryInterface(Riid, reinterpret_cast<void**>(&(RawPointer)));
222 }
223
224 /**
225 * Get raw pointer to the object pointed to.
226 *
227 * @return Pointer to the object, or NULL if not valid.
228 * @see IsValid
229 */
231 {
232 return RawPointer;
233 }
234
235 /**
236 * Whether this pointer is pointing to an actual object.
237 *
238 * @return true if the pointer is valid, false otherwise.
239 * @see Get
240 */
241 FORCEINLINE const bool IsValid() const
242 {
243 return (RawPointer != NULL);
244 }
245
246 /** Reset this pointer to null. */
247 void Reset()
248 {
249 if (RawPointer)
250 {
252 RawPointer = NULL;
253 }
254 }
255
256private:
257
258 /** Pointer to the actual object, if any. */
260
261 friend FORCEINLINE uint32 GetTypeHash(const TComPtr<T>& InObjectPtr)
262 {
264 }
265};
#define check(expr)
#define FORCEINLINE
Definition Platform.h:644
FORCEINLINE PointerType * operator->() const
Definition COMPointer.h:157
TComPtr< PointerType > & operator=(const TComPtr< PointerType > &Other)
Definition COMPointer.h:100
FORCEINLINE bool operator!=(PointerType *const Object) const
Definition COMPointer.h:168
TComPtr(TComPtr< PointerType > &&Other)
Definition COMPointer.h:64
friend FORCEINLINE uint32 GetTypeHash(const TComPtr< T > &InObjectPtr)
Definition COMPointer.h:261
FORCEINLINE PointerType ** operator&()
Definition COMPointer.h:152
FORCEINLINE const bool IsValid() const
Definition COMPointer.h:241
TComPtr(const TComPtr< PointerType > &Other)
Definition COMPointer.h:50
FORCEINLINE PointerType * Get() const
Definition COMPointer.h:230
TComPtr< PointerType > & operator=(TComPtr< PointerType > &&Other)
Definition COMPointer.h:125
PointerType * RawPointer
Definition COMPointer.h:259
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
TComPtr< PointerType > & operator=(PointerType *const Object)
Definition COMPointer.h:75
void Attach(PointerType *Object)
Definition COMPointer.h:186
HRESULT FromQueryInterface(REFIID Riid, IUnknown *Unknown)
Definition COMPointer.h:213
FORCEINLINE operator PointerType *() const
Definition COMPointer.h:173
FORCEINLINE bool operator==(PointerType *const Object) const
Definition COMPointer.h:163