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