dom/xslt/xpath/txExprResult.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txExprResult.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     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 +#ifndef TRANSFRMX_EXPRRESULT_H
    1.10 +#define TRANSFRMX_EXPRRESULT_H
    1.11 +
    1.12 +#include "nsString.h"
    1.13 +#include "nsAutoPtr.h"
    1.14 +#include "txCore.h"
    1.15 +#include "txResultRecycler.h"
    1.16 +
    1.17 +/*
    1.18 + * ExprResult
    1.19 + *
    1.20 + * Classes Represented:
    1.21 + * BooleanResult, ExprResult, NumberResult, StringResult
    1.22 + *
    1.23 + * Note: for NodeSet, see NodeSet.h
    1.24 +*/
    1.25 +
    1.26 +class txAExprResult
    1.27 +{
    1.28 +public:
    1.29 +    friend class txResultRecycler;
    1.30 +
    1.31 +    // Update txLiteralExpr::getReturnType and sTypes in txEXSLTFunctions.cpp if
    1.32 +    // this enum is changed.
    1.33 +    enum ResultType {
    1.34 +        NODESET = 0,
    1.35 +        BOOLEAN,
    1.36 +        NUMBER,
    1.37 +        STRING,
    1.38 +        RESULT_TREE_FRAGMENT
    1.39 +    };
    1.40 +
    1.41 +    txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler)
    1.42 +    {
    1.43 +    }
    1.44 +    virtual ~txAExprResult()
    1.45 +    {
    1.46 +    }
    1.47 +
    1.48 +    void AddRef()
    1.49 +    {
    1.50 +        ++mRefCnt;
    1.51 +        NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this));
    1.52 +    }
    1.53 +    
    1.54 +    void Release(); // Implemented in txResultRecycler.cpp
    1.55 +
    1.56 +    /**
    1.57 +     * Returns the type of ExprResult represented
    1.58 +     * @return the type of ExprResult represented
    1.59 +    **/
    1.60 +    virtual short getResultType()      = 0;
    1.61 +
    1.62 +    /**
    1.63 +     * Creates a String representation of this ExprResult
    1.64 +     * @param aResult the destination string to append the String
    1.65 +     *                representation to.
    1.66 +    **/
    1.67 +    virtual void stringValue(nsString& aResult) = 0;
    1.68 +
    1.69 +    /**
    1.70 +     * Returns a pointer to the stringvalue if possible. Otherwise null is
    1.71 +     * returned.
    1.72 +     */
    1.73 +    virtual const nsString* stringValuePointer() = 0;
    1.74 +
    1.75 +    /**
    1.76 +     * Converts this ExprResult to a Boolean (bool) value
    1.77 +     * @return the Boolean value
    1.78 +    **/
    1.79 +    virtual bool booleanValue()          = 0;
    1.80 +
    1.81 +    /**
    1.82 +     * Converts this ExprResult to a Number (double) value
    1.83 +     * @return the Number value
    1.84 +    **/
    1.85 +    virtual double numberValue()          = 0;
    1.86 +
    1.87 +private:
    1.88 +    nsAutoRefCnt mRefCnt;
    1.89 +    nsRefPtr<txResultRecycler> mRecycler;
    1.90 +};
    1.91 +
    1.92 +#define TX_DECL_EXPRRESULT                                        \
    1.93 +    virtual short getResultType();                                \
    1.94 +    virtual void stringValue(nsString& aString);                  \
    1.95 +    virtual const nsString* stringValuePointer();                 \
    1.96 +    virtual bool booleanValue();                                \
    1.97 +    virtual double numberValue();                                 \
    1.98 +
    1.99 +
   1.100 +class BooleanResult : public txAExprResult {
   1.101 +
   1.102 +public:
   1.103 +    BooleanResult(bool aValue);
   1.104 +
   1.105 +    TX_DECL_EXPRRESULT
   1.106 +
   1.107 +private:
   1.108 +    bool value;
   1.109 +};
   1.110 +
   1.111 +class NumberResult : public txAExprResult {
   1.112 +
   1.113 +public:
   1.114 +    NumberResult(double aValue, txResultRecycler* aRecycler);
   1.115 +
   1.116 +    TX_DECL_EXPRRESULT
   1.117 +
   1.118 +    double value;
   1.119 +
   1.120 +};
   1.121 +
   1.122 +
   1.123 +class StringResult : public txAExprResult {
   1.124 +public:
   1.125 +    StringResult(txResultRecycler* aRecycler);
   1.126 +    StringResult(const nsAString& aValue, txResultRecycler* aRecycler);
   1.127 +
   1.128 +    TX_DECL_EXPRRESULT
   1.129 +
   1.130 +    nsString mValue;
   1.131 +};
   1.132 +
   1.133 +#endif
   1.134 +

mercurial