summaryrefslogtreecommitdiff
path: root/Plugins/utils/mir_scope.h
blob: 31edde09d4e3e4b80f1a2a284b363a351036fd18 (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 mir_scope 
{
public:
	mir_scope() : p(NULL) {}
	mir_scope(T t) : p(t) {}
	~mir_scope() { release(); }

	void release()
	{
		if (p != NULL)
			mir_free(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__