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