Initial
This commit is contained in:
94
com/ComPtr.hpp
Normal file
94
com/ComPtr.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef _COM_COMPOINTER_HPP_
|
||||
#define _COM_COMPOINTER_HPP_
|
||||
#ifndef _COMMON_SMARTPOINTER_HPP_
|
||||
#include <common/pointer.hpp>
|
||||
#endif
|
||||
#ifndef _COM_COM_HPP_
|
||||
#include <com/com.hpp>
|
||||
#endif
|
||||
#ifndef _COM_RESULT_HPP_
|
||||
#include <com/result.hpp>
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class ComPointer : public SmartPointer<T>
|
||||
{
|
||||
public:
|
||||
ComPointer(void);
|
||||
ComPointer(T *pComPointer,PointerDisposition::Disposition disposition=PointerDisposition::Assume);
|
||||
ComPointer(const ComPointer<T> &comPointer);
|
||||
virtual ~ComPointer();
|
||||
ComResult createInstance(REFCLSID rclsId,REFIID riid);
|
||||
ComResult createInstance(REFCLSID rcldId);
|
||||
void Release(void);
|
||||
void destroy(void);
|
||||
operator T**(void);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComPointer<T>::ComPointer(void)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComPointer<T>::ComPointer(T *pComPointer,PointerDisposition::Disposition disposition)
|
||||
: SmartPointer<T>(pComPointer,disposition)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComPointer<T>::ComPointer(const ComPointer<T> &comPointer)
|
||||
: SmartPointer<T>(comPointer)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComPointer<T>::~ComPointer()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComResult ComPointer<T>::createInstance(REFCLSID rclsId,REFIID riid)
|
||||
{
|
||||
ComObj comObj;
|
||||
return comObj.createInstance(rclsId,riid,(SmartPointer<IUnknown>&)*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComResult ComPointer<T>::createInstance(REFCLSID rclsId)
|
||||
{
|
||||
ComObj comObj;
|
||||
return comObj.createInstance(rclsId,__uuidof(T),(SmartPointer<IUnknown>&)*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
ComPointer<T>::operator T**(void)
|
||||
{
|
||||
Release();
|
||||
return ppt();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
void ComPointer<T>::destroy(void)
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
void ComPointer<T>::Release(void)
|
||||
{
|
||||
if(!isOkay())return;
|
||||
((IUnknown*)((T *)*this))->Release();
|
||||
SmartPointer<T>::destroy();
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user