summaryrefslogtreecommitdiff
path: root/src/cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache.h')
-rw-r--r--src/cache.h34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/cache.h b/src/cache.h
index 8ab0659..f7b71ce 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -11,16 +11,15 @@
11 11
12namespace Bu 12namespace Bu
13{ 13{
14 template<class obtype> class Cache;
15 template<class obtype> long getCacheId( const obtype *o );
16
17 template<class obtype> 14 template<class obtype>
18 class Cache 15 class Cache
19 { 16 {
20 friend class Bu::CPtr<obtype>; 17 friend class Bu::CPtr<obtype>;
21 typedef Bu::CPtr<obtype> Ptr; 18 typedef Bu::CPtr<obtype> Ptr;
19 typedef Bu::CacheHandler<obtype> Handler;
20 typedef Bu::List<Handler *> HandlerList;
22 public: 21 public:
23 typedef long cid; /**< Cache ID type. Unique cache entry ID. */ 22 typedef long cid_t; /**< Cache ID type. Unique cache entry ID. */
24 23
25 public: 24 public:
26 Cache() 25 Cache()
@@ -31,19 +30,19 @@ namespace Bu
31 virtual ~Cache() 30 virtual ~Cache()
32 { 31 {
33 TRACE(); 32 TRACE();
34 for( HandlerList::iterator i = lHandler.begin(); 33/* for( HandlerList::iterator i = lHandler.begin();
35 i != lHandler.end(); i++ ) 34 i != lHandler.end(); i++ )
36 { 35 {
37 delete *i; 36 delete *i;
38 } 37 }
39 } 38*/ }
40 39
41 void appendHandler( CacheHandler *pHand ) 40 void appendHandler( Handler *pHand )
42 { 41 {
43 lHandler.append( pHand ); 42 lHandler.append( pHand );
44 } 43 }
45 44
46 void prependHandler( CacheHandler *pHand ) 45 void prependHandler( Handler *pHand )
47 { 46 {
48 lHandler.prepend( pHand ); 47 lHandler.prepend( pHand );
49 } 48 }
@@ -52,33 +51,33 @@ namespace Bu
52 { 51 {
53 TRACE(); 52 TRACE();
54 CacheEntry e = {pData, 0}; 53 CacheEntry e = {pData, 0};
55 hEnt.insert( getCacheId( pData ), e ); 54 hEnt.insert( /*pData*/ 0 , e );
56 return Ptr( *this, pData ); 55 return Ptr( *this, pData );
57 } 56 }
58 57
59 Ptr get( cid cId ) 58 Ptr get( cid_t cId )
60 { 59 {
61 TRACE(); 60 TRACE();
62 return Ptr( *this, hEnt.get( cId ).pData ); 61 return Ptr( *this, hEnt.get( cId ).pData );
63 } 62 }
64 63
65 int getRefCnt( cid cId ) 64 int getRefCnt( cid_t cId )
66 { 65 {
67 TRACE(); 66 TRACE();
68 return hEnt.get( cId ).iRefs; 67 return hEnt.get( cId ).iRefs;
69 } 68 }
70 69
71 private: 70 private:
72 void incRef( obtype *pData ) 71 void incRef( cid_t cId )
73 { 72 {
74 TRACE(); 73 TRACE();
75 hEnt.get( getCacheId( pData ) ).iRefs++; 74 hEnt.get( cId ).iRefs++;
76 } 75 }
77 76
78 void decRef( obtype *pData ) 77 void decRef( cid_t cId )
79 { 78 {
80 TRACE(); 79 TRACE();
81 CacheEntry &e = hEnt.get( getCacheId( pData ) ); 80 CacheEntry &e = hEnt.get( cId );
82 e.iRefs--; 81 e.iRefs--;
83 } 82 }
84 83
@@ -90,10 +89,9 @@ namespace Bu
90 } CacheEntry; 89 } CacheEntry;
91 90
92 //typedef Bu::Hash<ptrdiff_t, int> RefHash; 91 //typedef Bu::Hash<ptrdiff_t, int> RefHash;
93 typedef Bu::Hash<cid, CacheEntry> CidHash; 92 typedef Bu::Hash<cid_t, CacheEntry> CidHash;
94 //RefHash hRefs; 93 //RefHash hRefs;
95 CidHash hEnt; 94 CidHash hEnt;
96 typedef Bu::List<CacheHandler *> HandlerList;
97 HandlerList lHandler; 95 HandlerList lHandler;
98 }; 96 };
99}; 97};