-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucpointer.h
54 lines (41 loc) · 798 Bytes
/
ucpointer.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
template <typename T>
class UCPointer {
public:
UCPointer(T* r = NULL):
m_pObj(r) {
increment();
}
~UCPointer() {
decrement();
}
UCPointer(const UCPointer<T>& p) {
m_pObj = p.m_pObj;
increment();
}
UCPointer& operator=(const UCPointer<T>& p) {
if(m_pObj != p.m_pObj){
decrement();
m_pObj = p.m_pObj;
increment();
}
return *this;
}
T* operator->() const {
return m_pObj;
}
T& operator*() const {
return *m_pObj;
}
private:
T* m_pObj;
void increment() {
if(m_pObj){
m_pObj->incr();
}
}
void decrement() {
if(m_pObj){
m_pObj->decr();
}
}
};