-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklcommon.h
57 lines (47 loc) · 850 Bytes
/
klcommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef KLCOMMON_H
#define KLCOMMON_H
template<class Interface>
inline void safeRelease(Interface *& pInterfaceToRelease)
{
if (pInterfaceToRelease != NULL)
{
pInterfaceToRelease->Release();
pInterfaceToRelease = NULL;
}
}
template<class Interface>
inline void safeDelete(Interface *& pInterfaceToDelete)
{
if (pInterfaceToDelete != NULL)
{
delete pInterfaceToDelete;
pInterfaceToDelete = NULL;
}
}
template<typename T>
class KLComPtr
{
private:
T* ptr = nullptr;
public:
~KLComPtr()
{
if ( ptr != nullptr ){
ptr->Release();
ptr = nullptr;
}
}
T** operator & ()
{
return &ptr;
}
T* operator -> ()
{
return ptr;
}
operator T* ()
{
return ptr;
}
};
#endif // KLCOMMON_H