blob: 8f35a03890b7393d7d0a97673ff62552b838ad54 (
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
43
44
45
46
47
48
|
#ifndef BU_C_PTR_H
#define BU_C_PTR_H
namespace Bu
{
template<class obtype, class keytype> class Cache;
/**
* Cache Pointer - Provides access to data that is held within the cache.
* This provides safe, refcounting access to data stored in the cache, with
* support for lazy loading.
*/
template<class obtype, class keytype>
class CPtr
{
friend class Bu::Cache<obtype, keytype>;
private:
CPtr( Cache<obtype, keytype> &rCache, obtype *pData ) :
rCache( rCache ),
pData( pData )
{
rCache.incRef( kId );
}
public:
virtual ~CPtr()
{
rCache.decRef( kId );
}
obtype &operator*()
{
return *pData;
}
obtype *operator->()
{
return pData;
}
private:
Bu::Cache<obtype, keytype> &rCache;
obtype *pData;
keytype kId;
};
};
#endif
|