diff options
Diffstat (limited to 'src/unstable/cachebase.h')
-rw-r--r-- | src/unstable/cachebase.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index af2884c..bb543dd 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h | |||
@@ -328,6 +328,7 @@ namespace Bu | |||
328 | 328 | ||
329 | typedef CacheEntry<keytype, obtype> Entry; | 329 | typedef CacheEntry<keytype, obtype> Entry; |
330 | typedef Bu::List<keytype> KeyList; | 330 | typedef Bu::List<keytype> KeyList; |
331 | typedef CacheObject<keytype, obtype> ObjectType; | ||
331 | 332 | ||
332 | CachePtr<keytype, obtype> insert( obtype *pObject ) | 333 | CachePtr<keytype, obtype> insert( obtype *pObject ) |
333 | { | 334 | { |
@@ -466,7 +467,10 @@ namespace Bu | |||
466 | virtual void _create( const obtype *o )=0; | 467 | virtual void _create( const obtype *o )=0; |
467 | virtual void _erase( const keytype &k )=0; | 468 | virtual void _erase( const keytype &k )=0; |
468 | 469 | ||
469 | virtual obtype *_load( const keytype &k )=0; | 470 | virtual obtype *_load( |
471 | typename Bu::CacheObject<keytype, obtype>::Initializer &initObj, | ||
472 | const keytype &k | ||
473 | )=0; | ||
470 | virtual void _save( const obtype *o )=0; | 474 | virtual void _save( const obtype *o )=0; |
471 | 475 | ||
472 | virtual void _sync()=0; | 476 | virtual void _sync()=0; |
@@ -481,7 +485,10 @@ namespace Bu | |||
481 | hChanged.insert( pObject->getKey(), true ); | 485 | hChanged.insert( pObject->getKey(), true ); |
482 | mCacheEntry.unlockWrite(); | 486 | mCacheEntry.unlockWrite(); |
483 | _create( pObject ); | 487 | _create( pObject ); |
484 | pObject->setCache( this, pEnt ); | 488 | // I'm not sold on the ordering here...or the fact we're not |
489 | // using th initilizer | ||
490 | pObject->setCache( this ); | ||
491 | pObject->setCacheEntry( pEnt ); | ||
485 | 492 | ||
486 | return pEnt; | 493 | return pEnt; |
487 | } | 494 | } |
@@ -497,9 +504,12 @@ namespace Bu | |||
497 | catch(...) | 504 | catch(...) |
498 | { | 505 | { |
499 | // try to load the object from the backing store | 506 | // try to load the object from the backing store |
500 | obtype *pObject = _load( k ); | 507 | typename ObjectType::Initializer initObj( |
508 | this | ||
509 | ); | ||
510 | obtype *pObject = _load( initObj, k ); | ||
501 | pEnt = new Entry( pObject ); | 511 | pEnt = new Entry( pObject ); |
502 | pObject->setCache( this, pEnt ); | 512 | pObject->setCacheEntry( pEnt ); |
503 | Bu::ReadWriteMutex::WriteLocker wl( mCacheEntry ); | 513 | Bu::ReadWriteMutex::WriteLocker wl( mCacheEntry ); |
504 | hCacheEntry.insert( k, pEnt ); | 514 | hCacheEntry.insert( k, pEnt ); |
505 | } | 515 | } |
@@ -536,11 +546,15 @@ namespace Bu | |||
536 | ar << *pObject; | 546 | ar << *pObject; |
537 | } | 547 | } |
538 | 548 | ||
539 | template<typename obtype> | 549 | template<typename keytype, typename obtype> |
540 | obtype *_cacheObjectLoad( Bu::Stream &s ) | 550 | obtype *_cacheObjectLoad( |
551 | typename Bu::CacheObject<keytype, obtype>::Initializer &initObject, | ||
552 | const keytype & /*rKey*/, | ||
553 | Bu::Stream &s | ||
554 | ) | ||
541 | { | 555 | { |
542 | Bu::Archive ar( s, Bu::Archive::load ); | 556 | Bu::Archive ar( s, Bu::Archive::load ); |
543 | obtype *ret = new obtype(); | 557 | obtype *ret = initObject(new obtype()); |
544 | ar >> *ret; | 558 | ar >> *ret; |
545 | return ret; | 559 | return ret; |
546 | } | 560 | } |