|
1 /* |
|
2 * Copyright (c) 2005,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: List class to hold CXnDomList objects. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "xndomlist.h" |
|
22 #include "xndomnode.h" |
|
23 #include "xndomattribute.h" |
|
24 #include "xndomproperty.h" |
|
25 #include "xndompropertyvalue.h" |
|
26 #include "xndomstringpool.h" |
|
27 |
|
28 |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CXnDomList::CXnDomList |
|
34 // C++ parameter constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CXnDomList::CXnDomList( |
|
39 TListType aListType, |
|
40 CXnDomStringPool& aStringPool, |
|
41 TInt aGranularity ): |
|
42 iListType( aListType ), |
|
43 iList( aGranularity ), |
|
44 iStringPool( aStringPool ) |
|
45 { |
|
46 } |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CXnDomList::ConstructL |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CXnDomList::ConstructL() |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CXnDomList::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CXnDomList* CXnDomList::NewL( |
|
63 TListType aListType, |
|
64 CXnDomStringPool& aStringPool, |
|
65 TInt aGranularity) |
|
66 { |
|
67 CXnDomList* self = |
|
68 new( ELeave ) CXnDomList( aListType, aStringPool,aGranularity ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 |
|
74 return self; |
|
75 } |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CXnDomList::NewL |
|
78 // Two-phased stream constructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CXnDomList* CXnDomList::NewL( |
|
82 RReadStream& aStream, |
|
83 CXnDomStringPool& aStringPool ) |
|
84 { |
|
85 CXnDomList* self = new( ELeave ) CXnDomList( ENodeList, aStringPool ); |
|
86 |
|
87 CleanupStack::PushL( self ); |
|
88 |
|
89 aStream >> *self; |
|
90 CleanupStack::Pop( self ); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 // Destructor |
|
96 CXnDomList::~CXnDomList() |
|
97 { |
|
98 iList.ResetAndDestroy(); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CXnDomList::Reset |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C void CXnDomList::Reset() |
|
106 { |
|
107 iList.Reset(); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CXnDomList::AddItemL |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CXnDomList::AddItemL( MXnDomListItem* aItem ) |
|
115 { |
|
116 iList.AppendL( aItem ); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CXnDomList::AddItemL |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C void CXnDomList::AddItemL( MXnDomListItem* aItem, TInt aIndex ) |
|
124 { |
|
125 iList.InsertL( aItem, aIndex ); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CXnDomList::RemoveItem |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CXnDomList::RemoveItem( TInt aIndex ) |
|
133 { |
|
134 iList.Remove( aIndex); |
|
135 iList.Compress(); |
|
136 } |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CXnDomList::DeleteItem |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C void CXnDomList::DeleteItem( TInt aIndex ) |
|
142 { |
|
143 delete iList[ aIndex ]; |
|
144 iList.Remove( aIndex); |
|
145 iList.Compress(); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CXnDomList::RemoveItem |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C void CXnDomList::RemoveItem( MXnDomListItem* aItem ) |
|
153 { |
|
154 MXnDomListItem* tmp = NULL; |
|
155 TInt count( iList.Count() ); |
|
156 TBool stop( EFalse ); |
|
157 for ( TInt i=0; i<count && !stop; i++ ) |
|
158 { |
|
159 tmp = iList[i]; |
|
160 if ( tmp == aItem ) |
|
161 { |
|
162 iList.Remove( i ); |
|
163 iList.Compress(); |
|
164 stop = ETrue; |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CXnDomList::DeleteItem |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C void CXnDomList::DeleteItem( MXnDomListItem* aItem ) |
|
174 { |
|
175 MXnDomListItem* tmp = NULL; |
|
176 TInt count( iList.Count() ); |
|
177 TBool stop( EFalse ); |
|
178 for ( TInt i=0; i<count && !stop ; i++ ) |
|
179 { |
|
180 tmp = iList[i]; |
|
181 if ( tmp == aItem ) |
|
182 { |
|
183 delete iList[i]; |
|
184 iList.Remove( i ); |
|
185 iList.Compress(); |
|
186 stop = ETrue; |
|
187 } |
|
188 } |
|
189 } |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CXnDomList::Item |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C MXnDomListItem* CXnDomList::Item( TInt aIndex )const |
|
195 { |
|
196 |
|
197 return iList[ aIndex ]; |
|
198 } |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CXnDomList::Length |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 EXPORT_C TInt CXnDomList::Length() const |
|
204 { |
|
205 |
|
206 return iList.Count(); |
|
207 } |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CXnDomList::First |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C MXnDomListItem* CXnDomList::First() |
|
213 { |
|
214 if ( iList.Count() ) |
|
215 { |
|
216 return iList[ 0 ]; |
|
217 } |
|
218 else |
|
219 { |
|
220 return NULL; |
|
221 } |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CXnDomList::Last |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 EXPORT_C MXnDomListItem* CXnDomList::Last() |
|
229 { |
|
230 TInt count( iList.Count() ); |
|
231 if ( count ) |
|
232 { |
|
233 return iList[ count-1 ]; |
|
234 } |
|
235 else |
|
236 { |
|
237 return NULL; |
|
238 } |
|
239 |
|
240 } |
|
241 |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CXnDomList::FindByName |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C MXnDomListItem* CXnDomList::FindByName( const TDesC8& aName ) |
|
248 { |
|
249 |
|
250 if ( iListType == CXnDomList::EPropertyValueList ) |
|
251 { |
|
252 return NULL; |
|
253 } |
|
254 |
|
255 MXnDomListItem* tmp = NULL; |
|
256 TInt count( iList.Count() ); |
|
257 for ( TInt i=0; i<count; i++ ) |
|
258 { |
|
259 tmp = iList[ i ]; |
|
260 |
|
261 if ( aName.Compare( tmp->Name() ) == 0 ) |
|
262 { |
|
263 return tmp; |
|
264 } |
|
265 } |
|
266 return NULL; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CXnDomList::ItemIndex |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 EXPORT_C TInt CXnDomList::ItemIndex( const MXnDomListItem& aItem ) const |
|
274 { |
|
275 |
|
276 MXnDomListItem* tmp = NULL; |
|
277 TInt count( iList.Count() ); |
|
278 for ( TInt i=0; i<count; i++ ) |
|
279 { |
|
280 tmp = iList[ i ]; |
|
281 if ( tmp == &aItem ) |
|
282 { |
|
283 return i; |
|
284 } |
|
285 } |
|
286 return KErrNotFound; |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CXnDomList::StringPool |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 EXPORT_C CXnDomStringPool& CXnDomList::StringPool() const |
|
294 { |
|
295 return iStringPool; |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CXnDomList::Size |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 TInt CXnDomList::Size() const |
|
303 { |
|
304 TInt size = 0; |
|
305 |
|
306 size += sizeof(TInt8); //Type |
|
307 size += sizeof(TInt32); //Item count |
|
308 |
|
309 TInt count( iList.Count() ); |
|
310 for ( TInt i=0; i<count; i++ ) |
|
311 { |
|
312 size += iList[ i ]->Size(); |
|
313 } |
|
314 return size; |
|
315 } |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CXnDomList::ExternalizeL |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void CXnDomList::ExternalizeL( RWriteStream& aStream ) const |
|
321 { |
|
322 aStream.WriteInt8L( iListType ); |
|
323 |
|
324 |
|
325 TInt count( iList.Count() ); |
|
326 aStream.WriteInt32L( count ); |
|
327 |
|
328 |
|
329 for ( TInt i=0; i<count; i++ ) |
|
330 { |
|
331 aStream << *iList[ i ]; |
|
332 } |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CXnDomList::InternalizeL |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 void CXnDomList::InternalizeL( RReadStream& aStream ) |
|
340 { |
|
341 iListType = static_cast<CXnDomList::TListType>( aStream.ReadInt8L() ); |
|
342 |
|
343 TInt count ( aStream.ReadInt32L() ); |
|
344 for ( TInt i=0; i<count; i++ ) |
|
345 { |
|
346 MXnDomListItem* item = NULL; |
|
347 |
|
348 switch( iListType ) |
|
349 { |
|
350 case CXnDomList::ENodeList: |
|
351 { |
|
352 item = CXnDomNode::NewL( aStream, iStringPool ); |
|
353 } |
|
354 break; |
|
355 |
|
356 case CXnDomList::EAttributeList: |
|
357 { |
|
358 item = CXnDomAttribute::NewL( aStream, iStringPool ); |
|
359 } |
|
360 break; |
|
361 case CXnDomList::EPropertyList: |
|
362 { |
|
363 item = CXnDomProperty::NewL( aStream, iStringPool ); |
|
364 } |
|
365 break; |
|
366 case CXnDomList::EPropertyValueList: |
|
367 { |
|
368 item = CXnDomPropertyValue::NewL( aStream, iStringPool ); |
|
369 } |
|
370 break; |
|
371 |
|
372 default: |
|
373 User::Leave(KErrArgument); |
|
374 break; |
|
375 } |
|
376 CleanupDeletePushL( item ); |
|
377 iList.AppendL( item ); |
|
378 CleanupStack::Pop( item ); |
|
379 } |
|
380 } |
|
381 |
|
382 |
|
383 |
|
384 // End of File |