|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Version : %version: 3 % << Don't touch! Updated by Synergy at check-out. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "hnbitmapidcache.h" |
|
20 #include "hnglobals.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 TUint32 HBufC8HashCache( HBufC8* const & aBuf ) |
|
27 { |
|
28 return DefaultHash::Des8(*aBuf); |
|
29 } |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 TBool HBufC8IdentCache( HBufC8* const & aL, HBufC8* const & aR ) |
|
36 { |
|
37 return DefaultIdentity::Des8(*aL, *aR); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CHnBitmapIdCache::CHnBitmapIdCache() : iEntries( &HBufC8HashCache, |
|
45 &HBufC8IdentCache ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CHnBitmapIdCache::ConstructL() |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 TInt CHnBitmapIdCache::AddL( const TDesC8& aKey, TInt aValue ) |
|
64 { |
|
65 HBufC8* key = aKey.AllocL(); |
|
66 iEntries.InsertL( key, aValue ); |
|
67 return KErrNone; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 TBool CHnBitmapIdCache::ExistsL( const TDesC8& aKey ) |
|
75 { |
|
76 HBufC8* buf = aKey.AllocLC(); |
|
77 TInt* value = iEntries.Find( buf ); |
|
78 CleanupStack::PopAndDestroy( buf ); |
|
79 |
|
80 if ( value ) |
|
81 return ETrue; |
|
82 else |
|
83 return EFalse; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CHnBitmapIdCache::GetL( const TDesC8& aKey, TInt& value ) |
|
91 { |
|
92 HBufC8* buf = aKey.AllocLC(); |
|
93 const TInt* res = iEntries.Find( buf ); |
|
94 |
|
95 if ( res ) |
|
96 { |
|
97 value = *res; |
|
98 } |
|
99 |
|
100 CleanupStack::PopAndDestroy( buf ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 CHnBitmapIdCache* CHnBitmapIdCache::NewLC() |
|
108 { |
|
109 CHnBitmapIdCache* self = new (ELeave) CHnBitmapIdCache(); |
|
110 CleanupStack::PushL( self ); |
|
111 self->ConstructL(); |
|
112 return self; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CHnBitmapIdCache* CHnBitmapIdCache::NewL() |
|
120 { |
|
121 CHnBitmapIdCache* self = CHnBitmapIdCache::NewLC(); |
|
122 CleanupStack::Pop( self ); |
|
123 return self; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CHnBitmapIdCache::Reset() |
|
131 { |
|
132 THashMapIter<HBufC8*, TInt> iter( iEntries ); |
|
133 while ( HBufC8* const * ptr = iter.NextKey() ) |
|
134 { |
|
135 TInt* value = iter.CurrentValue(); |
|
136 delete *ptr; |
|
137 } |
|
138 iEntries.Close(); |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 CHnBitmapIdCache::~CHnBitmapIdCache() |
|
147 { |
|
148 Reset(); |
|
149 } |