summaryrefslogtreecommitdiff
path: root/src/unstable/cacheobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/cacheobject.h')
-rw-r--r--src/unstable/cacheobject.h84
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
15namespace 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