aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cache.h16
-rw-r--r--src/cachecalc.h8
-rw-r--r--src/cachestore.h2
-rw-r--r--src/cachestorenids.h24
-rw-r--r--src/tests/cache.cpp6
5 files changed, 28 insertions, 28 deletions
diff --git a/src/cache.h b/src/cache.h
index 87037f7..c738d28 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -18,10 +18,10 @@
18 18
19namespace Bu 19namespace Bu
20{ 20{
21// template<class obtype, class keytype> 21// template<class keytype, class obtype>
22// keytype __cacheGetKey( obtype *&pObj ); 22// keytype __cacheGetKey( obtype *&pObj );
23 23
24 template<class obtype, class keytype> 24 template<class keytype, class obtype>
25 class Cache 25 class Cache
26 { 26 {
27 public: 27 public:
@@ -32,9 +32,9 @@ namespace Bu
32 */ 32 */
33 class Ptr 33 class Ptr
34 { 34 {
35 friend class Bu::Cache<obtype, keytype>; 35 friend class Bu::Cache<keytype, obtype>;
36 private: 36 private:
37 Ptr( Cache<obtype, keytype> *pCache, obtype *pData, 37 Ptr( Cache<keytype, obtype> *pCache, obtype *pData,
38 const keytype &kId ) : 38 const keytype &kId ) :
39 pCache( pCache ), 39 pCache( pCache ),
40 pData( pData ), 40 pData( pData ),
@@ -44,7 +44,7 @@ namespace Bu
44 pCache->incRef( kId ); 44 pCache->incRef( kId );
45 } 45 }
46 46
47 Ptr( Cache<obtype, keytype> *pCache, const keytype &kId ) : 47 Ptr( Cache<keytype, obtype> *pCache, const keytype &kId ) :
48 pCache( pCache ), 48 pCache( pCache ),
49 pData( NULL ), 49 pData( NULL ),
50 kId( kId ) 50 kId( kId )
@@ -168,15 +168,15 @@ namespace Bu
168 } 168 }
169 169
170 private: 170 private:
171 Bu::Cache<obtype, keytype> *pCache; 171 Bu::Cache<keytype, obtype> *pCache;
172 mutable obtype *pData; 172 mutable obtype *pData;
173 mutable keytype kId; 173 mutable keytype kId;
174 }; 174 };
175 175
176 private: 176 private:
177 typedef Bu::CacheStore<obtype, keytype> Store; 177 typedef Bu::CacheStore<keytype, obtype> Store;
178 typedef Bu::List<Store *> StoreList; 178 typedef Bu::List<Store *> StoreList;
179 typedef Bu::CacheCalc<obtype, keytype> Calc; 179 typedef Bu::CacheCalc<keytype, obtype> Calc;
180 180
181 typedef struct CacheEntry 181 typedef struct CacheEntry
182 { 182 {
diff --git a/src/cachecalc.h b/src/cachecalc.h
index dd6add1..27680b9 100644
--- a/src/cachecalc.h
+++ b/src/cachecalc.h
@@ -14,14 +14,14 @@
14 14
15namespace Bu 15namespace Bu
16{ 16{
17 template<class obtype, class keytype> class Cache; 17 template<class keytype, class obtype> class Cache;
18 18
19 template<class obtype, class keytype> 19 template<class keytype, class obtype>
20 class CacheCalc 20 class CacheCalc
21 { 21 {
22 friend class Cache<obtype, keytype>; 22 friend class Cache<keytype, obtype>;
23 private: 23 private:
24 typedef Cache<obtype, keytype> MyCache; 24 typedef Cache<keytype, obtype> MyCache;
25 public: 25 public:
26 CacheCalc() : 26 CacheCalc() :
27 pCache( (MyCache *)0 ) 27 pCache( (MyCache *)0 )
diff --git a/src/cachestore.h b/src/cachestore.h
index 6ce42b8..d44326d 100644
--- a/src/cachestore.h
+++ b/src/cachestore.h
@@ -16,7 +16,7 @@ namespace Bu
16 * Handles I/O for data in the cache. This also assigns ID's to the newly 16 * Handles I/O for data in the cache. This also assigns ID's to the newly
17 * created objects that are requested through this system. 17 * created objects that are requested through this system.
18 */ 18 */
19 template<class obtype, class keytype> 19 template<class keytype, class obtype>
20 class CacheStore 20 class CacheStore
21 { 21 {
22 public: 22 public:
diff --git a/src/cachestorenids.h b/src/cachestorenids.h
index ae2b9a2..0d104cf 100644
--- a/src/cachestorenids.h
+++ b/src/cachestorenids.h
@@ -19,16 +19,16 @@
19 19
20namespace Bu 20namespace Bu
21{ 21{
22 template<class obtype, class keytype> 22 template<class keytype, class obtype>
23 keytype __cacheGetKey( const obtype *pObj ); 23 keytype __cacheGetKey( const obtype *pObj );
24 24
25 template<class obtype, class keytype> 25 template<class keytype, class obtype>
26 obtype *__cacheStoreNidsAlloc( const keytype &key ) 26 obtype *__cacheStoreNidsAlloc( const keytype &key )
27 { 27 {
28 return new obtype(); 28 return new obtype();
29 } 29 }
30 30
31 template<class obtype, class keytype> 31 template<class keytype, class obtype>
32 void __cacheStoreNidsStore( Bu::Stream &s, obtype &rObj, 32 void __cacheStoreNidsStore( Bu::Stream &s, obtype &rObj,
33 const keytype & ) 33 const keytype & )
34 { 34 {
@@ -36,17 +36,17 @@ namespace Bu
36 ar << rObj; 36 ar << rObj;
37 } 37 }
38 38
39 template<class obtype, class keytype> 39 template<class keytype, class obtype>
40 obtype *__cacheStoreNidsLoad( Bu::Stream &s, const keytype &key ) 40 obtype *__cacheStoreNidsLoad( Bu::Stream &s, const keytype &key )
41 { 41 {
42 obtype *pObj = __cacheStoreNidsAlloc<obtype, keytype>( key ); 42 obtype *pObj = __cacheStoreNidsAlloc<keytype, obtype>( key );
43 Bu::Archive ar( s, Bu::Archive::load ); 43 Bu::Archive ar( s, Bu::Archive::load );
44 ar >> (*pObj); 44 ar >> (*pObj);
45 return pObj; 45 return pObj;
46 } 46 }
47 47
48 template<class obtype, class keytype> 48 template<class keytype, class obtype>
49 class CacheStoreNids : public CacheStore<obtype, keytype> 49 class CacheStoreNids : public CacheStore<keytype, obtype>
50 { 50 {
51 public: 51 public:
52 CacheStoreNids( Bu::Stream &sArch, 52 CacheStoreNids( Bu::Stream &sArch,
@@ -83,7 +83,7 @@ namespace Bu
83 { 83 {
84 int iStream = hId.get( key ); 84 int iStream = hId.get( key );
85 NidsStream ns = nStore.openStream( iStream ); 85 NidsStream ns = nStore.openStream( iStream );
86 obtype *pOb = __cacheStoreNidsLoad<obtype, keytype>( ns, key ); 86 obtype *pOb = __cacheStoreNidsLoad<keytype, obtype>( ns, key );
87 return pOb; 87 return pOb;
88 } 88 }
89 89
@@ -91,17 +91,17 @@ namespace Bu
91 { 91 {
92 int iStream = hId.get( key ); 92 int iStream = hId.get( key );
93 NidsStream ns = nStore.openStream( iStream ); 93 NidsStream ns = nStore.openStream( iStream );
94 __cacheStoreNidsStore<obtype, keytype>( ns, *pObj, key ); 94 __cacheStoreNidsStore<keytype, obtype>( ns, *pObj, key );
95 delete pObj; 95 delete pObj;
96 } 96 }
97 97
98 virtual keytype create( obtype *pSrc ) 98 virtual keytype create( obtype *pSrc )
99 { 99 {
100 keytype key = __cacheGetKey<obtype,keytype>( pSrc ); 100 keytype key = __cacheGetKey<keytype, obtype>( pSrc );
101 int iStream = nStore.createStream(); 101 int iStream = nStore.createStream();
102 hId.insert( key, iStream ); 102 hId.insert( key, iStream );
103 NidsStream ns = nStore.openStream( iStream ); 103 NidsStream ns = nStore.openStream( iStream );
104 __cacheStoreNidsStore<obtype, keytype>( ns, *pSrc, key ); 104 __cacheStoreNidsStore<keytype, obtype>( ns, *pSrc, key );
105 return key; 105 return key;
106 } 106 }
107 107
@@ -118,7 +118,7 @@ namespace Bu
118 { 118 {
119 int iStream = hId.get( key ); 119 int iStream = hId.get( key );
120 NidsStream ns = nStore.openStream( iStream ); 120 NidsStream ns = nStore.openStream( iStream );
121 __cacheStoreNidsStore<obtype, keytype>( ns, *pSrc, key ); 121 __cacheStoreNidsStore<keytype, obtype>( ns, *pSrc, key );
122 } 122 }
123 123
124 virtual void destroy( obtype *pObj, const keytype &key ) 124 virtual void destroy( obtype *pObj, const keytype &key )
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index a098145..11a4215 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -58,7 +58,7 @@ namespace Bu {
58 } 58 }
59} 59}
60 60
61class BobStore : public Bu::CacheStore<Bob, long> 61class BobStore : public Bu::CacheStore<long, Bob>
62{ 62{
63public: 63public:
64 BobStore() : 64 BobStore() :
@@ -158,7 +158,7 @@ private:
158 long cLastId; 158 long cLastId;
159}; 159};
160 160
161class BobCalc : public Bu::CacheCalc<Bob, long> 161class BobCalc : public Bu::CacheCalc<long, Bob>
162{ 162{
163public: 163public:
164 BobCalc() 164 BobCalc()
@@ -189,7 +189,7 @@ private:
189int main( int argc, char *argv[] ) 189int main( int argc, char *argv[] )
190{ 190{
191 TRACE( argc, argv ); 191 TRACE( argc, argv );
192 typedef Bu::Cache<Bob, long> BobCache; 192 typedef Bu::Cache<long, Bob> BobCache;
193 typedef BobCache::Ptr BobPtr; 193 typedef BobCache::Ptr BobPtr;
194 194
195 if( argc < 3 ) 195 if( argc < 3 )