author | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
commit | 6c715b67a8f0e32a4edca5be91332622834c8d91 (patch) (unidiff) | |
tree | ae2d660e1fd9c990c2d725c075ce6c42480b0af8 /libopie/pim/opimcache.h | |
parent | cb45aa10043fdd6fddcab42ef0e07ddafc3d506d (diff) | |
download | opie-6c715b67a8f0e32a4edca5be91332622834c8d91.zip opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.gz opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.bz2 |
Merging changes from BRANCH_1_0 to HEAD
-rw-r--r-- | libopie/pim/opimcache.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h index 73414e5..7f7cff5 100644 --- a/libopie/pim/opimcache.h +++ b/libopie/pim/opimcache.h | |||
@@ -1,96 +1,102 @@ | |||
1 | #ifndef OPIE_PIM_CACHE_H | 1 | #ifndef OPIE_PIM_CACHE_H |
2 | #define OPIE_PIM_CACHE_H | 2 | #define OPIE_PIM_CACHE_H |
3 | 3 | ||
4 | #include <qintcache.h> | 4 | #include <qintcache.h> |
5 | 5 | ||
6 | #include "opimrecord.h" | 6 | #include "opimrecord.h" |
7 | 7 | ||
8 | class OPimCacheItemPrivate; | ||
9 | |||
8 | template <class T = OPimRecord> | 10 | template <class T = OPimRecord> |
9 | class OPimCacheItem { | 11 | class OPimCacheItem { |
10 | public: | 12 | public: |
11 | OPimCacheItem( const T& t = T() ); | 13 | OPimCacheItem( const T& t = T() ); |
12 | OPimCacheItem( const OPimCacheItem& ); | 14 | OPimCacheItem( const OPimCacheItem& ); |
13 | ~OPimCacheItem(); | 15 | ~OPimCacheItem(); |
14 | 16 | ||
15 | OPimCacheItem &operator=( const OPimCacheItem& ); | 17 | OPimCacheItem &operator=( const OPimCacheItem& ); |
16 | 18 | ||
17 | T record()const; | 19 | T record()const; |
18 | void setRecord( const T& ); | 20 | void setRecord( const T& ); |
19 | private: | 21 | private: |
20 | T m_t; | 22 | T m_t; |
23 | OPimCacheItemPrivate *d; | ||
21 | }; | 24 | }; |
22 | 25 | ||
26 | |||
27 | class OPimCachePrivate; | ||
23 | /** | 28 | /** |
24 | * OPimCache for caching the items | 29 | * OPimCache for caching the items |
25 | * We support adding, removing | 30 | * We support adding, removing |
26 | * and finding | 31 | * and finding |
27 | */ | 32 | */ |
28 | template <class T = OPimRecord> | 33 | template <class T = OPimRecord> |
29 | class OPimCache { | 34 | class OPimCache { |
30 | public: | 35 | public: |
31 | typedef OPimCacheItem<T> Item; | 36 | typedef OPimCacheItem<T> Item; |
32 | OPimCache(); | 37 | OPimCache(); |
33 | OPimCache( const OPimCache& ); | 38 | OPimCache( const OPimCache& ); |
34 | ~OPimCache(); | 39 | ~OPimCache(); |
35 | 40 | ||
36 | OPimCache &operator=( const OPimCache& ); | 41 | OPimCache &operator=( const OPimCache& ); |
37 | 42 | ||
38 | bool contains(int uid)const; | 43 | bool contains(int uid)const; |
39 | void invalidate(); | 44 | void invalidate(); |
40 | void setSize( int size ); | 45 | void setSize( int size ); |
41 | 46 | ||
42 | T find(int uid )const; | 47 | T find(int uid )const; |
43 | void add( const T& ); | 48 | void add( const T& ); |
44 | void remove( int uid ); | 49 | void remove( int uid ); |
45 | void replace( const T& ); | 50 | void replace( const T& ); |
46 | 51 | ||
47 | private: | 52 | private: |
48 | QIntCache<Item> m_cache; | 53 | QIntCache<Item> m_cache; |
54 | OPimCachePrivate* d; | ||
49 | }; | 55 | }; |
50 | 56 | ||
51 | // Implementation | 57 | // Implementation |
52 | template <class T> | 58 | template <class T> |
53 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 59 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
54 | : m_t(t) { | 60 | : m_t(t) { |
55 | } | 61 | } |
56 | template <class T> | 62 | template <class T> |
57 | OPimCacheItem<T>::~OPimCacheItem() { | 63 | OPimCacheItem<T>::~OPimCacheItem() { |
58 | 64 | ||
59 | } | 65 | } |
60 | template <class T> | 66 | template <class T> |
61 | T OPimCacheItem<T>::record()const { | 67 | T OPimCacheItem<T>::record()const { |
62 | return m_t; | 68 | return m_t; |
63 | } | 69 | } |
64 | template <class T> | 70 | template <class T> |
65 | void OPimCacheItem<T>::setRecord( const T& t ) { | 71 | void OPimCacheItem<T>::setRecord( const T& t ) { |
66 | m_t = t; | 72 | m_t = t; |
67 | } | 73 | } |
68 | // Cache | 74 | // Cache |
69 | template <class T> | 75 | template <class T> |
70 | OPimCache<T>::OPimCache() | 76 | OPimCache<T>::OPimCache() |
71 | : m_cache(100, 53 ) | 77 | : m_cache(100, 53 ) |
72 | { | 78 | { |
73 | m_cache.setAutoDelete( TRUE ); | 79 | m_cache.setAutoDelete( TRUE ); |
74 | } | 80 | } |
75 | template <class T> | 81 | template <class T> |
76 | OPimCache<T>::~OPimCache() { | 82 | OPimCache<T>::~OPimCache() { |
77 | 83 | ||
78 | } | 84 | } |
79 | template <class T> | 85 | template <class T> |
80 | bool OPimCache<T>::contains(int uid )const { | 86 | bool OPimCache<T>::contains(int uid )const { |
81 | Item* it = m_cache.find( uid, FALSE ); | 87 | Item* it = m_cache.find( uid, FALSE ); |
82 | if (!it) | 88 | if (!it) |
83 | return false; | 89 | return false; |
84 | return true; | 90 | return true; |
85 | } | 91 | } |
86 | template <class T> | 92 | template <class T> |
87 | void OPimCache<T>::invalidate() { | 93 | void OPimCache<T>::invalidate() { |
88 | m_cache.clear(); | 94 | m_cache.clear(); |
89 | } | 95 | } |
90 | template <class T> | 96 | template <class T> |
91 | void OPimCache<T>::setSize( int size ) { | 97 | void OPimCache<T>::setSize( int size ) { |
92 | m_cache.setMaxCost( size ); | 98 | m_cache.setMaxCost( size ); |
93 | } | 99 | } |
94 | template <class T> | 100 | template <class T> |
95 | T OPimCache<T>::find(int uid )const { | 101 | T OPimCache<T>::find(int uid )const { |
96 | Item *it = m_cache.find( uid ); | 102 | Item *it = m_cache.find( uid ); |