From 1a0f10f17a85afef20a2610104d590fb1e41cffa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 8 Feb 2009 07:39:09 +0000 Subject: The Bu::CacheStoreNids system has been generalized further while maintaining backwards compatibility. When using it you now have the option to do the loading, storing, and memory allocation yourself if you want to. If you don't it will use new/delete, and an archive to store and load your data for you. --- src/cachestorenids.h | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/cachestorenids.h') diff --git a/src/cachestorenids.h b/src/cachestorenids.h index a5fa402..40213cd 100644 --- a/src/cachestorenids.h +++ b/src/cachestorenids.h @@ -20,6 +20,23 @@ namespace Bu return new obtype(); } + template + void __cacheStoreNidsStore( Bu::Stream &s, obtype &rObj, + const keytype & ) + { + Bu::Archive ar( s, Bu::Archive::save ); + ar << rObj; + } + + template + obtype *__cacheStoreNidsLoad( Bu::Stream &s, const keytype &key ) + { + obtype *pObj = __cacheStoreNidsAlloc( key ); + Bu::Archive ar( s, Bu::Archive::load ); + ar >> (*pObj); + return pObj; + } + template class CacheStoreNids : public CacheStore { @@ -58,9 +75,7 @@ namespace Bu { int iStream = hId.get( key ); NidsStream ns = nStore.openStream( iStream ); - Bu::Archive ar( ns, Bu::Archive::load ); - obtype *pOb = __cacheStoreNidsAlloc( key ); - ar >> (*pOb); + obtype *pOb = __cacheStoreNidsLoad( ns, key ); return pOb; } @@ -68,8 +83,7 @@ namespace Bu { int iStream = hId.get( key ); NidsStream ns = nStore.openStream( iStream ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << (*pObj); + __cacheStoreNidsStore( ns, *pObj, key ); delete pObj; } @@ -79,8 +93,7 @@ namespace Bu int iStream = nStore.createStream(); hId.insert( key, iStream ); NidsStream ns = nStore.openStream( iStream ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << (*pSrc); + __cacheStoreNidsStore( ns, *pSrc, key ); return key; } -- cgit v1.2.3