|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Implementation of GECODefaultObject |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "gecodefaultobject.h" |
|
21 #include "xcfwpanic.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CGECODefaultObject::CGECODefaultObject |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 EXPORT_C CGECODefaultObject::CGECODefaultObject() |
|
32 { |
|
33 } |
|
34 |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CGECODefaultObject::NewL |
|
38 // Two phased constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CGECODefaultObject* CGECODefaultObject::NewL( |
|
42 const TDesC& aTypeIdentifier ) |
|
43 { |
|
44 CGECODefaultObject* self = new( ELeave ) CGECODefaultObject() ; |
|
45 |
|
46 CleanupStack::PushL( self ); |
|
47 self->BaseConstructL( aTypeIdentifier ); |
|
48 CleanupStack::Pop( self ); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CGECODefaultObject::BaseConstructL |
|
55 // Initializes default object data arrays and type identifier. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void CGECODefaultObject::BaseConstructL( const TDesC& aTypeIdentifier ) |
|
59 { |
|
60 const TInt KDefaultGranularity = 3; |
|
61 iTypeIdentifier = aTypeIdentifier.AllocL(); |
|
62 iAttrNames = new ( ELeave ) CDesCArraySeg( KDefaultGranularity ); |
|
63 iAttrValues = new ( ELeave ) CDesCArraySeg( KDefaultGranularity ); |
|
64 } |
|
65 |
|
66 |
|
67 // Destructor |
|
68 EXPORT_C CGECODefaultObject::~CGECODefaultObject() |
|
69 { |
|
70 delete iTypeIdentifier; |
|
71 delete iAttrNames; |
|
72 delete iAttrValues; |
|
73 delete iText; |
|
74 iAttrLocStatus.Close(); |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CGECODefaultObject::Identifier |
|
80 // return object TypeIdentifier |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C const TDesC& CGECODefaultObject::TypeIdentifier() |
|
84 { |
|
85 |
|
86 __ASSERT_PANIC_DEBUG( iTypeIdentifier, |
|
87 EXCFWPanicNoTypeIdentifier ); |
|
88 |
|
89 return *iTypeIdentifier; |
|
90 |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CGECODefaultObject::GetAttribute |
|
96 // Returns attribute value for given attrib. name |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C TInt CGECODefaultObject::GetAttribute( |
|
100 const TDesC& aAttrName, |
|
101 TPtrC& aAttrValue ) |
|
102 { |
|
103 |
|
104 TInt error = KErrNotFound; |
|
105 const TInt count = iAttrNames->Count(); |
|
106 |
|
107 for ( TInt i = 0; i < count; i++ ) |
|
108 { |
|
109 if ( iAttrNames->MdcaPoint( i ) == aAttrName ) |
|
110 { |
|
111 error = KErrNone; |
|
112 aAttrValue.Set( iAttrValues->MdcaPoint( i ) ); |
|
113 } |
|
114 } |
|
115 |
|
116 return error; |
|
117 |
|
118 |
|
119 } |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CGECODefaultObject::GetAttribute |
|
122 // Returns attribute value and localization status for given attrib. name |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C TInt CGECODefaultObject::GetAttribute( |
|
126 const TDesC& aAttrName, |
|
127 TPtrC& aAttrValue, |
|
128 TBool& aIsLocalized) |
|
129 { |
|
130 |
|
131 TInt error = KErrNotFound; |
|
132 const TInt count = iAttrNames->Count(); |
|
133 |
|
134 for ( TInt i = 0; i < count; i++ ) |
|
135 { |
|
136 if ( iAttrNames->MdcaPoint( i ) == aAttrName ) |
|
137 { |
|
138 error = KErrNone; |
|
139 aAttrValue.Set( iAttrValues->MdcaPoint( i ) ); |
|
140 aIsLocalized = iAttrLocStatus[i]; |
|
141 } |
|
142 } |
|
143 |
|
144 return error; |
|
145 |
|
146 |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CGECODefaultObject::SetAttributeL |
|
151 // This function adds new attribute with Localization status EFalse |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C void CGECODefaultObject::SetAttributeL( |
|
155 const TDesC& aAttrName, |
|
156 const TDesC& aAttrValue ) |
|
157 { |
|
158 SetAttributeL( aAttrName, aAttrValue, EFalse ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CGECODefaultObject::SetAttributeL |
|
163 // New attribute is added to object data arrays. Value and localization status |
|
164 // addition is TRAPped to make sure that all arrays have identical item count |
|
165 // at all times. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CGECODefaultObject::SetAttributeL( |
|
169 const TDesC& aAttrName, |
|
170 const TDesC& aAttrValue, |
|
171 TBool aIsLocalized ) |
|
172 { |
|
173 |
|
174 iAttrNames->AppendL( aAttrName ); |
|
175 TInt err = KErrNone; |
|
176 |
|
177 TRAP( err, iAttrValues->AppendL( aAttrValue ) ); |
|
178 if ( err != KErrNone ) |
|
179 { |
|
180 //if attribute value addition failed, remove name and leave |
|
181 TInt lastindex = iAttrNames->Count() - 1; |
|
182 iAttrNames->Delete( lastindex ); |
|
183 User::Leave( err ); |
|
184 } |
|
185 else |
|
186 { |
|
187 TRAP( err, iAttrLocStatus.AppendL( aIsLocalized ) ); |
|
188 if ( err != KErrNone ) |
|
189 { |
|
190 //if loc status addition failed, remove name and leave |
|
191 TInt lastindex = iAttrNames->Count() - 1; |
|
192 iAttrNames->Delete( lastindex ); |
|
193 iAttrValues->Delete( lastindex ); |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CGECODefaultObject::TextDetails |
|
201 // Returns objects text data if any |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C void CGECODefaultObject::TextDetailsL( |
|
205 TPtrC& aText, |
|
206 TBool& aIsLocalized ) |
|
207 { |
|
208 if ( iText ) |
|
209 { |
|
210 aText.Set( iText->Des() ); |
|
211 aIsLocalized = iTextLocStatus; |
|
212 } |
|
213 else |
|
214 { |
|
215 User::Leave( KErrNotFound ); |
|
216 } |
|
217 } |
|
218 |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CGECODefaultObject::NumAttributes |
|
222 // Returns number of attributes from internal array |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C TInt CGECODefaultObject::NumAttributes() |
|
226 { |
|
227 return iAttrNames->Count(); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CGECODefaultObject::AttributeDetailsL |
|
232 // Returns details of the attribute in given index (MGECOAttributeProvider IF) |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C void CGECODefaultObject::AttributeDetailsL( |
|
236 const TInt aIndex, |
|
237 TPtrC& aAttrName, |
|
238 TPtrC& aAttrValue, |
|
239 TBool& aIsLocalized) |
|
240 { |
|
241 |
|
242 if ( aIndex >= 0 && iAttrNames->Count() > aIndex ) |
|
243 { |
|
244 aAttrName.Set( iAttrNames->MdcaPoint( aIndex ) ); |
|
245 aAttrValue.Set( iAttrValues->MdcaPoint( aIndex ) ); |
|
246 aIsLocalized = iAttrLocStatus[aIndex]; |
|
247 } |
|
248 else |
|
249 { |
|
250 User::Leave( KErrNotFound ); |
|
251 } |
|
252 |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CGECODefaultObject::AttributeDetailsL |
|
257 // Returns details of the attribute in given index (MGECOAttributeProvider IF) |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CGECODefaultObject::AttributeDetailsL( |
|
261 const TInt aIndex, |
|
262 TPtrC& aAttrName, |
|
263 TPtrC& aAttrValue) |
|
264 { |
|
265 |
|
266 if ( aIndex >= 0 && iAttrNames->Count() > aIndex ) |
|
267 { |
|
268 aAttrName.Set( iAttrNames->MdcaPoint( aIndex ) ); |
|
269 aAttrValue.Set( iAttrValues->MdcaPoint( aIndex ) ); |
|
270 } |
|
271 else |
|
272 { |
|
273 User::Leave( KErrNotFound ); |
|
274 } |
|
275 |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CGECODefaultObject::RemoveAttribute |
|
280 // Removes an attribute from the internal attribute name array. |
|
281 // Value + localization status from same position are deleted as well. |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C TInt CGECODefaultObject::RemoveAttribute( |
|
285 const TDesC& aAttrName ) |
|
286 { |
|
287 |
|
288 TInt error = KErrNotFound; |
|
289 |
|
290 const TInt index = iAttrNames->Count() - 1; |
|
291 |
|
292 for ( TInt i = index; i >= 0; i-- ) |
|
293 |
|
294 { |
|
295 if ( iAttrNames->MdcaPoint( i ) == aAttrName ) |
|
296 { |
|
297 error = KErrNone; |
|
298 iAttrNames->Delete( i ); |
|
299 iAttrValues->Delete( i ); |
|
300 iAttrLocStatus.Remove( i ); |
|
301 } |
|
302 } |
|
303 |
|
304 return error; |
|
305 } |
|
306 |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CGECODefaultObject::SetText |
|
310 // Sets the object's text data |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 EXPORT_C void CGECODefaultObject::SetTextL( |
|
314 const TDesC& aText ) |
|
315 { |
|
316 SetTextL( aText, EFalse ); |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CGECODefaultObject::SetText |
|
321 // Sets the object's text data and corresponding localization status |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C void CGECODefaultObject::SetTextL( |
|
325 const TDesC& aText, |
|
326 TBool aIsLocalized ) |
|
327 { |
|
328 delete iText; |
|
329 iText = NULL; |
|
330 iText = aText.AllocL(); |
|
331 iTextLocStatus = aIsLocalized; |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CGECODefaultObject::HasTextData |
|
336 // Returns ETrue if object has text data |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 EXPORT_C TBool CGECODefaultObject::HasTextData() |
|
340 { |
|
341 TBool ret = EFalse; |
|
342 if ( iText ) |
|
343 { |
|
344 ret = ETrue; |
|
345 } |
|
346 return ret; |
|
347 } |
|
348 |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CGECODefaultObject::GetText |
|
352 // Returns the text data for this object |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 EXPORT_C TInt CGECODefaultObject::GetText( TPtrC& aText ) |
|
356 { |
|
357 TInt ret = KErrNotFound; |
|
358 if ( iText ) |
|
359 { |
|
360 ret = KErrNone; |
|
361 aText.Set( *iText ); |
|
362 } |
|
363 return ret; |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CGECODefaultObject::RemoveText |
|
368 // Removes possible text data from the object |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 EXPORT_C void CGECODefaultObject::RemoveText() |
|
372 { |
|
373 delete iText; |
|
374 iText = NULL; |
|
375 iTextLocStatus = EFalse; |
|
376 } |
|
377 |
|
378 // End of File |