From ec05778d5718a7912e506764d443a78d6a6179e3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 5 Nov 2012 22:41:51 +0000 Subject: Converted tabs to spaces with tabconv. --- src/experimental/cachestoremyriad.h | 270 ++++++++++++++++++------------------ 1 file changed, 135 insertions(+), 135 deletions(-) (limited to 'src/experimental/cachestoremyriad.h') diff --git a/src/experimental/cachestoremyriad.h b/src/experimental/cachestoremyriad.h index 1953b61..01fe307 100644 --- a/src/experimental/cachestoremyriad.h +++ b/src/experimental/cachestoremyriad.h @@ -18,141 +18,141 @@ namespace Bu { - template - keytype __cacheGetKey( const obtype *pObj ); - - template - obtype *__cacheStoreMyriadAlloc( const keytype &key ) - { - return new obtype(); - } - - template - void __cacheStoreMyriadStore( Bu::Stream &s, obtype &rObj, - const keytype & ) - { - Bu::Archive ar( s, Bu::Archive::save ); - ar << rObj; - } - - template - obtype *__cacheStoreMyriadLoad( Bu::Stream &s, const keytype &key ) - { - obtype *pObj = __cacheStoreMyriadAlloc( key ); - Bu::Archive ar( s, Bu::Archive::load ); - ar >> (*pObj); - return pObj; - } - - template - class CacheStoreMyriad : public CacheStore - { - public: - CacheStoreMyriad( Bu::Stream &sArch, - int iBlockSize=512, int iPreAllocate=8 ) : - mStore( sArch, iBlockSize, iPreAllocate ) - { - try - { - MyriadStream ns = mStore.openStream( 1 ); - Bu::Archive ar( ns, Bu::Archive::load ); - ar >> hId; - } - catch( Bu::MyriadException &e ) - { - int iStream = mStore.createStream(); - if( iStream != 1 ) - throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", - iStream ); - MyriadStream ns = mStore.openStream( 1 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - } - } - - virtual ~CacheStoreMyriad() - { - MyriadStream ns = mStore.openStream( 1 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - } - - virtual obtype *load( const keytype &key ) - { - int iStream = hId.get( key ); - MyriadStream ns = mStore.openStream( iStream ); - obtype *pOb = __cacheStoreMyriadLoad( ns, key ); - return pOb; - } - - virtual void unload( obtype *pObj, const keytype & ) - { - delete pObj; - } - - virtual keytype create( obtype *pSrc ) - { - keytype key = __cacheGetKey( pSrc ); - int iStream = mStore.createStream(); - hId.insert( key, iStream ); - MyriadStream ns = mStore.openStream( iStream ); - __cacheStoreMyriadStore( ns, *pSrc, key ); - ns.setSize( ns.tell() ); - return key; - } - - virtual void sync() - { - MyriadStream ns = mStore.openStream( 1 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - ns.setSize( ns.tell() ); - mStore.sync(); - } - - virtual void sync( obtype *pSrc, const keytype &key ) - { - int iStream = hId.get( key ); - MyriadStream ns = mStore.openStream( iStream ); - __cacheStoreMyriadStore( ns, *pSrc, key ); - ns.setSize( ns.tell() ); - } - - virtual void destroy( obtype *pObj, const keytype &key ) - { - int iStream = hId.get( key ); - mStore.deleteStream( iStream ); - hId.erase( key ); - delete pObj; - } - - virtual void destroy( const keytype &key ) - { - int iStream = hId.get( key ); - mStore.deleteStream( iStream ); - hId.erase( key ); - } - - virtual bool has( const keytype &key ) - { - return hId.has( key ); - } - - virtual Bu::List getKeys() - { - return hId.getKeys(); - } - - virtual int getSize() - { - return hId.getSize(); - } - - private: - Myriad mStore; - typedef Bu::Hash StreamHash; - StreamHash hId; - }; + template + keytype __cacheGetKey( const obtype *pObj ); + + template + obtype *__cacheStoreMyriadAlloc( const keytype &key ) + { + return new obtype(); + } + + template + void __cacheStoreMyriadStore( Bu::Stream &s, obtype &rObj, + const keytype & ) + { + Bu::Archive ar( s, Bu::Archive::save ); + ar << rObj; + } + + template + obtype *__cacheStoreMyriadLoad( Bu::Stream &s, const keytype &key ) + { + obtype *pObj = __cacheStoreMyriadAlloc( key ); + Bu::Archive ar( s, Bu::Archive::load ); + ar >> (*pObj); + return pObj; + } + + template + class CacheStoreMyriad : public CacheStore + { + public: + CacheStoreMyriad( Bu::Stream &sArch, + int iBlockSize=512, int iPreAllocate=8 ) : + mStore( sArch, iBlockSize, iPreAllocate ) + { + try + { + MyriadStream ns = mStore.openStream( 1 ); + Bu::Archive ar( ns, Bu::Archive::load ); + ar >> hId; + } + catch( Bu::MyriadException &e ) + { + int iStream = mStore.createStream(); + if( iStream != 1 ) + throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", + iStream ); + MyriadStream ns = mStore.openStream( 1 ); + Bu::Archive ar( ns, Bu::Archive::save ); + ar << hId; + } + } + + virtual ~CacheStoreMyriad() + { + MyriadStream ns = mStore.openStream( 1 ); + Bu::Archive ar( ns, Bu::Archive::save ); + ar << hId; + } + + virtual obtype *load( const keytype &key ) + { + int iStream = hId.get( key ); + MyriadStream ns = mStore.openStream( iStream ); + obtype *pOb = __cacheStoreMyriadLoad( ns, key ); + return pOb; + } + + virtual void unload( obtype *pObj, const keytype & ) + { + delete pObj; + } + + virtual keytype create( obtype *pSrc ) + { + keytype key = __cacheGetKey( pSrc ); + int iStream = mStore.createStream(); + hId.insert( key, iStream ); + MyriadStream ns = mStore.openStream( iStream ); + __cacheStoreMyriadStore( ns, *pSrc, key ); + ns.setSize( ns.tell() ); + return key; + } + + virtual void sync() + { + MyriadStream ns = mStore.openStream( 1 ); + Bu::Archive ar( ns, Bu::Archive::save ); + ar << hId; + ns.setSize( ns.tell() ); + mStore.sync(); + } + + virtual void sync( obtype *pSrc, const keytype &key ) + { + int iStream = hId.get( key ); + MyriadStream ns = mStore.openStream( iStream ); + __cacheStoreMyriadStore( ns, *pSrc, key ); + ns.setSize( ns.tell() ); + } + + virtual void destroy( obtype *pObj, const keytype &key ) + { + int iStream = hId.get( key ); + mStore.deleteStream( iStream ); + hId.erase( key ); + delete pObj; + } + + virtual void destroy( const keytype &key ) + { + int iStream = hId.get( key ); + mStore.deleteStream( iStream ); + hId.erase( key ); + } + + virtual bool has( const keytype &key ) + { + return hId.has( key ); + } + + virtual Bu::List getKeys() + { + return hId.getKeys(); + } + + virtual int getSize() + { + return hId.getSize(); + } + + private: + Myriad mStore; + typedef Bu::Hash StreamHash; + StreamHash hId; + }; }; #endif -- cgit v1.2.3