|
1 /* |
|
2 * Copyright (c) 2006 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: CNcdKeyValueMap declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_NCDKEYVALUEMAP_H |
|
20 #define C_NCDKEYVALUEMAP_H |
|
21 |
|
22 #include "e32base.h" |
|
23 |
|
24 class RWriteStream; |
|
25 class RReadStream; |
|
26 class CNcdKeyValuePair; |
|
27 |
|
28 /** |
|
29 * Map implementation |
|
30 */ |
|
31 class CNcdKeyValueMap : public CBase |
|
32 { |
|
33 public: |
|
34 |
|
35 typedef TInt KeyValueIndex; |
|
36 |
|
37 public: |
|
38 |
|
39 /** |
|
40 * Creator |
|
41 */ |
|
42 static CNcdKeyValueMap* NewL(); |
|
43 |
|
44 /** |
|
45 * Creator |
|
46 */ |
|
47 static CNcdKeyValueMap* NewLC(); |
|
48 |
|
49 |
|
50 /** |
|
51 * Copy constructor |
|
52 */ |
|
53 static CNcdKeyValueMap* NewL( const CNcdKeyValueMap& aOther ); |
|
54 |
|
55 /** |
|
56 * Cloner |
|
57 */ |
|
58 CNcdKeyValueMap* CloneL() const; |
|
59 |
|
60 /** |
|
61 * Destructor |
|
62 */ |
|
63 ~CNcdKeyValueMap(); |
|
64 |
|
65 public: |
|
66 |
|
67 /** |
|
68 * Adds a key-value pair |
|
69 * |
|
70 * @note Always adds a new pair even if the key already exists. |
|
71 * ValueByKey and KeyExists -methods return the oldest instance of the key |
|
72 * |
|
73 * @param aKey Key name |
|
74 * @param aValue Data |
|
75 */ |
|
76 void AddL( const TDesC& aKey, const TDesC& aValue ); |
|
77 |
|
78 |
|
79 /** |
|
80 * Adds a key-value pair. |
|
81 * |
|
82 * @note Always adds a new pair even if the key already exists. |
|
83 * ValueByKey and KeyExists -methods return the oldest instance of the key |
|
84 * |
|
85 * @param aPair Pair to add. The ownership of the pair is transferred |
|
86 * to the CNcdKeyValueMap if the operation is successful. |
|
87 * @note If a leave occurs, it is the responsibility of the caller to |
|
88 * delete the pair. |
|
89 */ |
|
90 void AddL( CNcdKeyValuePair* aPair ); |
|
91 |
|
92 |
|
93 |
|
94 /** |
|
95 * Adds a new or replaces an old key-value pair. |
|
96 * |
|
97 * If the key already exists, the old value is replaced with the new one |
|
98 * |
|
99 * @param aPair Pair to add. The ownership of the pair is transferred |
|
100 * to the CNcdKeyValueMap if the operation is successful. |
|
101 * @note If a leave occurs, it is the responsibility of the caller to |
|
102 * delete the pair. |
|
103 */ |
|
104 void ReplaceL( CNcdKeyValuePair* aPair ); |
|
105 |
|
106 |
|
107 /** |
|
108 * Removes key-value pair. |
|
109 * |
|
110 * @note If the key exists more than once, then the oldest |
|
111 * instance is removed. |
|
112 * |
|
113 * @param aKey Key |
|
114 * @return KErrNotFound if the pair was not found |
|
115 */ |
|
116 TInt Remove( const TDesC& aKey ); |
|
117 |
|
118 |
|
119 /** |
|
120 * Returns an array of all key-value pairs |
|
121 * |
|
122 * @return Array of headers |
|
123 */ |
|
124 RPointerArray<CNcdKeyValuePair>& Pairs(); |
|
125 |
|
126 |
|
127 /** |
|
128 * Returns an array of all key-value pairs |
|
129 * |
|
130 * @return Array of headers |
|
131 */ |
|
132 const RPointerArray<CNcdKeyValuePair>& Pairs() const; |
|
133 |
|
134 |
|
135 /** |
|
136 * Searches for the value that matches the key |
|
137 * |
|
138 * @param aPair Wanted key |
|
139 * @return Header |
|
140 * @exception KErrNotFound if a matching value was not found |
|
141 */ |
|
142 const TDesC& ValueByKeyL( const TDesC& aKey ) const; |
|
143 |
|
144 |
|
145 KeyValueIndex KeyExists( const TDesC& aKey ) const; |
|
146 |
|
147 const TDesC& ValueByIndex( const KeyValueIndex& aIndex ) const; |
|
148 |
|
149 |
|
150 KeyValueIndex PairExists( const CNcdKeyValuePair& aPair ) const; |
|
151 |
|
152 |
|
153 /** |
|
154 * Deletes all key-value pairs |
|
155 */ |
|
156 void ResetAndDestroy(); |
|
157 |
|
158 |
|
159 /** |
|
160 * Resets the array but doesn't delete the pairs |
|
161 */ |
|
162 void Reset(); |
|
163 |
|
164 |
|
165 /** |
|
166 * Appends a map. |
|
167 * |
|
168 * Simply appends key-value -pairs from the given map to this |
|
169 * map. No key collision checks are made. |
|
170 * |
|
171 * @param aMap Map |
|
172 */ |
|
173 void AppendL( const CNcdKeyValueMap& aMap ); |
|
174 |
|
175 |
|
176 /** |
|
177 * Externalizes the map |
|
178 * |
|
179 * @param aStream Target stream |
|
180 */ |
|
181 void ExternalizeL( RWriteStream& aStream ) const; |
|
182 |
|
183 /** |
|
184 * Externalizes the map to a RBuf8 |
|
185 * |
|
186 * @param aTarge Target buffer. |
|
187 */ |
|
188 void ExternalizeL( RBuf8& aTarget ) const; |
|
189 |
|
190 /** |
|
191 * Internalizes the map |
|
192 * |
|
193 * @param aStream Source stream |
|
194 */ |
|
195 void InternalizeL( RReadStream& aStream ); |
|
196 |
|
197 |
|
198 private: |
|
199 |
|
200 /** |
|
201 * Constructor |
|
202 */ |
|
203 CNcdKeyValueMap(); |
|
204 |
|
205 /** |
|
206 * Copy constructor |
|
207 */ |
|
208 CNcdKeyValueMap( const CNcdKeyValueMap& aOther ); |
|
209 |
|
210 /** |
|
211 * 2nd phase copy constructor |
|
212 */ |
|
213 void ConstructL( const CNcdKeyValueMap& aOther ); |
|
214 |
|
215 private: |
|
216 |
|
217 /** |
|
218 * Searches for the pair that matches the key in the given |
|
219 * pair |
|
220 * |
|
221 * @param aPair Key-value pair that has the wanted key set |
|
222 * @return A value |
|
223 * @note aPair is popped from the Cleanupstack and deleted |
|
224 * @exception KErrNotFound if a matching header was not found |
|
225 */ |
|
226 const TDesC& FindValueL( CNcdKeyValuePair* aPair ) const; |
|
227 |
|
228 |
|
229 private: |
|
230 |
|
231 RPointerArray<CNcdKeyValuePair> iPairs; |
|
232 |
|
233 }; |
|
234 |
|
235 #endif // C_NCDKEYVALUEMAP_H |