summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimcache.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimcache.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimcache.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h
index 7f7cff5..e70a910 100644
--- a/libopie2/opiepim/core/opimcache.h
+++ b/libopie2/opiepim/core/opimcache.h
@@ -1,31 +1,60 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
1#ifndef OPIE_PIM_CACHE_H 29#ifndef OPIE_PIM_CACHE_H
2#define OPIE_PIM_CACHE_H 30#define OPIE_PIM_CACHE_H
3 31
4#include <qintcache.h> 32#include <qintcache.h>
5 33
6#include "opimrecord.h" 34#include <opie2/opimrecord.h>
7 35
36namespace Opie {
8class OPimCacheItemPrivate; 37class OPimCacheItemPrivate;
9 38
10template <class T = OPimRecord> 39template <class T = OPimRecord>
11class OPimCacheItem { 40class OPimCacheItem {
12public: 41public:
13 OPimCacheItem( const T& t = T() ); 42 OPimCacheItem( const T& t = T() );
14 OPimCacheItem( const OPimCacheItem& ); 43 OPimCacheItem( const OPimCacheItem& );
15 ~OPimCacheItem(); 44 ~OPimCacheItem();
16 45
17 OPimCacheItem &operator=( const OPimCacheItem& ); 46 OPimCacheItem &operator=( const OPimCacheItem& );
18 47
19 T record()const; 48 T record()const;
20 void setRecord( const T& ); 49 void setRecord( const T& );
21private: 50private:
22 T m_t; 51 T m_t;
23 OPimCacheItemPrivate *d; 52 OPimCacheItemPrivate *d;
24}; 53};
25 54
26 55
27class OPimCachePrivate; 56class OPimCachePrivate;
28/** 57/**
29 * OPimCache for caching the items 58 * OPimCache for caching the items
30 * We support adding, removing 59 * We support adding, removing
31 * and finding 60 * and finding
@@ -107,25 +136,27 @@ T OPimCache<T>::find(int uid )const {
107template <class T> 136template <class T>
108void OPimCache<T>::add( const T& t ) { 137void OPimCache<T>::add( const T& t ) {
109 Item* it = 0l; 138 Item* it = 0l;
110 it = m_cache.find(t.uid(), FALSE ); 139 it = m_cache.find(t.uid(), FALSE );
111 140
112 if (it ) 141 if (it )
113 it->setRecord( t ); 142 it->setRecord( t );
114 143
115 it = new Item( t ); 144 it = new Item( t );
116 if (!m_cache.insert( t.uid(), it ) ) 145 if (!m_cache.insert( t.uid(), it ) )
117 delete it; 146 delete it;
118} 147}
119template <class T> 148template <class T>
120void OPimCache<T>::remove( int uid ) { 149void OPimCache<T>::remove( int uid ) {
121 m_cache.remove( uid ); 150 m_cache.remove( uid );
122} 151}
123template <class T> 152template <class T>
124void OPimCache<T>::replace( const T& t) { 153void OPimCache<T>::replace( const T& t) {
125 Item *it = m_cache.find( t.uid() ); 154 Item *it = m_cache.find( t.uid() );
126 if ( it ) { 155 if ( it ) {
127 it->setRecord( t ); 156 it->setRecord( t );
128 } 157 }
129} 158}
130 159
160}
161
131#endif 162#endif