michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "txNodeSetAdaptor.h" michael@0: #include "txXPathTreeWalker.h" michael@0: michael@0: txNodeSetAdaptor::txNodeSetAdaptor() michael@0: : txXPathObjectAdaptor(), michael@0: mWritable(true) michael@0: { michael@0: } michael@0: michael@0: txNodeSetAdaptor::txNodeSetAdaptor(txNodeSet *aNodeSet) michael@0: : txXPathObjectAdaptor(aNodeSet), michael@0: mWritable(false) michael@0: { michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS_INHERITED(txNodeSetAdaptor, txXPathObjectAdaptor, txINodeSet) michael@0: michael@0: nsresult michael@0: txNodeSetAdaptor::Init() michael@0: { michael@0: if (!mValue) { michael@0: mValue = new txNodeSet(nullptr); michael@0: } michael@0: michael@0: return mValue ? NS_OK : NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: txNodeSetAdaptor::Item(uint32_t aIndex, nsIDOMNode **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: michael@0: if (aIndex > (uint32_t)NodeSet()->size()) { michael@0: return NS_ERROR_ILLEGAL_VALUE; michael@0: } michael@0: michael@0: return txXPathNativeNode::getNode(NodeSet()->get(aIndex), aResult); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: txNodeSetAdaptor::ItemAsNumber(uint32_t aIndex, double *aResult) michael@0: { michael@0: if (aIndex > (uint32_t)NodeSet()->size()) { michael@0: return NS_ERROR_ILLEGAL_VALUE; michael@0: } michael@0: michael@0: nsAutoString result; michael@0: txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), result); michael@0: michael@0: *aResult = txDouble::toDouble(result); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: txNodeSetAdaptor::ItemAsString(uint32_t aIndex, nsAString &aResult) michael@0: { michael@0: if (aIndex > (uint32_t)NodeSet()->size()) { michael@0: return NS_ERROR_ILLEGAL_VALUE; michael@0: } michael@0: michael@0: txXPathNodeUtils::appendNodeValue(NodeSet()->get(aIndex), aResult); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: txNodeSetAdaptor::GetLength(uint32_t *aLength) michael@0: { michael@0: *aLength = (uint32_t)NodeSet()->size(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: txNodeSetAdaptor::Add(nsIDOMNode *aNode) michael@0: { michael@0: NS_ENSURE_TRUE(mWritable, NS_ERROR_FAILURE); michael@0: michael@0: nsAutoPtr node(txXPathNativeNode::createXPathNode(aNode, michael@0: true)); michael@0: michael@0: return node ? NodeSet()->add(*node) : NS_ERROR_OUT_OF_MEMORY; michael@0: }