summaryrefslogtreecommitdiff
path: root/src/cptr.h
blob: 5aafbd31df158885f0d4303fd4ff81462b1fd0c6 (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
38
39
40
41
42
#ifndef BU_C_PTR_H
#define BU_C_PTR_H

namespace Bu
{
	template<class obtype> class Cache;

	template<class obtype>
	class CPtr
	{
	friend class Bu::Cache<obtype>;
	private:
		CPtr( Cache<obtype> &rCache, obtype *pData ) :
			rCache( rCache ),
			pData( pData )
		{
			rCache.incRef( pData );
		}

	public:
		virtual ~CPtr()
		{
			rCache.decRef( pData );
		}

		obtype &operator*()
		{
			return *pData;
		}

		obtype *operator->()
		{
			return pData;
		}

	private:
		Bu::Cache<obtype> &rCache;
		obtype *pData;
	};
};

#endif