blob: 2fad797b88f2d255ec2b52e39d40595a9728b5d0 (
plain)
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
|
#ifndef __PTR_H__
# define __PTR_H__
template<class T>
class scope
{
public:
scope() : p(NULL) {}
scope(T t) : p(t) {}
~scope() { release(); }
void release()
{
if (p != NULL)
delete p;
p = NULL;
}
T operator=(T t) { release(); p = t; return t; }
T operator->() const { return p; }
operator T() const { return p; }
T detach()
{
T ret = p;
p = NULL;
return ret;
}
private:
T p;
};
#endif // __PTR_H__
|