diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-02-08 07:39:09 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-02-08 07:39:09 +0000 |
commit | 1a0f10f17a85afef20a2610104d590fb1e41cffa (patch) | |
tree | e776db04fdc508548c44406568a6a9999b6db754 /src | |
parent | 366a8063730aa7ae696bcb9cf56eafd13d43dfc0 (diff) | |
download | libbu++-1a0f10f17a85afef20a2610104d590fb1e41cffa.tar.gz libbu++-1a0f10f17a85afef20a2610104d590fb1e41cffa.tar.bz2 libbu++-1a0f10f17a85afef20a2610104d590fb1e41cffa.tar.xz libbu++-1a0f10f17a85afef20a2610104d590fb1e41cffa.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/cachestorenids.h | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/cachestorenids.h b/src/cachestorenids.h index a5fa402..40213cd 100644 --- a/src/cachestorenids.h +++ b/src/cachestorenids.h | |||
@@ -21,6 +21,23 @@ namespace Bu | |||
21 | } | 21 | } |
22 | 22 | ||
23 | template<class obtype, class keytype> | 23 | template<class obtype, class keytype> |
24 | void __cacheStoreNidsStore( Bu::Stream &s, obtype &rObj, | ||
25 | const keytype & ) | ||
26 | { | ||
27 | Bu::Archive ar( s, Bu::Archive::save ); | ||
28 | ar << rObj; | ||
29 | } | ||
30 | |||
31 | template<class obtype, class keytype> | ||
32 | obtype *__cacheStoreNidsLoad( Bu::Stream &s, const keytype &key ) | ||
33 | { | ||
34 | obtype *pObj = __cacheStoreNidsAlloc<obtype, keytype>( key ); | ||
35 | Bu::Archive ar( s, Bu::Archive::load ); | ||
36 | ar >> (*pObj); | ||
37 | return pObj; | ||
38 | } | ||
39 | |||
40 | template<class obtype, class keytype> | ||
24 | class CacheStoreNids : public CacheStore<obtype, keytype> | 41 | class CacheStoreNids : public CacheStore<obtype, keytype> |
25 | { | 42 | { |
26 | public: | 43 | public: |
@@ -58,9 +75,7 @@ namespace Bu | |||
58 | { | 75 | { |
59 | int iStream = hId.get( key ); | 76 | int iStream = hId.get( key ); |
60 | NidsStream ns = nStore.openStream( iStream ); | 77 | NidsStream ns = nStore.openStream( iStream ); |
61 | Bu::Archive ar( ns, Bu::Archive::load ); | 78 | obtype *pOb = __cacheStoreNidsLoad<obtype, keytype>( ns, key ); |
62 | obtype *pOb = __cacheStoreNidsAlloc<obtype, keytype>( key ); | ||
63 | ar >> (*pOb); | ||
64 | return pOb; | 79 | return pOb; |
65 | } | 80 | } |
66 | 81 | ||
@@ -68,8 +83,7 @@ namespace Bu | |||
68 | { | 83 | { |
69 | int iStream = hId.get( key ); | 84 | int iStream = hId.get( key ); |
70 | NidsStream ns = nStore.openStream( iStream ); | 85 | NidsStream ns = nStore.openStream( iStream ); |
71 | Bu::Archive ar( ns, Bu::Archive::save ); | 86 | __cacheStoreNidsStore<obtype, keytype>( ns, *pObj, key ); |
72 | ar << (*pObj); | ||
73 | delete pObj; | 87 | delete pObj; |
74 | } | 88 | } |
75 | 89 | ||
@@ -79,8 +93,7 @@ namespace Bu | |||
79 | int iStream = nStore.createStream(); | 93 | int iStream = nStore.createStream(); |
80 | hId.insert( key, iStream ); | 94 | hId.insert( key, iStream ); |
81 | NidsStream ns = nStore.openStream( iStream ); | 95 | NidsStream ns = nStore.openStream( iStream ); |
82 | Bu::Archive ar( ns, Bu::Archive::save ); | 96 | __cacheStoreNidsStore<obtype, keytype>( ns, *pSrc, key ); |
83 | ar << (*pSrc); | ||
84 | return key; | 97 | return key; |
85 | } | 98 | } |
86 | 99 | ||