aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2013-03-13 05:03:59 +0000
committerMike Buland <eichlan@xagasoft.com>2013-03-13 05:03:59 +0000
commit55f8e2c01fe4513d5e3de55f567c392b4a18ecc2 (patch)
tree0e515f65ff43fbebe396516e79cb5f6b96759e73 /src/tests
parent0ac226c809b6495d5dbc09c2f847638e10aca315 (diff)
downloadlibbu++-55f8e2c01fe4513d5e3de55f567c392b4a18ecc2.tar.gz
libbu++-55f8e2c01fe4513d5e3de55f567c392b4a18ecc2.tar.bz2
libbu++-55f8e2c01fe4513d5e3de55f567c392b4a18ecc2.tar.xz
libbu++-55f8e2c01fe4513d5e3de55f567c392b4a18ecc2.zip
Added bind/unbind to the Cache system. Fixed typo in docs of heap.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cache.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index 15662af..aa71c39 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -220,7 +220,7 @@ public:
220 220
221 virtual ~CachePtr() 221 virtual ~CachePtr()
222 { 222 {
223 release(); 223 unbind();
224 } 224 }
225 225
226 const keytype &getKey() const 226 const keytype &getKey() const
@@ -230,31 +230,31 @@ public:
230 230
231 obtype &operator*() 231 obtype &operator*()
232 { 232 {
233 checkRef(); 233 bind();
234 return pData; 234 return pData;
235 } 235 }
236 236
237 const obtype &operator*() const 237 const obtype &operator*() const
238 { 238 {
239 checkRef(); 239 bind();
240 return pData; 240 return pData;
241 } 241 }
242 242
243 obtype *operator->() 243 obtype *operator->()
244 { 244 {
245 checkRef(); 245 bind();
246 return pData; 246 return pData;
247 } 247 }
248 248
249 const obtype *operator->() const 249 const obtype *operator->() const
250 { 250 {
251 checkRef(); 251 bind();
252 return pData; 252 return pData;
253 } 253 }
254 254
255 MyType operator=( const MyType &rhs ) 255 MyType operator=( const MyType &rhs )
256 { 256 {
257 release(); 257 unbind();
258 pCache = rhs.pCache; 258 pCache = rhs.pCache;
259 kId = rhs.kId; 259 kId = rhs.kId;
260 pEnt = rhs.pEnt; 260 pEnt = rhs.pEnt;
@@ -275,22 +275,27 @@ public:
275 return pCache != rhs.pCache || 275 return pCache != rhs.pCache ||
276 kId != rhs.kId; 276 kId != rhs.kId;
277 } 277 }
278
279 void bind()
280 {
281 CachePtrInterface<keytype, basetype>::checkRef( pCache, kId, pEnt, pData );
282 }
278 283
279 void release() 284 void unbind()
280 { 285 {
281 CachePtrInterface<keytype, basetype>::releaseRef( pCache, pEnt, pData ); 286 CachePtrInterface<keytype, basetype>::releaseRef( pCache, pEnt, pData );
282 } 287 }
283 288
284 void lock() 289 void lock()
285 { 290 {
286 checkRef(); 291 bind();
287 if( pEnt ) 292 if( pEnt )
288 pEnt->lock(); 293 pEnt->lock();
289 } 294 }
290 295
291 void unlock() 296 void unlock()
292 { 297 {
293 checkRef(); 298 bind();
294 if( pEnt ) 299 if( pEnt )
295 pEnt->unlock(); 300 pEnt->unlock();
296 } 301 }
@@ -324,12 +329,6 @@ public:
324 }; 329 };
325 330
326private: 331private:
327 void checkRef()
328 {
329 CachePtrInterface<keytype, basetype>::checkRef( pCache, kId, pEnt, pData );
330 }
331
332private:
333 CacheBase<keytype, basetype> *pCache; 332 CacheBase<keytype, basetype> *pCache;
334 mutable keytype kId; 333 mutable keytype kId;
335 mutable CacheEntry<keytype, basetype> *pEnt; 334 mutable CacheEntry<keytype, basetype> *pEnt;
@@ -658,13 +657,13 @@ int main( int argc, char *argv[] )
658 657
659 c._debug(); 658 c._debug();
660 659
661 p1.release(); 660 p1.unbind();
662 661
663 c._debug(); 662 c._debug();
664 663
665 Bu::println("Name: %1").arg( p1->getName() ); 664 Bu::println("Name: %1").arg( p1->getName() );
666 665
667 p1.release(); 666 p1.unbind();
668 p1.lock(); 667 p1.lock();
669 p1.unlock(); 668 p1.unlock();
670 669