|
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: Message store property collection. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __MSG_STORE_PROPERTY_CONTAINER_H__ |
|
21 #define __MSG_STORE_PROPERTY_CONTAINER_H__ |
|
22 |
|
23 #include <e32base.h> |
|
24 //<cmail> |
|
25 #include "MsgStoreTypes.h" |
|
26 #include "MsgStoreAddress.h" |
|
27 //</cmail> |
|
28 |
|
29 /** |
|
30 * Internal property value storage |
|
31 */ |
|
32 struct TMsgStoreProperty |
|
33 { |
|
34 RBuf8 iName; |
|
35 RBuf8 iValue; |
|
36 TPtrC16 iValue16; |
|
37 TMsgStorePropertyValueType iType; |
|
38 |
|
39 inline ~TMsgStoreProperty() {iName.Close(); iValue.Close();} |
|
40 |
|
41 }; // end TMsgStoreProperty |
|
42 |
|
43 /** This class defines a collection of name/value pairs. |
|
44 |
|
45 This class represents a collection of properties (i.e. name/value pairs) and provides functions |
|
46 to add/update/remove/find the properties. |
|
47 |
|
48 The maximum length for property names is 255 characters. Functions will leave with KErrUnderflow if |
|
49 a zero length property name is given, and will leave with KErrOverflow if the property name is too |
|
50 long. |
|
51 |
|
52 The maximum length for property values is 65535 bytes. Functions will leave with KErrOverflow if the |
|
53 property value is too long. |
|
54 */ |
|
55 class CMsgStorePropertyContainer : public CBase |
|
56 { |
|
57 public: |
|
58 |
|
59 /** Creates a property container. */ |
|
60 IMPORT_C static CMsgStorePropertyContainer* NewL(); |
|
61 |
|
62 virtual ~CMsgStorePropertyContainer(); |
|
63 |
|
64 /** Returns the ID of the container in storage (KMsgStoreInvalid if not yet stored). */ |
|
65 IMPORT_C TMsgStoreId Id() const; |
|
66 |
|
67 /** Returns the parent ID of the container in storage (KMsgStoreInvalid if not yet stored). */ |
|
68 IMPORT_C TMsgStoreId ParentId() const; |
|
69 |
|
70 /** Returns the total number of properties. */ |
|
71 IMPORT_C TUint PropertyCount() const; |
|
72 |
|
73 /** Returns the name of the given property. |
|
74 |
|
75 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
76 */ |
|
77 IMPORT_C const TDesC8& PropertyNameL( TUint aPropertyIndex ) const; |
|
78 |
|
79 /** Returns the type of value of the given property. |
|
80 |
|
81 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
82 */ |
|
83 IMPORT_C TMsgStorePropertyValueType PropertyTypeL( TUint aPropertyIndex ) const; |
|
84 |
|
85 /** Returns the value of the given property as a boolean. |
|
86 |
|
87 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
88 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
89 */ |
|
90 IMPORT_C TBool PropertyValueBoolL( TUint aPropertyIndex ) const; |
|
91 |
|
92 /** Returns the value of the given property as an 8-bit descriptor. |
|
93 |
|
94 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
95 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
96 */ |
|
97 IMPORT_C const TDesC8& PropertyValueDes8L( TUint aPropertyIndex ) const; |
|
98 |
|
99 /** Returns the value of the given property as a 16-bit descriptor. |
|
100 |
|
101 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
102 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
103 */ |
|
104 IMPORT_C const TDesC& PropertyValueDesL( TUint aPropertyIndex ) const; |
|
105 |
|
106 /** Returns the value of the given property as an integer. |
|
107 |
|
108 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
109 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
110 */ |
|
111 IMPORT_C TUint32 PropertyValueUint32L( TUint aPropertyIndex ) const; |
|
112 |
|
113 /** Returns the value of the given property as an TTime. |
|
114 |
|
115 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
116 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
117 */ |
|
118 IMPORT_C void PropertyValueTimeL( TUint aPropertyIndex, TTime& aTime ) const; |
|
119 |
|
120 /** Returns the value of the given property as an Address. |
|
121 |
|
122 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
123 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
124 */ |
|
125 IMPORT_C void PropertyValueAddressL( TUint aPropertyIndex, RMsgStoreAddress& aAddress ) const; |
|
126 |
|
127 /** Returns the value of the given property as an property container. |
|
128 |
|
129 The caller is responsible for deallocating the returned object. |
|
130 |
|
131 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
132 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
133 */ |
|
134 IMPORT_C CMsgStorePropertyContainer* PropertyValueContainerL( TUint aPropertyIndex ) const; |
|
135 |
|
136 /** Adds a boolean property. |
|
137 |
|
138 \retval Returns the index of the added property. |
|
139 */ |
|
140 IMPORT_C TUint AddPropertyL( const TDesC8& aName, TBool aValue ); |
|
141 |
|
142 /** Adds a integer property. |
|
143 |
|
144 \retval Returns the index of the added property. |
|
145 */ |
|
146 IMPORT_C TUint AddPropertyL( const TDesC8& aName, TUint32 aValue ); |
|
147 |
|
148 /** Adds an 8-bit descriptor property. |
|
149 |
|
150 \retval Returns the index of the added property. |
|
151 */ |
|
152 IMPORT_C TUint AddPropertyL( const TDesC8& aName, const TDesC8& aValue ); |
|
153 |
|
154 /** Adds a 16-bit descriptor property. |
|
155 |
|
156 \retval Returns the index of the added property. |
|
157 */ |
|
158 IMPORT_C TUint AddPropertyL( const TDesC8& aName, const TDesC& aValue ); |
|
159 |
|
160 /** Adds a TTime property. |
|
161 |
|
162 \retval Returns the index of the added property. |
|
163 */ |
|
164 IMPORT_C TUint AddPropertyL( const TDesC8& aName, const TTime& aValue ); |
|
165 |
|
166 /** Adds a Address property. |
|
167 |
|
168 \retval Returns the index of the added property. |
|
169 */ |
|
170 IMPORT_C TUint AddPropertyL( const TDesC8& aName, const RMsgStoreAddress& aValue ); |
|
171 |
|
172 /** Adds a container property. |
|
173 |
|
174 \retval Returns the index of the added property. |
|
175 */ |
|
176 IMPORT_C TUint AddPropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer ); |
|
177 |
|
178 /** Updates an 8-bit descriptor property. |
|
179 |
|
180 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
181 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
182 */ |
|
183 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, const TDesC8& aValue ); |
|
184 |
|
185 /** Updates a 16-bit descriptor property. |
|
186 |
|
187 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
188 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
189 */ |
|
190 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, const TDesC& aValue ); |
|
191 |
|
192 /** Updates a integer property. |
|
193 |
|
194 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
195 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
196 */ |
|
197 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, TUint32 aValue ); |
|
198 |
|
199 /** Updates a boolean property. |
|
200 |
|
201 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
202 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
203 */ |
|
204 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, TBool aValue ); |
|
205 |
|
206 /** Updates a TTime property. |
|
207 |
|
208 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
209 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
210 */ |
|
211 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, const TTime& aValue ); |
|
212 |
|
213 /** Updates a Address property. |
|
214 |
|
215 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
216 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
217 */ |
|
218 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, const RMsgStoreAddress& aValue ); |
|
219 |
|
220 /** Updates a container property. |
|
221 |
|
222 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
223 \note: This function will leave with KErrArgument if the property value type doesn't match. |
|
224 */ |
|
225 IMPORT_C void UpdatePropertyL( TUint aPropertyIndex, const CMsgStorePropertyContainer& aContainer ); |
|
226 |
|
227 /** Adds or updates a boolean property. |
|
228 |
|
229 If a property with the given name already exists then the first instance of the property will |
|
230 be updated. If not, the property will be added. |
|
231 |
|
232 \note: This function will leave with KErrArgument if the property already exists and the |
|
233 value type doesn't match. |
|
234 |
|
235 \retval Returns the index of the added or updated property. |
|
236 */ |
|
237 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, TBool aValue ); |
|
238 |
|
239 /** Adds or updates a integer property. |
|
240 |
|
241 If a property with the given name already exists then the first instance of the property will |
|
242 be updated. If not, the property will be added. |
|
243 |
|
244 \note: This function will leave with KErrArgument if the property already exists and the |
|
245 value type doesn't match. |
|
246 |
|
247 \retval Returns the index of the added or updated property. |
|
248 */ |
|
249 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, TUint32 aValue ); |
|
250 |
|
251 /** Adds or updates an 8-bit descriptor property. |
|
252 |
|
253 If a property with the given name already exists then the first instance of the property will |
|
254 be updated. If not, the property will be added. |
|
255 |
|
256 \note: This function will leave with KErrArgument if the property already exists and the |
|
257 value type doesn't match. |
|
258 |
|
259 \retval Returns the index of the added or updated property. |
|
260 */ |
|
261 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, const TDesC8& aValue ); |
|
262 |
|
263 /** Adds or updates a 16-bit descriptor property. |
|
264 |
|
265 If a property with the given name already exists then the first instance of the property will |
|
266 be updated. If not, the property will be added. |
|
267 |
|
268 \note: This function will leave with KErrArgument if the property already exists and the |
|
269 value type doesn't match. |
|
270 |
|
271 \retval Returns the index of the added or updated property. |
|
272 */ |
|
273 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, const TDesC& aValue ); |
|
274 |
|
275 /** Adds or updates a TTime property. |
|
276 |
|
277 If a property with the given name already exists then the first instance of the property will |
|
278 be updated. If not, the property will be added. |
|
279 |
|
280 \note: This function will leave with KErrArgument if the property already exists and the |
|
281 value type doesn't match. |
|
282 |
|
283 \retval Returns the index of the added or updated property. |
|
284 */ |
|
285 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, const TTime& aValue ); |
|
286 |
|
287 /** Adds or updates an Address property. |
|
288 |
|
289 If a property with the given name already exists then the first instance of the property will |
|
290 be updated. If not, the property will be added. |
|
291 |
|
292 \note: This function will leave with KErrArgument if the property already exists and the |
|
293 value type doesn't match. |
|
294 |
|
295 \retval Returns the index of the added or updated property. |
|
296 */ |
|
297 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, const RMsgStoreAddress& aValue ); |
|
298 |
|
299 /** Adds or updates a container property. |
|
300 |
|
301 If a property with the given name already exists then the first instance of the property will |
|
302 be updated. If not, the property will be added. |
|
303 |
|
304 \note: This function will leave with KErrArgument if the property already exists and the |
|
305 value type doesn't match. |
|
306 |
|
307 \retval Returns the index of the added or updated property. |
|
308 */ |
|
309 IMPORT_C TUint AddOrUpdatePropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer ); |
|
310 |
|
311 /** Removes a property. |
|
312 |
|
313 \note: This function will leave with KErrNotFound if an invalid property index is provided. |
|
314 */ |
|
315 IMPORT_C void RemovePropertyL( TUint aPropertyIndex ); |
|
316 |
|
317 /** Finds a property based on name, starting at the given index. |
|
318 |
|
319 \retval Returns ETrue if the property was found, EFalse otherwise. |
|
320 */ |
|
321 IMPORT_C TBool FindProperty( const TDesC8& aName, TUint& aFoundIndex, TUint aStartIndex = 0 ) const; |
|
322 |
|
323 // --------------------------- |
|
324 // INTERNAL USE (NOT EXPORTED) |
|
325 // --------------------------- |
|
326 |
|
327 void SerializeL( RBuf8& aBuffer ) const; |
|
328 |
|
329 void DeserializeL( const TDesC8& aBuf ); |
|
330 |
|
331 void SetIds( TMsgStoreId aId, TMsgStoreId aParentId ); |
|
332 |
|
333 protected: |
|
334 |
|
335 CMsgStorePropertyContainer(); |
|
336 |
|
337 void ValidateIndexL( TUint aIndex ) const; |
|
338 |
|
339 TMsgStoreId iId; |
|
340 TMsgStoreId iParentId; |
|
341 RPointerArray<TMsgStoreProperty> iProperties; |
|
342 |
|
343 private: |
|
344 TUint AddPropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer, TMsgStorePropertyValueType aType ); |
|
345 void UpdatePropertyL( TUint aPropertyIndex, const CMsgStorePropertyContainer& aContainer, TMsgStorePropertyValueType aType ); |
|
346 CMsgStorePropertyContainer* CMsgStorePropertyContainer::PropertyValueContainerL( TUint aPropertyIndex, TMsgStorePropertyValueType aType ) const; |
|
347 |
|
348 void ValidateIndexAndTypeL( TUint aIndex, TMsgStorePropertyValueType aType ) const; |
|
349 void ValidateLengthsL( TUint aNameLength, TUint aValueLength ) const; |
|
350 void ValidateValueLengthL( TUint aValueLength ) const; |
|
351 |
|
352 TUint DoAddPropertyL( TMsgStorePropertyValueType aType, const TDesC8& aName, const TDesC8& aValue ); |
|
353 void DoUpdatePropertyL( TUint aPropertyIndex, TMsgStorePropertyValueType aType, const TDesC8& aValue ); |
|
354 |
|
355 }; // end class CMsgStorePropertyContainer |
|
356 |
|
357 |
|
358 #endif //__MSG_STORE_PROPERTY_CONTAINER_H__ |