xml/xmldomandxpath/src/xmlenginedom/xmlengnodeset.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2005-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 // Node set functions implementation
       
    15 //
       
    16 
       
    17 #include <stdapis/libxml2/libxml2_globals.h>
       
    18 #include <stdapis/libxml2/libxml2_xpath.h>
       
    19 #include <stdapis/libxml2/libxml2_xpathinternals.h>
       
    20 
       
    21 #include <xml/dom/xmlengnodeset.h>
       
    22 #include <xml/dom/xmlengnode.h>
       
    23 #include "xmlengdomdefs.h"
       
    24 #include <xml/utils/xmlengmem.h>
       
    25 
       
    26 #define THIS_NODESET (static_cast<xmlNodeSetPtr>(iInternal))
       
    27 // -----------------------------------------------------------------------------
       
    28 // Default constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C RXmlEngNodeSet::RXmlEngNodeSet():iInternal(NULL)
       
    32     {
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // Frees any allocated resources for the RXmlEngNodeSet instance.
       
    37 //
       
    38 // @note All nodes referred to in a node set are "live",
       
    39 //       meaning that they are not copies of actual nodes in
       
    40 //       a document tree. <br>
       
    41 //       <b> The only exception for this are namespace declarations, 
       
    42 //       which ARE COPIES AND ARE DESTROYED with a node set</b>
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C void RXmlEngNodeSet::Free()
       
    46     {
       
    47     // NOTE: namespace nodes are new objects (->next points to parent element)
       
    48     //       and should be destroyed; all other nodes are "live" and belong 
       
    49     //       to the document tree (so, should not be deleted)
       
    50     //       xmlXPathNodeSetFreeNs(xmlNsPtr ns) is used for namespaces
       
    51     if (!THIS_NODESET)
       
    52         return;  // nothing to free..
       
    53     xmlXPathFreeNodeSet(THIS_NODESET);
       
    54     iInternal = NULL;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // @return Number of nodes in a node set
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C TInt RXmlEngNodeSet::Length() const
       
    62     {
       
    63     return THIS_NODESET ? THIS_NODESET->nodeNr : 0;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // Retrieves a node from node set by index
       
    68 //
       
    69 // @param aIndex  Node index  { 0 <= aIndex < Length() } 
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C TXmlEngNode RXmlEngNodeSet::operator[](
       
    73     TInt aIndex) const
       
    74     {
       
    75     XE_ASSERT_DEBUG(THIS_NODESET && aIndex >= 0 && aIndex < THIS_NODESET->nodeNr);
       
    76     return TXmlEngNode(THIS_NODESET->nodeTab[aIndex]);
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Checks whether aNode is in a resulting node set
       
    81 //
       
    82 // @return TRUE is node in the node set, FALSE otherwise
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C TBool RXmlEngNodeSet::Contains(
       
    86     TXmlEngNode aNode) const
       
    87     {
       
    88     return xmlXPathNodeSetContains(THIS_NODESET, INTERNAL_NODEPTR(aNode));
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // Initializes a RXmlEngNodeSet instance as being "empty"
       
    93 //
       
    94 // This method is used when preparing node sets that will
       
    95 // be used with RXmlEngXPathExpression::EvaluateWithDependenciesL(TXmlEngNode,RXmlEngNodeSet&)
       
    96 // and TXmlEngXPathEvaluator::EvaluateWithDependenciesL(aExpression,aContextNode,aResolver,aDependents)
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void RXmlEngNodeSet::InitializeL()
       
   100     {
       
   101     Free();
       
   102     // create the libxml nodeset "object"
       
   103     iInternal = xmlXPathNodeSetCreate(NULL);
       
   104     OOM_IF_NULL(iInternal);
       
   105     }
       
   106 // -----------------------------------------------------------------------------
       
   107 // Constructor
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 RXmlEngNodeSet::RXmlEngNodeSet(void* aData):iInternal(aData)
       
   111     {
       
   112     }