From 5db154c3fb36a677c551e39c3c6661207eb51778 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 13 Dec 2008 09:26:03 +0000 Subject: The Calc should be functional, and is being called by the Cache itself. The Bu::CacheCalc still needs to reference the Bu::Cache so that it can make the changes it needs to. --- src/cache.h | 34 +++++++++++++++++++++++++++++++--- src/cachecalc.h | 6 +++++- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cache.h b/src/cache.h index 9488044..cc13fc8 100644 --- a/src/cache.h +++ b/src/cache.h @@ -5,6 +5,7 @@ #include "bu/hash.h" #include "bu/list.h" #include "bu/cachestore.h" +#include "bu/cachecalc.h" #define BU_TRACE #include "bu/trace.h" @@ -20,6 +21,7 @@ namespace Bu private: typedef Bu::CacheStore Store; typedef Bu::List StoreList; + typedef Bu::CacheCalc Calc; typedef struct CacheEntry { @@ -30,7 +32,8 @@ namespace Bu typedef Bu::Hash CidHash; public: - Cache() + Cache() : + pCalc( NULL ) { TRACE(); } @@ -47,6 +50,10 @@ namespace Bu __tracer_format( i.getKey() ); printf("!\n"); } + if( pCalc ) pCalc->onUnload( + i.getValue().pData, + i.getKey() + ); lStore.first()->unload( i.getValue().pData, i.getKey() @@ -71,6 +78,16 @@ namespace Bu lStore.prepend( pHand ); } + void setCalc( Calc *pCalc ) + { + TRACE(); + if( this->pCalc ) + { + delete this->pCalc; + } + this->pCalc = pCalc; + } + Ptr insert( obtype *pData ) { TRACE( pData ); @@ -78,10 +95,12 @@ namespace Bu keytype k = lStore.first()->create( pData ); hEnt.insert( k, e ); + if( pCalc ) pCalc->onLoad( pData, k ); + return Ptr( *this, pData, k ); } - Ptr get( keytype cId ) + Ptr get( const keytype &cId ) { TRACE( cId ); try { @@ -94,7 +113,12 @@ namespace Bu } } - void erase( keytype cId ) + int getRefCount( const keytype &cId ) + { + return hEnt.get( cId ).iRefs; + } + + void erase( const keytype &cId ) { TRACE( cId ); try { @@ -107,6 +131,9 @@ namespace Bu catch( Bu::HashException &e ) { get( cId ); } + + if( pCalc ) pCalc->onUnload( hEnt.get( cId ).pData, cId ); + lStore.first()->destroy( hEnt.get( cId ).pData, cId ); hEnt.erase( cId ); } @@ -134,6 +161,7 @@ namespace Bu private: CidHash hEnt; StoreList lStore; + Calc *pCalc; }; }; diff --git a/src/cachecalc.h b/src/cachecalc.h index 9e83b06..289c4ac 100644 --- a/src/cachecalc.h +++ b/src/cachecalc.h @@ -3,7 +3,7 @@ namespace Bu { - template + template class CacheCalc { public: @@ -15,6 +15,10 @@ namespace Bu { } + virtual void onLoad( obtype *pSrc, const keytype &key )=0; + virtual void onUnload( obtype *pSrc, const keytype &key )=0; + virtual void onTick() { }; + private: }; }; -- cgit v1.2.3