From fb5176bbd5355b02b7d0e65da3ef3f0105824cd0 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 17 Mar 2013 23:45:21 +0000 Subject: The new cache system has been broken out into it's individual headers, and is now ready for actual use. --- src/experimental/cachestoremyriad.h | 158 ------------------------------------ 1 file changed, 158 deletions(-) delete mode 100644 src/experimental/cachestoremyriad.h (limited to 'src/experimental/cachestoremyriad.h') diff --git a/src/experimental/cachestoremyriad.h b/src/experimental/cachestoremyriad.h deleted file mode 100644 index 798d205..0000000 --- a/src/experimental/cachestoremyriad.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2007-2013 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_CACHE_STORE_MYRIAD_H -#define BU_CACHE_STORE_MYRIAD_H - -#include "bu/string.h" -#include "bu/stream.h" -#include "bu/myriad.h" -#include "bu/cachestore.h" -#include "bu/myriadstream.h" - -#include "bu/archive.h" - -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; - }; -}; - -#endif -- cgit v1.2.3