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