summaryrefslogtreecommitdiff
path: root/src/cache.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-16 03:49:54 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-16 03:49:54 +0000
commit0244488a3a6158659c4fcd1053f15d7f84fc06f8 (patch)
treef3ef25f682470f7b8539c896f0c2f64fdbfad548 /src/cache.h
parent90a51615bec786fac6750616e82570cf8727db06 (diff)
downloadlibbu++-0244488a3a6158659c4fcd1053f15d7f84fc06f8.tar.gz
libbu++-0244488a3a6158659c4fcd1053f15d7f84fc06f8.tar.bz2
libbu++-0244488a3a6158659c4fcd1053f15d7f84fc06f8.tar.xz
libbu++-0244488a3a6158659c4fcd1053f15d7f84fc06f8.zip
Ok...we'll try this change up of the cache system. It now takes two pointers,
one to a Calc and one to a Store. It takes ownership of the two objects, and deletes them when it gets cleaned up.
Diffstat (limited to 'src/cache.h')
-rw-r--r--src/cache.h50
1 files changed, 18 insertions, 32 deletions
diff --git a/src/cache.h b/src/cache.h
index 3ca1802..f614aca 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -106,11 +106,12 @@ namespace Bu
106 typedef Bu::Hash<keytype, CacheEntry> CidHash; 106 typedef Bu::Hash<keytype, CacheEntry> CidHash;
107 107
108 public: 108 public:
109 Cache( Calc &rCalc ) : 109 Cache( Calc *pCalc, Store *pStore ) :
110 rCalc( rCalc ) 110 pCalc( pCalc ),
111 pStore( pStore )
111 { 112 {
112 TRACE(); 113 TRACE();
113 rCalc.setCache( this ); 114 pCalc->setCache( this );
114 } 115 }
115 116
116 virtual ~Cache() 117 virtual ~Cache()
@@ -125,42 +126,27 @@ namespace Bu
125 __tracer_format( i.getKey() ); 126 __tracer_format( i.getKey() );
126 printf("!\n"); 127 printf("!\n");
127 } 128 }
128 rCalc.onUnload( 129 pCalc->onUnload(
129 i.getValue().pData, 130 i.getValue().pData,
130 i.getKey() 131 i.getKey()
131 ); 132 );
132 lStore.first()->unload( 133 pStore->unload(
133 i.getValue().pData, 134 i.getValue().pData,
134 i.getKey() 135 i.getKey()
135 ); 136 );
136 } 137 }
137 for( typename StoreList::iterator i = lStore.begin(); 138 delete pCalc;
138 i != lStore.end(); i++ ) 139 delete pStore;
139 {
140 delete *i;
141 }
142 }
143
144 void appendStore( Store *pHand )
145 {
146 TRACE();
147 lStore.append( pHand );
148 }
149
150 void prependStore( Store *pHand )
151 {
152 TRACE();
153 lStore.prepend( pHand );
154 } 140 }
155 141
156 Ptr insert( obtype *pData ) 142 Ptr insert( obtype *pData )
157 { 143 {
158 TRACE( pData ); 144 TRACE( pData );
159 CacheEntry e = {pData, 0}; 145 CacheEntry e = {pData, 0};
160 keytype k = lStore.first()->create( pData ); 146 keytype k = pStore->create( pData );
161 hEnt.insert( k, e ); 147 hEnt.insert( k, e );
162 148
163 rCalc.onLoad( pData, k ); 149 pCalc->onLoad( pData, k );
164 150
165 return Ptr( this, pData, k ); 151 return Ptr( this, pData, k );
166 } 152 }
@@ -172,8 +158,8 @@ namespace Bu
172 return Ptr( this, hEnt.get( cId ).pData, cId ); 158 return Ptr( this, hEnt.get( cId ).pData, cId );
173 } 159 }
174 catch( Bu::HashException &e ) { 160 catch( Bu::HashException &e ) {
175 CacheEntry e = {lStore.first()->load( cId ), 0}; 161 CacheEntry e = {pStore->load( cId ), 0};
176 rCalc.onLoad( e.pData, cId ); 162 pCalc->onLoad( e.pData, cId );
177 hEnt.insert( cId, e ); 163 hEnt.insert( cId, e );
178 return Ptr( this, e.pData, cId ); 164 return Ptr( this, e.pData, cId );
179 } 165 }
@@ -200,12 +186,12 @@ namespace Bu
200 return; 186 return;
201 } 187 }
202 obtype *pObj = hEnt.get( cId ).pData; 188 obtype *pObj = hEnt.get( cId ).pData;
203 rCalc.onUnload( pObj, cId ); 189 pCalc->onUnload( pObj, cId );
204 hEnt.erase( cId ); 190 hEnt.erase( cId );
205 191
206 // The unload has to happen last just in case cId is a reference 192 // The unload has to happen last just in case cId is a reference
207 // to data that is about to be deleted from memory by the unload. 193 // to data that is about to be deleted from memory by the unload.
208 lStore.first()->unload( pObj, cId ); 194 pStore->unload( pObj, cId );
209 } 195 }
210 196
211 void erase( const keytype &cId ) 197 void erase( const keytype &cId )
@@ -222,9 +208,9 @@ namespace Bu
222 get( cId ); 208 get( cId );
223 } 209 }
224 210
225 rCalc.onUnload( hEnt.get( cId ).pData, cId ); 211 pCalc->onUnload( hEnt.get( cId ).pData, cId );
226 212
227 lStore.first()->destroy( hEnt.get( cId ).pData, cId ); 213 pStore->destroy( hEnt.get( cId ).pData, cId );
228 hEnt.erase( cId ); 214 hEnt.erase( cId );
229 } 215 }
230 216
@@ -244,8 +230,8 @@ namespace Bu
244 230
245 private: 231 private:
246 CidHash hEnt; 232 CidHash hEnt;
247 StoreList lStore; 233 Store *pStore;
248 Calc &rCalc; 234 Calc *pCalc;
249 }; 235 };
250}; 236};
251 237