dom/xslt/xpath/txNodeSetAdaptor.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txNodeSetAdaptor.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "txNodeSetAdaptor.h"
    1.10 +#include "txXPathTreeWalker.h"
    1.11 +
    1.12 +txNodeSetAdaptor::txNodeSetAdaptor()
    1.13 +    : txXPathObjectAdaptor(),
    1.14 +      mWritable(true)
    1.15 +{
    1.16 +}
    1.17 +
    1.18 +txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet)
    1.19 +    : txXPathObjectAdaptor(aNodeSet),
    1.20 +      mWritable(false)
    1.21 +{
    1.22 +}
    1.23 +
    1.24 +NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet)
    1.25 +
    1.26 +nsresult
    1.27 +txNodeSetAdaptor::Init()
    1.28 +{
    1.29 +    if (!mValue) {
    1.30 +        mValue = new txNodeSet(nullptr);
    1.31 +    }
    1.32 +
    1.33 +    return mValue ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
    1.34 +}
    1.35 +
    1.36 +NS_IMETHODIMP
    1.37 +txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult)
    1.38 +{
    1.39 +    *aResult = nullptr;
    1.40 +
    1.41 +    if (aIndex > (uint32_t)NodeSet()->size()) {
    1.42 +        return NS_ERROR_ILLEGAL_VALUE;
    1.43 +    }
    1.44 +
    1.45 +    return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult);
    1.46 +}
    1.47 +
    1.48 +NS_IMETHODIMP
    1.49 +txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult)
    1.50 +{
    1.51 +    if (aIndex > (uint32_t)NodeSet()->size()) {
    1.52 +        return NS_ERROR_ILLEGAL_VALUE;
    1.53 +    }
    1.54 +
    1.55 +    nsAutoString result;
    1.56 +    txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result);
    1.57 +
    1.58 +    *aResult = txDouble::toDouble(result);
    1.59 +
    1.60 +    return NS_OK;
    1.61 +}
    1.62 +
    1.63 +NS_IMETHODIMP
    1.64 +txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult)
    1.65 +{
    1.66 +    if (aIndex > (uint32_t)NodeSet()->size()) {
    1.67 +        return NS_ERROR_ILLEGAL_VALUE;
    1.68 +    }
    1.69 +
    1.70 +    txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult);
    1.71 +
    1.72 +    return NS_OK;
    1.73 +}
    1.74 +
    1.75 +NS_IMETHODIMP
    1.76 +txNodeSetAdaptor::GetLength(uint32_t *aLength)
    1.77 +{
    1.78 +    *aLength = (uint32_t)NodeSet()->size();
    1.79 +
    1.80 +    return NS_OK;
    1.81 +}
    1.82 +
    1.83 +NS_IMETHODIMP
    1.84 +txNodeSetAdaptor::Add(nsIDOMNode *aNode)
    1.85 +{
    1.86 +    NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE);
    1.87 +
    1.88 +    nsAutoPtr<txXPathNode> node(txXPathNativeNode::createXPathNode(aNode,
    1.89 +                                                                   true));
    1.90 +
    1.91 +    return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY;
    1.92 +}

mercurial