dom/xslt/xpath/txNumberResult.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txNumberResult.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     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 +/**
    1.10 + * NumberResult
    1.11 + * Represents the a number as the result of evaluating an Expr
    1.12 +**/
    1.13 +
    1.14 +#include "mozilla/FloatingPoint.h"
    1.15 +
    1.16 +#include "txExprResult.h"
    1.17 +
    1.18 +/**
    1.19 + * Default Constructor
    1.20 +**/
    1.21 +
    1.22 +/**
    1.23 + * Creates a new NumberResult with the value of the given double parameter
    1.24 + * @param dbl the double to use for initialization of this NumberResult's value
    1.25 +**/
    1.26 +NumberResult::NumberResult(double aValue, txResultRecycler* aRecycler)
    1.27 +    : txAExprResult(aRecycler), value(aValue)
    1.28 +{
    1.29 +} //-- NumberResult
    1.30 +
    1.31 +/*
    1.32 + * Virtual Methods from ExprResult
    1.33 +*/
    1.34 +
    1.35 +short NumberResult::getResultType() {
    1.36 +    return txAExprResult::NUMBER;
    1.37 +} //-- getResultType
    1.38 +
    1.39 +void
    1.40 +NumberResult::stringValue(nsString& aResult)
    1.41 +{
    1.42 +    txDouble::toString(value, aResult);
    1.43 +}
    1.44 +
    1.45 +const nsString*
    1.46 +NumberResult::stringValuePointer()
    1.47 +{
    1.48 +    return nullptr;
    1.49 +}
    1.50 +
    1.51 +bool NumberResult::booleanValue() {
    1.52 +  // OG+
    1.53 +  // As per the XPath spec, the boolean value of a number is true if and only if
    1.54 +  // it is neither positive 0 nor negative 0 nor NaN
    1.55 +  return (bool)(value != 0.0 && !mozilla::IsNaN(value));
    1.56 +  // OG-
    1.57 +} //-- booleanValue
    1.58 +
    1.59 +double NumberResult::numberValue() {
    1.60 +    return this->value;
    1.61 +} //-- numberValue
    1.62 +

mercurial