1 cnode.inl |
1 /// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 /// All rights reserved. |
|
3 /// This component and the accompanying materials are made available |
|
4 /// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 /// which accompanies this distribution, and is available |
|
6 /// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 /// |
|
8 /// Initial Contributors: |
|
9 /// Nokia Corporation - initial contribution. |
|
10 /// |
|
11 /// Contributors: |
|
12 /// |
|
13 /// Description: |
|
14 /// All rights reserved. |
|
15 /// This component and the accompanying materials are made available |
|
16 /// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
17 /// which accompanies this distribution, and is available |
|
18 /// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
19 /// Initial Contributors: |
|
20 /// Nokia Corporation - initial contribution. |
|
21 /// Contributors: |
|
22 /// |
|
23 |
|
24 _LIT(KWapBaseNodePanic,"Node-Panic"); |
|
25 |
|
26 #ifndef __WAP_MONOLITHIC__ |
|
27 |
|
28 void Panic(TNodePanic aPanic) |
|
29 // |
|
30 // Panic the client program. |
|
31 // |
|
32 { |
|
33 User::Panic(KWapBaseNodePanic,aPanic); |
|
34 } |
|
35 #endif |
|
36 |
|
37 // |
|
38 // INLINED Node implementation |
|
39 // for description of templated api's see CNODE.H |
|
40 // |
|
41 |
|
42 //CTOR of non-deletable data |
|
43 /** Constructor. |
|
44 |
|
45 @param aData Buffer to wrap |
|
46 */ |
|
47 inline CDataNoDelete::CDataNoDelete(HBufC16* aData) |
|
48 : iData(aData) |
|
49 { |
|
50 } |
|
51 |
|
52 //DTOR doesn't delete the data member |
|
53 /** Destructor. |
|
54 |
|
55 The wrapped buffer is not deleted. |
|
56 */ |
|
57 inline CDataNoDelete::~CDataNoDelete() |
|
58 { |
|
59 } |
|
60 |
|
61 //Accessor method to set the iData pointer to the parameter passed in |
|
62 //Ownership is taken here |
|
63 // Returns the previous value |
|
64 /** Changes the buffer that is wrapped. |
|
65 |
|
66 @return The previous wrapped buffer |
|
67 @param aData Buffer to wrap |
|
68 */ |
|
69 inline HBufC16* CDataNoDelete::SetData(HBufC16* aData) |
|
70 { |
|
71 HBufC16* prevVal = iData; |
|
72 iData = aData; |
|
73 return prevVal; |
|
74 } |
|
75 |
|
76 //Resets data pointer to point to aData, data is not deleted |
|
77 /** Sets the buffer that is wrapped. |
|
78 |
|
79 The existing value is forgotten. |
|
80 |
|
81 @param aData Buffer to wrap |
|
82 */ |
|
83 inline void CDataNoDelete::ResetDataPointer(HBufC16 *aData) |
|
84 { |
|
85 iData = aData; |
|
86 } |
|
87 |
|
88 //Accessor method to get the data |
|
89 /** Gets the wrapped buffer. |
|
90 |
|
91 @return The wrapped buffer |
|
92 */ |
|
93 inline HBufC16* CDataNoDelete::Data() |
|
94 { |
|
95 return iData; |
|
96 } |
|
97 |
|
98 //CTOR of deletable data |
|
99 /** Constructor. |
|
100 |
|
101 @param aData Buffer to wrap |
|
102 */ |
|
103 inline CDataDelete::CDataDelete(HBufC16* aData) |
|
104 : CDataNoDelete(aData) |
|
105 { |
|
106 } |
|
107 |
|
108 //DTOR of deletable data...DELETES THE DATA |
|
109 /** Destructor. |
|
110 |
|
111 The wrapped buffer is deleted. |
|
112 */ |
|
113 inline CDataDelete::~CDataDelete() |
|
114 { |
|
115 delete iData; |
|
116 } |
|
117 |
|
118 /** Sets the buffer that is wrapped. |
|
119 |
|
120 The existing value is deleted. |
|
121 |
|
122 @param aData Buffer to wrap |
|
123 */ |
|
124 inline void CDataDelete::ResetDataPointer(HBufC16* aData) |
|
125 { |
|
126 delete iData; |
|
127 iData = aData; |
|
128 } |
|
129 |
|
130 //CTOR of deletable file data |
|
131 /** Constructor. |
|
132 |
|
133 @param aData Buffer to wrap |
|
134 */ |
|
135 inline CFileDataDelete::CFileDataDelete(HBufC16* aData) |
|
136 : CDataNoDelete(aData) |
|
137 { |
|
138 } |
|
139 |
|
140 // DTOR of deletable file data... |
|
141 // DELETES THE DATA AFTER REMOVING THE REFERENCED FILE |
|
142 /** Destructor. |
|
143 |
|
144 It deletes the filename buffer and the file itself. |
|
145 */ |
|
146 inline CFileDataDelete::~CFileDataDelete() |
|
147 { |
|
148 RemoveFile(); |
|
149 delete iData; |
|
150 } |
|
151 |
|
152 /** Sets the filename that is wrapped. |
|
153 |
|
154 The existing filename buffer and the file itself are deleted. |
|
155 |
|
156 @param aData Buffer to wrap |
|
157 */ |
|
158 inline void CFileDataDelete::ResetDataPointer(HBufC16* aData) |
|
159 { |
|
160 RemoveFile(); |
|
161 delete iData; |
|
162 iData = aData; |
|
163 } |
|
164 |
|
165 inline void CFileDataDelete::RemoveFile() |
|
166 { |
|
167 // When this panics |
|
168 // Someone somewhere has incorrectly reset this node's data |
|
169 __ASSERT_DEBUG(iData,Panic(ENoData)); |
|
170 RFs fs; |
|
171 // If connect fails we can sadly do nothing to remove the file |
|
172 // it will be left lying around :-< |
|
173 if(fs.Connect() == KErrNone) |
|
174 { |
|
175 fs.Delete(iData->Des()); |
|
176 fs.Close(); |
|
177 } |
|
178 } |
|
179 |
|
180 //CTOR of wrapper for integer attributes |
|
181 /** Constructor. |
|
182 |
|
183 @param aInteger Integer to wrap |
|
184 */ |
|
185 inline CIntAttribute::CIntAttribute(TInt aInteger) |
|
186 : iInteger(aInteger) |
|
187 { |
|
188 } |
|
189 |
|
190 //Accessor method |
|
191 /** Gets the wrapped integer. |
|
192 |
|
193 @return The wrapped integer |
|
194 */ |
|
195 inline TInt CIntAttribute::Int() const |
|
196 { |
|
197 return iInteger; |
|
198 } |
|
199 |
|
200 |
|
201 // |
|
202 // |
|
203 //TEMPLATED FUNCTIONS SEE CNODE.H FOR DESCRIPTIONS OF API'S |
|
204 // |
|
205 // |
|
206 /** Allocates and constructs a new node. |
|
207 |
|
208 @return New node |
|
209 @param aType The type of the node |
|
210 @param aParent The parent of this node |
|
211 */ |
|
212 template <class TNodeType, class TAttributeType> |
|
213 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NewL(TNodeType aType, CNode* aParent) |
|
214 { |
|
215 return (STATIC_CAST(CTypedNode*,CNode::NewL(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny*,aType)),aParent))); |
|
216 } |
|
217 |
|
218 |
|
219 template <class TNodeType, class TAttributeType> |
|
220 inline CTypedNode<TNodeType, TAttributeType>::CTypedNode(TNodeType aType, CNode* aParent) |
|
221 : CNode(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny*,aType)),aParent) |
|
222 {} |
|
223 |
|
224 /** Deletes a specified child node. |
|
225 |
|
226 @param aNode Node to delete |
|
227 */ |
|
228 template <class TNodeType, class TAttributeType> |
|
229 inline void CTypedNode<TNodeType, TAttributeType>::DeleteChildNode(CNode* aNode) |
|
230 { |
|
231 CNode::DeleteChildNode(aNode); |
|
232 } |
|
233 |
|
234 /** Deletes all the child nodes of this node. |
|
235 */ |
|
236 template <class TNodeType, class TAttributeType> |
|
237 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAllChildNodes() |
|
238 { |
|
239 CNode::DeleteAllChildNodes(); |
|
240 } |
|
241 |
|
242 /** Creates a new child node. |
|
243 |
|
244 @return The new child node |
|
245 @param aType Node type |
|
246 */ |
|
247 template <class TNodeType, class TAttributeType> |
|
248 inline CTypedNode<TNodeType, TAttributeType>& CTypedNode<TNodeType, TAttributeType>::AppendNodeL(TNodeType aType) |
|
249 { |
|
250 return (STATIC_CAST(CTypedNode& , CNode::AppendNodeL(CONST_CAST(TAny*,REINTERPRET_CAST(TAny*,aType))))); |
|
251 } |
|
252 |
|
253 /** Adds an existing node as a child. |
|
254 |
|
255 @param aNode Node to make a child |
|
256 */ |
|
257 template <class TNodeType, class TAttributeType> |
|
258 inline void CTypedNode<TNodeType, TAttributeType>::AppendNodeToThisNodeL(CNode* aNode) |
|
259 { |
|
260 CNode::AppendNodeToThisNodeL(aNode); |
|
261 } |
|
262 |
|
263 /** Gets the first child or the next child after a specified child. |
|
264 |
|
265 @return First or next child node |
|
266 @param aNode Child node or NULL to get the first child |
|
267 */ |
|
268 template <class TNodeType, class TAttributeType> |
|
269 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NextChild(const CNode* aNode) const |
|
270 { |
|
271 return (STATIC_CAST(CTypedNode*,CNode::NextChild(aNode))); |
|
272 } |
|
273 |
|
274 /** Gets the previous child before a specified child. |
|
275 |
|
276 @return Previous child node |
|
277 @param aNode Child node |
|
278 */ |
|
279 template <class TNodeType, class TAttributeType> |
|
280 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::PrevChild(const CNode& aNode) const |
|
281 { |
|
282 return (STATIC_CAST(CTypedNode*,CNode::PrevChild(aNode))); |
|
283 } |
|
284 |
|
285 /** Gets the parent of this node. |
|
286 |
|
287 @return Parent |
|
288 */ |
|
289 template <class TNodeType, class TAttributeType> |
|
290 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::Parent() const |
|
291 { |
|
292 return (STATIC_CAST(CTypedNode*,CNode::Parent())); |
|
293 } |
|
294 |
|
295 /** Changes the parent of the node. |
|
296 |
|
297 The node is removed from the childlist of its current parent. |
|
298 |
|
299 @param aParent New parent |
|
300 */ |
|
301 template <class TNodeType, class TAttributeType> |
|
302 inline void CTypedNode<TNodeType, TAttributeType>::ReparentL(CNode* aParent) |
|
303 { |
|
304 CNode::ReparentL(aParent); |
|
305 } |
|
306 |
|
307 /** Gets the next sibling node. |
|
308 |
|
309 This asks for the next child of its parent. |
|
310 |
|
311 @return Next sibling node |
|
312 */ |
|
313 template <class TNodeType, class TAttributeType> |
|
314 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NextSibling() const |
|
315 { |
|
316 return (STATIC_CAST(CTypedNode*,CNode::NextSibling())); |
|
317 } |
|
318 |
|
319 /** Gets the previous sibling node. |
|
320 |
|
321 This asks for the previous child of its parent. |
|
322 |
|
323 @return Previous sibling node |
|
324 */ |
|
325 template <class TNodeType, class TAttributeType> |
|
326 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::PrevSibling() const |
|
327 { |
|
328 return (STATIC_CAST(CTypedNode*,CNode::PrevSibling())); |
|
329 } |
|
330 |
|
331 /** Gets the number of children of this node. |
|
332 |
|
333 @return Number of children of this node |
|
334 */ |
|
335 template <class TNodeType, class TAttributeType> |
|
336 inline TInt CTypedNode<TNodeType, TAttributeType>::NumberImmediateChildren() const |
|
337 { |
|
338 return (CNode::NumberImmediateChildren()); |
|
339 } |
|
340 |
|
341 /** Gets the absolute root node of the tree. |
|
342 |
|
343 @return Root node |
|
344 */ |
|
345 template <class TNodeType, class TAttributeType> |
|
346 inline const CTypedNode<TNodeType, TAttributeType>& CTypedNode<TNodeType, TAttributeType>::Root() const |
|
347 { |
|
348 return (STATIC_CAST(const CTypedNode&,CNode::Root())); |
|
349 } |
|
350 |
|
351 /** Sets the node data. |
|
352 |
|
353 The object will delete the data in its destructor. |
|
354 |
|
355 @param aData Node data |
|
356 */ |
|
357 template <class TNodeType, class TAttributeType> |
|
358 inline void CTypedNode<TNodeType, TAttributeType>::SetDataL(HBufC16 *aData) |
|
359 { |
|
360 CNode::SetDataL(aData); |
|
361 } |
|
362 |
|
363 /** Sets the object not to delete the node data in its destructor. |
|
364 |
|
365 Note that the function internally reallocates memory. If it leaves, the data is lost. |
|
366 */ |
|
367 template <class TNodeType, class TAttributeType> |
|
368 inline void CTypedNode<TNodeType, TAttributeType>::SetDataNoDeleteL() |
|
369 { |
|
370 CNode::SetDataNoDeleteL(); |
|
371 } |
|
372 |
|
373 /** Sets the object to delete the node data in its destructor. |
|
374 |
|
375 Note that the function internally reallocates memory. If it leaves, the data is lost. */ |
|
376 template <class TNodeType, class TAttributeType> |
|
377 inline void CTypedNode<TNodeType, TAttributeType>::ClearSetDataNoDeleteL() |
|
378 { |
|
379 CNode::ClearSetDataNoDeleteL(); |
|
380 } |
|
381 |
|
382 /** Sets the node data to be taken from a specified file. |
|
383 |
|
384 If the data is deleted, the referenced file is also deleted. |
|
385 |
|
386 @param aData Name of the file containing the data |
|
387 */ |
|
388 template <class TNodeType, class TAttributeType> |
|
389 inline void CTypedNode<TNodeType, TAttributeType>::SetFileDataL(HBufC16 *aData) |
|
390 { |
|
391 CNode::SetFileDataL(aData); |
|
392 } |
|
393 |
|
394 /** Resets the node data to a specified pointer. |
|
395 |
|
396 Existing data owned by the node is deleted. |
|
397 |
|
398 @param aData Root node |
|
399 */ |
|
400 template <class TNodeType, class TAttributeType> |
|
401 inline void CTypedNode<TNodeType, TAttributeType>::ResetDataPointer(HBufC16* aData) |
|
402 { |
|
403 CNode::ResetDataPointer(aData); |
|
404 } |
|
405 |
|
406 /** Gets the node data. |
|
407 |
|
408 @return Node data or NULL if no data is set |
|
409 */ |
|
410 template <class TNodeType, class TAttributeType> |
|
411 inline HBufC16* CTypedNode<TNodeType, TAttributeType>::Data() const |
|
412 { |
|
413 return (CNode::Data()); |
|
414 } |
|
415 |
|
416 /** Deletes an attribute of a specified type. |
|
417 |
|
418 Note that the attribute value will be deleted. |
|
419 |
|
420 @param aAttributeType Attribute type |
|
421 */ |
|
422 template <class TNodeType, class TAttributeType> |
|
423 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAttribute(TAttributeType aAttributeType) |
|
424 { |
|
425 CNode::DeleteAttribute(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType))); |
|
426 } |
|
427 |
|
428 /** Delete all node attributes. |
|
429 |
|
430 Note that attribute values will be deleted. |
|
431 */ |
|
432 template <class TNodeType, class TAttributeType> |
|
433 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAllAttributes() |
|
434 { |
|
435 CNode::DeleteAllAttributes(); |
|
436 } |
|
437 |
|
438 /** Removes an attribute of a specified type, but does not delete it. |
|
439 |
|
440 The caller is now responsible for the destruction of the attribute value. |
|
441 |
|
442 @param aAttributeType Attribute type |
|
443 */ |
|
444 template <class TNodeType, class TAttributeType> |
|
445 inline void CTypedNode<TNodeType, TAttributeType>::RemoveAttributeNoDelete(TAttributeType aAttributeType) |
|
446 { |
|
447 CNode::RemoveAttributeNoDelete(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny*,aAttributeType))); |
|
448 } |
|
449 |
|
450 /** Gets the number of attributes of this node. |
|
451 |
|
452 @return Number of attributes of this node |
|
453 */ |
|
454 template <class TNodeType, class TAttributeType> |
|
455 inline TInt CTypedNode<TNodeType, TAttributeType>::AttributeCount() const |
|
456 { |
|
457 return(CNode::AttributeCount()); |
|
458 } |
|
459 |
|
460 /** Gets the attribute value of an attribute at a specified index |
|
461 |
|
462 @return Attribute value |
|
463 @param aIndex Attribute index |
|
464 */ |
|
465 template <class TNodeType, class TAttributeType> |
|
466 inline TAttributeType CTypedNode<TNodeType, TAttributeType>::AttributeTypeByIndex(TInt aIndex) const |
|
467 { |
|
468 return(REINTERPRET_CAST(TAttributeType, CNode::AttributeTypeByIndex(aIndex))); |
|
469 } |
|
470 |
|
471 /** Gets the attribute value of an attribute at a specified index |
|
472 |
|
473 @return Attribute value |
|
474 @param aIndex Attribute index |
|
475 */ |
|
476 template <class TNodeType, class TAttributeType> |
|
477 inline CBase* CTypedNode<TNodeType, TAttributeType>::AttributeByIndex(TInt aIndex) const |
|
478 { |
|
479 return(CNode::AttributeByIndex(aIndex)); |
|
480 } |
|
481 |
|
482 /** Gets the attribute value and type of an attribute at a specified index.. |
|
483 |
|
484 @return Attribute value |
|
485 @param aIndex Attribute index |
|
486 @param aType On return, the attribute type |
|
487 */ |
|
488 template <class TNodeType, class TAttributeType> |
|
489 inline CBase* CTypedNode<TNodeType, TAttributeType>::AttributeByIndex(TInt aIndex,TAttributeType& aType) const |
|
490 { |
|
491 TAny* type; |
|
492 CBase* ret=CNode::AttributeByIndex(aIndex,type); |
|
493 aType=REINTERPRET_CAST(TAttributeType, type); |
|
494 return ret; |
|
495 } |
|
496 |
|
497 /** Adds an attribute. |
|
498 |
|
499 The node takes ownership of aAttributeValue. |
|
500 |
|
501 @param aAttributeType Attribute type |
|
502 @param aAttributeValue Attribute value |
|
503 */ |
|
504 template <class TNodeType, class TAttributeType> |
|
505 inline void CTypedNode<TNodeType, TAttributeType>::AddAttributeL(TAttributeType aAttributeType, CBase* aAttributeValue) |
|
506 { |
|
507 CNode::AddAttributeL(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)),aAttributeValue); |
|
508 } |
|
509 |
|
510 /** Sets node data and adds an attribute. |
|
511 |
|
512 The node takes ownership of aDataand aAttributeValue. |
|
513 Existing node data owned by the node is deleted. |
|
514 |
|
515 @param aData Node data |
|
516 @param aAttributeType Attribute type |
|
517 @param aAttributeValue Attribute value |
|
518 */ |
|
519 template <class TNodeType, class TAttributeType> |
|
520 inline void CTypedNode<TNodeType, TAttributeType>::AddDataAndAttributeL(HBufC16 *aData, TAttributeType aAttributeType, CBase* aAttributeValue) |
|
521 { |
|
522 CNode::AddDataAndAttributeL(aData,CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)),aAttributeValue); |
|
523 } |
|
524 |
|
525 /** Gets a child node by index. |
|
526 |
|
527 @return Child node |
|
528 @param aByIndex Index of the child node |
|
529 */ |
|
530 template <class TNodeType, class TAttributeType> |
|
531 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::Child(TInt aByIndex) const |
|
532 { |
|
533 return (REINTERPRET_CAST(CTypedNode*,CNode::Child(aByIndex))); |
|
534 } |
|
535 |
|
536 /** Gets an attribute value for a specified attribute type. |
|
537 |
|
538 @return Attribute value |
|
539 @param aAttributeType Attribute type |
|
540 */ |
|
541 template <class TNodeType, class TAttributeType> |
|
542 inline CBase* CTypedNode<TNodeType, TAttributeType>::Attribute(TAttributeType aAttributeType) const |
|
543 { |
|
544 return (CNode::Attribute(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)))); |
|
545 } |
|
546 |
|
547 /** Tests if an attribute of a specified type exists. |
|
548 |
|
549 @return True if the attribute exists, otherwise false |
|
550 @param aAttributeType Attribute type |
|
551 */ |
|
552 template <class TNodeType, class TAttributeType> |
|
553 inline TBool CTypedNode<TNodeType, TAttributeType>::AttributeExists(TAttributeType aAttributeType) const |
|
554 { |
|
555 return (CNode::AttributeExists(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)))); |
|
556 } |
|
557 |
|
558 /** Gets the node type. |
|
559 |
|
560 @return Node type |
|
561 */ |
|
562 template <class TNodeType, class TAttributeType> |
|
563 inline TNodeType CTypedNode<TNodeType, TAttributeType>::Type() const |
|
564 { |
|
565 return (REINTERPRET_CAST(TNodeType,CNode::Type())); |
|
566 } |
|
567 |
|
568 /** Sets the node type. |
|
569 |
|
570 @param aType Node type |
|
571 */ |
|
572 template <class TNodeType, class TAttributeType> |
|
573 inline void CTypedNode<TNodeType, TAttributeType>::SetType(TNodeType aType) |
|
574 { |
|
575 CNode::SetType(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny* ,aType))); |
|
576 } |