29 #ifndef YCL_MinGW32_INC_COMPtr_h_
30 #define YCL_MinGW32_INC_COMPtr_h_ 1
49 : hResult(::CoInitialize(
nullptr))
63 class YF_API COMException :
public std::runtime_error
70 : runtime_error(
"COMException"), hResult(h)
87 throw COMException(h);
98 throw COMException(S_FALSE);
106 template<
class _iCOM>
109 template<
class _iOther>
125 template<
class _iOther>
130 template<
class _iOther>
143 template<
class _iOther>
145 std::is_convertible<_iOther*, _iCOM*>::value,
int> = 0)
ynothrow
156 template<
class _iOther>
158 std::is_convertible<_iOther*, _iCOM*>::value,
int> = 0)
ynothrow
161 ptr.pInterface =
nullptr;
211 return Get() !=
nullptr;
226 reinterpret_cast<void**>(&res.ReleaseAndGetRef())));
227 return std::move(res);
229 template<
class _iOther>
238 reinterpret_cast<void**>(&res.ReleaseAndGetRef())));
239 return std::move(res);
248 reinterpret_cast<void**>(&ptr.ReleaseAndGetRef()));
250 template<
class _iOther>
256 return pInterface->QueryInterface(__uuidof(_iOther),
257 reinterpret_cast<void**>(&ptr.ReleaseAndGetRef()));
284 template<
typename _type>
288 return pInterface->QueryInterface(__uuidof(_type),
289 reinterpret_cast<void**>(&p));
327 template<
class _iCOM1,
class _iCOM2>
331 static_assert(std::is_base_of<_iCOM1, _iCOM2>::value
332 || std::is_base_of<_iCOM1, _iCOM2>::value,
333 "'_iCOM1' and '_iCOM2' pointers must be comparable");
335 return x.Get() == y.Get();
337 template<
class _iCOM>
343 template<
class _iCOM>
345 operator==(std::nullptr_t,
const COMPtr<_iCOM>& x) ynothrow
350 template<
class _iCOM1,
class _iCOM2>
352 operator!=(
const COMPtr<_iCOM1>& x,
const COMPtr<_iCOM2>& y) ynothrow
356 template<
class _iCOM>
358 operator!=(
const COMPtr<_iCOM>& x, std::nullptr_t) ynothrow
363 template<
class _iCOM>
365 operator!=(std::nullptr_t,
const COMPtr<_iCOM>& x) ynothrow
370 template<
class _iCOM1,
class _iCOM2>
372 operator<(const COMPtr<_iCOM1>& x,
const COMPtr<_iCOM2>& y) ynothrow
374 static_assert(std::is_base_of<_iCOM1, _iCOM2>::value
375 || std::is_base_of<_iCOM1, _iCOM2>::value,
376 "'_iCOM1' and '_iCOM2' pointers must be comparable");
378 return x.Get() < y.Get();
381 template<
class _iCOM>
383 Attach(COMPtr<_iCOM>& ptr,
typename COMPtr<_iCOM>::InterfaceType* p) ynothrow
385 if(
const auto p_interface = ptr.Get())
387 const auto ref(p_interface->Release());
391 yassume(ref != 0 || p_interface != p);
396 template<
class _iCOM>
398 Detach(COMPtr<_iCOM>& ptr) ynothrow
402 ptr.GetRef() =
nullptr;
406 template<
class _iCOM>
408 Reset(COMPtr<_iCOM>& ptr) ynothrow
412 if(
const auto tmp = ptr.Get())
414 ptr.GetRef() =
nullptr;
420 template<
class _iCOM>
421 inline DefSwap(ynothrow, COMPtr<_iCOM>)
void InternalRelease() ynothrow
#define yunused(...)
标记未使用的表达式。
COMPtr< _iOther > As() const ythrow(COMException)
_iCOM * Detach(COMPtr< _iCOM > &ptr) ynothrow
COMPtr(std::nullptr_t) ynothrow
COMPtr & operator=(std::nullptr_t) ynothrow
COMPtr(const COMPtr< _iOther > &ptr, ystdex::enable_if_t< std::is_convertible< _iOther *, _iCOM * >::value, int >=0) ynothrow
_iCOM *& ReleaseAndGetRef() ynothrow
const class ystdex::nullptr_t nullptr
::HRESULT CopyTo(REFIID riid, void **ptr) const ynothrow
void EnsureNonNull(void *p) ythrow(COMException)
检查指针值,若为空则抛出 COMException 。
#define DefGetter(_q, _t, _n,...)
void swap(any &x, any &y)
交换对象。
COMPtr & operator=(_iCOM *p) ynothrow
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
COMPtr(_iOther *ptr) ynothrow
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
#define yconstraint
约束:接口语义。
_iCOM EnsureNonNull(pInterface)
bool operator!=(const COMPtr< _iCOM1 > &x, const COMPtr< _iCOM2 > &y) ynothrow
COMException(::HRESULT h)
void Attach(COMPtr< _iCOM > &ptr, typename COMPtr< _iCOM >::InterfaceType *p) ynothrow
unsigned long Reset(COMPtr< _iCOM > &ptr) ynothrow
_iCOM * operator->() const ynothrow
::HRESULT Cast(REFIID riid, COMPtr< IUnknown > &ptr) const ynothrow
_iCOM & operator*() const ynothrow
::HRESULT CopyTo(_type *&p) const ynothrow
void InternalAddRef() const ynothrow
COMPtr(COMPtr &&ptr) ynothrow
bool operator==(const COMPtr< _iCOM1 > &x, const COMPtr< _iCOM2 > &y) ynothrow
InterfaceType * Copy() const ynothrow
COMPtr & operator=(const COMPtr &ptr) ynothrow
::HRESULT Cast(COMPtr< _iOther > &ptr) const ynothrow
DefGetter(const ynothrow, _iCOM *,, pInterface) DefGetter(const
COMPtr(_iOther &intf, ystdex::enable_if_t<!std::is_convertible< _iOther &, COMPtr & >::value, int >=0) ynothrow
void * Copy(REFIID riid) const ythrow(COMException)
InterfaceType * pInterface
COMPtr & operator=(COMPtr &&ptr) ynothrow
COMPtr(const COMPtr &ptr) ynothrow
COMPtr(COMPtr< _iOther > &&ptr, ystdex::enable_if_t< std::is_convertible< _iOther *, _iCOM * >::value, int >=0) ynothrow
typename enable_if< _bCond, _type >::type enable_if_t
inline::HRESULT CheckHResult(::HRESULT h) ythrow(COMException)
检查 ::HRESULT 值,若表示失败则抛出 COMException 。
void swap(COMPtr &ptr) ynothrow