diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2013-03-17 23:45:21 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2013-03-17 23:45:21 +0000 |
| commit | fb5176bbd5355b02b7d0e65da3ef3f0105824cd0 (patch) | |
| tree | 32a9d8114ce4852b901a35f6aec982e6071a3bac /src/unstable/cacheobject.h | |
| parent | a6d249cad214dc0baff0e80e56ffdec91d8a1cf0 (diff) | |
| download | libbu++-fb5176bbd5355b02b7d0e65da3ef3f0105824cd0.tar.gz libbu++-fb5176bbd5355b02b7d0e65da3ef3f0105824cd0.tar.bz2 libbu++-fb5176bbd5355b02b7d0e65da3ef3f0105824cd0.tar.xz libbu++-fb5176bbd5355b02b7d0e65da3ef3f0105824cd0.zip | |
The new cache system has been broken out into it's individual headers, and is
now ready for actual use.
Diffstat (limited to 'src/unstable/cacheobject.h')
| -rw-r--r-- | src/unstable/cacheobject.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/unstable/cacheobject.h b/src/unstable/cacheobject.h new file mode 100644 index 0000000..0088685 --- /dev/null +++ b/src/unstable/cacheobject.h | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007-2013 Xagasoft, All rights reserved. | ||
| 3 | * | ||
| 4 | * This file is part of the libbu++ library and is released under the | ||
| 5 | * terms of the license contained in the file LICENSE. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef BU_CACHE_OBJECT_H | ||
| 9 | #define BU_CACHE_OBJECT_H | ||
| 10 | |||
| 11 | #ifndef NULL | ||
| 12 | #define NULL 0 | ||
| 13 | #endif | ||
| 14 | |||
| 15 | namespace Bu | ||
| 16 | { | ||
| 17 | template<typename keytype, typename obtype> class CacheBase; | ||
| 18 | template<typename keytype, typename obtype> class CacheEntry; | ||
| 19 | |||
| 20 | template<typename keytype, typename obtype> | ||
| 21 | class CacheObject | ||
| 22 | { | ||
| 23 | friend class CacheBase<keytype, obtype>; | ||
| 24 | public: | ||
| 25 | CacheObject() : | ||
| 26 | pCache( NULL ), | ||
| 27 | bChanged( false ) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | virtual ~CacheObject() | ||
| 32 | { | ||
| 33 | } | ||
| 34 | |||
| 35 | typedef CacheBase<keytype, obtype> CacheType; | ||
| 36 | |||
| 37 | virtual keytype getKey() const=0; | ||
| 38 | virtual int getPersistenceScore() const { return 0; } | ||
| 39 | |||
| 40 | void lock() | ||
| 41 | { | ||
| 42 | pEntry->lock(); | ||
| 43 | } | ||
| 44 | |||
| 45 | void unlock() | ||
| 46 | { | ||
| 47 | pEntry->unlock(); | ||
| 48 | } | ||
| 49 | |||
| 50 | int getRefCount() const | ||
| 51 | { | ||
| 52 | return pEntry->getRefCount(); | ||
| 53 | } | ||
| 54 | |||
| 55 | bool hasChanged() const | ||
| 56 | { | ||
| 57 | return bChanged; | ||
| 58 | } | ||
| 59 | |||
| 60 | protected: | ||
| 61 | void changed( bool bChanged=true ) | ||
| 62 | { | ||
| 63 | if( this->bChanged == false && bChanged == true ) | ||
| 64 | pCache->objectChanged( getKey() ); | ||
| 65 | |||
| 66 | this->bChanged = bChanged; | ||
| 67 | } | ||
| 68 | |||
| 69 | private: | ||
| 70 | typedef CacheEntry<keytype, obtype> Entry; | ||
| 71 | void setCache( CacheType *pCache, Entry *pEntry ) | ||
| 72 | { | ||
| 73 | this->pCache = pCache; | ||
| 74 | this->pEntry = pEntry; | ||
| 75 | } | ||
| 76 | |||
| 77 | private: | ||
| 78 | CacheType *pCache; | ||
| 79 | Entry *pEntry; | ||
| 80 | bool bChanged; | ||
| 81 | }; | ||
| 82 | } | ||
| 83 | |||
| 84 | #endif | ||
