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".
8 /// Initial Contributors:
9 /// Nokia Corporation - initial contribution.
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.
24 _LIT(KWapBaseNodePanic,"Node-Panic");
26 #ifndef __WAP_MONOLITHIC__
28 void Panic(TNodePanic aPanic)
30 // Panic the client program.
33 User::Panic(KWapBaseNodePanic,aPanic);
38 // INLINED Node implementation
39 // for description of templated api's see CNODE.H
42 //CTOR of non-deletable data
45 @param aData Buffer to wrap
47 inline CDataNoDelete::CDataNoDelete(HBufC16* aData)
52 //DTOR doesn't delete the data member
55 The wrapped buffer is not deleted.
57 inline CDataNoDelete::~CDataNoDelete()
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.
66 @return The previous wrapped buffer
67 @param aData Buffer to wrap
69 inline HBufC16* CDataNoDelete::SetData(HBufC16* aData)
71 HBufC16* prevVal = iData;
76 //Resets data pointer to point to aData, data is not deleted
77 /** Sets the buffer that is wrapped.
79 The existing value is forgotten.
81 @param aData Buffer to wrap
83 inline void CDataNoDelete::ResetDataPointer(HBufC16 *aData)
88 //Accessor method to get the data
89 /** Gets the wrapped buffer.
91 @return The wrapped buffer
93 inline HBufC16* CDataNoDelete::Data()
98 //CTOR of deletable data
101 @param aData Buffer to wrap
103 inline CDataDelete::CDataDelete(HBufC16* aData)
104 : CDataNoDelete(aData)
108 //DTOR of deletable data...DELETES THE DATA
111 The wrapped buffer is deleted.
113 inline CDataDelete::~CDataDelete()
118 /** Sets the buffer that is wrapped.
120 The existing value is deleted.
122 @param aData Buffer to wrap
124 inline void CDataDelete::ResetDataPointer(HBufC16* aData)
130 //CTOR of deletable file data
133 @param aData Buffer to wrap
135 inline CFileDataDelete::CFileDataDelete(HBufC16* aData)
136 : CDataNoDelete(aData)
140 // DTOR of deletable file data...
141 // DELETES THE DATA AFTER REMOVING THE REFERENCED FILE
144 It deletes the filename buffer and the file itself.
146 inline CFileDataDelete::~CFileDataDelete()
152 /** Sets the filename that is wrapped.
154 The existing filename buffer and the file itself are deleted.
156 @param aData Buffer to wrap
158 inline void CFileDataDelete::ResetDataPointer(HBufC16* aData)
165 inline void CFileDataDelete::RemoveFile()
168 // Someone somewhere has incorrectly reset this node's data
169 __ASSERT_DEBUG(iData,Panic(ENoData));
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)
175 fs.Delete(iData->Des());
180 //CTOR of wrapper for integer attributes
183 @param aInteger Integer to wrap
185 inline CIntAttribute::CIntAttribute(TInt aInteger)
191 /** Gets the wrapped integer.
193 @return The wrapped integer
195 inline TInt CIntAttribute::Int() const
203 //TEMPLATED FUNCTIONS SEE CNODE.H FOR DESCRIPTIONS OF API'S
206 /** Allocates and constructs a new node.
209 @param aType The type of the node
210 @param aParent The parent of this node
212 template <class TNodeType, class TAttributeType>
213 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NewL(TNodeType aType, CNode* aParent)
215 return (STATIC_CAST(CTypedNode*,CNode::NewL(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny*,aType)),aParent)));
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)
224 /** Deletes a specified child node.
226 @param aNode Node to delete
228 template <class TNodeType, class TAttributeType>
229 inline void CTypedNode<TNodeType, TAttributeType>::DeleteChildNode(CNode* aNode)
231 CNode::DeleteChildNode(aNode);
234 /** Deletes all the child nodes of this node.
236 template <class TNodeType, class TAttributeType>
237 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAllChildNodes()
239 CNode::DeleteAllChildNodes();
242 /** Creates a new child node.
244 @return The new child node
245 @param aType Node type
247 template <class TNodeType, class TAttributeType>
248 inline CTypedNode<TNodeType, TAttributeType>& CTypedNode<TNodeType, TAttributeType>::AppendNodeL(TNodeType aType)
250 return (STATIC_CAST(CTypedNode& , CNode::AppendNodeL(CONST_CAST(TAny*,REINTERPRET_CAST(TAny*,aType)))));
253 /** Adds an existing node as a child.
255 @param aNode Node to make a child
257 template <class TNodeType, class TAttributeType>
258 inline void CTypedNode<TNodeType, TAttributeType>::AppendNodeToThisNodeL(CNode* aNode)
260 CNode::AppendNodeToThisNodeL(aNode);
263 /** Gets the first child or the next child after a specified child.
265 @return First or next child node
266 @param aNode Child node or NULL to get the first child
268 template <class TNodeType, class TAttributeType>
269 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NextChild(const CNode* aNode) const
271 return (STATIC_CAST(CTypedNode*,CNode::NextChild(aNode)));
274 /** Gets the previous child before a specified child.
276 @return Previous child node
277 @param aNode Child node
279 template <class TNodeType, class TAttributeType>
280 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::PrevChild(const CNode& aNode) const
282 return (STATIC_CAST(CTypedNode*,CNode::PrevChild(aNode)));
285 /** Gets the parent of this node.
289 template <class TNodeType, class TAttributeType>
290 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::Parent() const
292 return (STATIC_CAST(CTypedNode*,CNode::Parent()));
295 /** Changes the parent of the node.
297 The node is removed from the childlist of its current parent.
299 @param aParent New parent
301 template <class TNodeType, class TAttributeType>
302 inline void CTypedNode<TNodeType, TAttributeType>::ReparentL(CNode* aParent)
304 CNode::ReparentL(aParent);
307 /** Gets the next sibling node.
309 This asks for the next child of its parent.
311 @return Next sibling node
313 template <class TNodeType, class TAttributeType>
314 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::NextSibling() const
316 return (STATIC_CAST(CTypedNode*,CNode::NextSibling()));
319 /** Gets the previous sibling node.
321 This asks for the previous child of its parent.
323 @return Previous sibling node
325 template <class TNodeType, class TAttributeType>
326 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::PrevSibling() const
328 return (STATIC_CAST(CTypedNode*,CNode::PrevSibling()));
331 /** Gets the number of children of this node.
333 @return Number of children of this node
335 template <class TNodeType, class TAttributeType>
336 inline TInt CTypedNode<TNodeType, TAttributeType>::NumberImmediateChildren() const
338 return (CNode::NumberImmediateChildren());
341 /** Gets the absolute root node of the tree.
345 template <class TNodeType, class TAttributeType>
346 inline const CTypedNode<TNodeType, TAttributeType>& CTypedNode<TNodeType, TAttributeType>::Root() const
348 return (STATIC_CAST(const CTypedNode&,CNode::Root()));
351 /** Sets the node data.
353 The object will delete the data in its destructor.
355 @param aData Node data
357 template <class TNodeType, class TAttributeType>
358 inline void CTypedNode<TNodeType, TAttributeType>::SetDataL(HBufC16 *aData)
360 CNode::SetDataL(aData);
363 /** Sets the object not to delete the node data in its destructor.
365 Note that the function internally reallocates memory. If it leaves, the data is lost.
367 template <class TNodeType, class TAttributeType>
368 inline void CTypedNode<TNodeType, TAttributeType>::SetDataNoDeleteL()
370 CNode::SetDataNoDeleteL();
373 /** Sets the object to delete the node data in its destructor.
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()
379 CNode::ClearSetDataNoDeleteL();
382 /** Sets the node data to be taken from a specified file.
384 If the data is deleted, the referenced file is also deleted.
386 @param aData Name of the file containing the data
388 template <class TNodeType, class TAttributeType>
389 inline void CTypedNode<TNodeType, TAttributeType>::SetFileDataL(HBufC16 *aData)
391 CNode::SetFileDataL(aData);
394 /** Resets the node data to a specified pointer.
396 Existing data owned by the node is deleted.
398 @param aData Root node
400 template <class TNodeType, class TAttributeType>
401 inline void CTypedNode<TNodeType, TAttributeType>::ResetDataPointer(HBufC16* aData)
403 CNode::ResetDataPointer(aData);
406 /** Gets the node data.
408 @return Node data or NULL if no data is set
410 template <class TNodeType, class TAttributeType>
411 inline HBufC16* CTypedNode<TNodeType, TAttributeType>::Data() const
413 return (CNode::Data());
416 /** Deletes an attribute of a specified type.
418 Note that the attribute value will be deleted.
420 @param aAttributeType Attribute type
422 template <class TNodeType, class TAttributeType>
423 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAttribute(TAttributeType aAttributeType)
425 CNode::DeleteAttribute(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)));
428 /** Delete all node attributes.
430 Note that attribute values will be deleted.
432 template <class TNodeType, class TAttributeType>
433 inline void CTypedNode<TNodeType, TAttributeType>::DeleteAllAttributes()
435 CNode::DeleteAllAttributes();
438 /** Removes an attribute of a specified type, but does not delete it.
440 The caller is now responsible for the destruction of the attribute value.
442 @param aAttributeType Attribute type
444 template <class TNodeType, class TAttributeType>
445 inline void CTypedNode<TNodeType, TAttributeType>::RemoveAttributeNoDelete(TAttributeType aAttributeType)
447 CNode::RemoveAttributeNoDelete(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny*,aAttributeType)));
450 /** Gets the number of attributes of this node.
452 @return Number of attributes of this node
454 template <class TNodeType, class TAttributeType>
455 inline TInt CTypedNode<TNodeType, TAttributeType>::AttributeCount() const
457 return(CNode::AttributeCount());
460 /** Gets the attribute value of an attribute at a specified index
462 @return Attribute value
463 @param aIndex Attribute index
465 template <class TNodeType, class TAttributeType>
466 inline TAttributeType CTypedNode<TNodeType, TAttributeType>::AttributeTypeByIndex(TInt aIndex) const
468 return(REINTERPRET_CAST(TAttributeType, CNode::AttributeTypeByIndex(aIndex)));
471 /** Gets the attribute value of an attribute at a specified index
473 @return Attribute value
474 @param aIndex Attribute index
476 template <class TNodeType, class TAttributeType>
477 inline CBase* CTypedNode<TNodeType, TAttributeType>::AttributeByIndex(TInt aIndex) const
479 return(CNode::AttributeByIndex(aIndex));
482 /** Gets the attribute value and type of an attribute at a specified index..
484 @return Attribute value
485 @param aIndex Attribute index
486 @param aType On return, the attribute type
488 template <class TNodeType, class TAttributeType>
489 inline CBase* CTypedNode<TNodeType, TAttributeType>::AttributeByIndex(TInt aIndex,TAttributeType& aType) const
492 CBase* ret=CNode::AttributeByIndex(aIndex,type);
493 aType=REINTERPRET_CAST(TAttributeType, type);
497 /** Adds an attribute.
499 The node takes ownership of aAttributeValue.
501 @param aAttributeType Attribute type
502 @param aAttributeValue Attribute value
504 template <class TNodeType, class TAttributeType>
505 inline void CTypedNode<TNodeType, TAttributeType>::AddAttributeL(TAttributeType aAttributeType, CBase* aAttributeValue)
507 CNode::AddAttributeL(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)),aAttributeValue);
510 /** Sets node data and adds an attribute.
512 The node takes ownership of aDataand aAttributeValue.
513 Existing node data owned by the node is deleted.
515 @param aData Node data
516 @param aAttributeType Attribute type
517 @param aAttributeValue Attribute value
519 template <class TNodeType, class TAttributeType>
520 inline void CTypedNode<TNodeType, TAttributeType>::AddDataAndAttributeL(HBufC16 *aData, TAttributeType aAttributeType, CBase* aAttributeValue)
522 CNode::AddDataAndAttributeL(aData,CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType)),aAttributeValue);
525 /** Gets a child node by index.
528 @param aByIndex Index of the child node
530 template <class TNodeType, class TAttributeType>
531 inline CTypedNode<TNodeType, TAttributeType>* CTypedNode<TNodeType, TAttributeType>::Child(TInt aByIndex) const
533 return (REINTERPRET_CAST(CTypedNode*,CNode::Child(aByIndex)));
536 /** Gets an attribute value for a specified attribute type.
538 @return Attribute value
539 @param aAttributeType Attribute type
541 template <class TNodeType, class TAttributeType>
542 inline CBase* CTypedNode<TNodeType, TAttributeType>::Attribute(TAttributeType aAttributeType) const
544 return (CNode::Attribute(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType))));
547 /** Tests if an attribute of a specified type exists.
549 @return True if the attribute exists, otherwise false
550 @param aAttributeType Attribute type
552 template <class TNodeType, class TAttributeType>
553 inline TBool CTypedNode<TNodeType, TAttributeType>::AttributeExists(TAttributeType aAttributeType) const
555 return (CNode::AttributeExists(CONST_CAST(TAny*, REINTERPRET_CAST(const TAny*,aAttributeType))));
558 /** Gets the node type.
562 template <class TNodeType, class TAttributeType>
563 inline TNodeType CTypedNode<TNodeType, TAttributeType>::Type() const
565 return (REINTERPRET_CAST(TNodeType,CNode::Type()));
568 /** Sets the node type.
570 @param aType Node type
572 template <class TNodeType, class TAttributeType>
573 inline void CTypedNode<TNodeType, TAttributeType>::SetType(TNodeType aType)
575 CNode::SetType(CONST_CAST(TAny*,REINTERPRET_CAST(const TAny* ,aType)));