From daa25c26e99eb62a4ce499f8079b15734987ac0d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Apr 2010 05:44:39 +0000 Subject: Many minor fixes to the caching system, membuf, and others, but mainly some important fixes for real-life use of the system. --- src/cache.h | 17 +++++++++++++---- src/cachestoremyriad.h | 5 ----- src/cachestorenids.h | 5 ----- src/membuf.cpp | 6 ++++++ src/membuf.h | 1 + 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/cache.h b/src/cache.h index 987443c..06b798c 100644 --- a/src/cache.h +++ b/src/cache.h @@ -205,6 +205,12 @@ namespace Bu virtual ~Cache() { TRACE(); + + // Better safe than sorry, better try a sync before anything + // else happens. + sync(); + + // Cycle through and unload all objects from the system. for( typename CidHash::iterator i = hEnt.begin(); i != hEnt.end(); i++ ) { @@ -214,10 +220,6 @@ namespace Bu // object when the Cache is destroyed. throw Bu::ExceptionBase("iRefs not zero."); } - pCalc->onUnload( - i.getValue().pData, - i.getKey() - ); pStore->unload( i.getValue().pData, i.getKey() @@ -230,6 +232,8 @@ namespace Bu Ptr insert( obtype *pData ) { TRACE( pData ); + if( pStore->has( __cacheGetKey( pData ) ) ) + throw Bu::ExceptionBase("Key already exists in cache."); CacheEntry e = {pData, 0, 0}; keytype k = pStore->create( pData ); hEnt.insert( k, e ); @@ -336,6 +340,11 @@ namespace Bu return pStore->getKeys(); } + KeyList getActiveKeys() + { + return hEnt.getKeys(); + } + int getSize() { return pStore->getSize(); diff --git a/src/cachestoremyriad.h b/src/cachestoremyriad.h index e5a10eb..3ae3ec8 100644 --- a/src/cachestoremyriad.h +++ b/src/cachestoremyriad.h @@ -88,9 +88,6 @@ namespace Bu virtual void unload( obtype *pObj, const keytype &key ) { - int iStream = hId.get( key ); - MyriadStream ns = mStore.openStream( iStream ); - __cacheStoreMyriadStore( ns, *pObj, key ); delete pObj; } @@ -109,8 +106,6 @@ namespace Bu MyriadStream ns = mStore.openStream( 1 ); Bu::Archive ar( ns, Bu::Archive::save ); ar << hId; - - mStore.sync(); } virtual void sync( obtype *pSrc, const keytype &key ) diff --git a/src/cachestorenids.h b/src/cachestorenids.h index c9e8fd1..54129b0 100644 --- a/src/cachestorenids.h +++ b/src/cachestorenids.h @@ -89,9 +89,6 @@ namespace Bu virtual void unload( obtype *pObj, const keytype &key ) { - int iStream = hId.get( key ); - NidsStream ns = nStore.openStream( iStream ); - __cacheStoreNidsStore( ns, *pObj, key ); delete pObj; } @@ -110,8 +107,6 @@ namespace Bu NidsStream ns = nStore.openStream( 0 ); Bu::Archive ar( ns, Bu::Archive::save ); ar << hId; - - nStore.sync(); } virtual void sync( obtype *pSrc, const keytype &key ) diff --git a/src/membuf.cpp b/src/membuf.cpp index fc2ebfa..0c1c441 100644 --- a/src/membuf.cpp +++ b/src/membuf.cpp @@ -145,3 +145,9 @@ Bu::FString &Bu::MemBuf::getString() return sBuf; } +void Bu::MemBuf::setString( const Bu::FString &sNewData ) +{ + sBuf = sNewData; + nPos = 0; +} + diff --git a/src/membuf.h b/src/membuf.h index 3de8552..c6c8079 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -47,6 +47,7 @@ namespace Bu virtual void setBlocking( bool bBlocking=true ); Bu::FString &getString(); + void setString( const Bu::FString &sNewData ); private: Bu::FString sBuf; -- cgit v1.2.3