dom/xslt/xpath/txExprResult.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef TRANSFRMX_EXPRRESULT_H
     7 #define TRANSFRMX_EXPRRESULT_H
     9 #include "nsString.h"
    10 #include "nsAutoPtr.h"
    11 #include "txCore.h"
    12 #include "txResultRecycler.h"
    14 /*
    15  * ExprResult
    16  *
    17  * Classes Represented:
    18  * BooleanResult, ExprResult, NumberResult, StringResult
    19  *
    20  * Note: for NodeSet, see NodeSet.h
    21 */
    23 class txAExprResult
    24 {
    25 public:
    26     friend class txResultRecycler;
    28     // Update txLiteralExpr::getReturnType and sTypes in txEXSLTFunctions.cpp if
    29     // this enum is changed.
    30     enum ResultType {
    31         NODESET = 0,
    32         BOOLEAN,
    33         NUMBER,
    34         STRING,
    35         RESULT_TREE_FRAGMENT
    36     };
    38     txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler)
    39     {
    40     }
    41     virtual ~txAExprResult()
    42     {
    43     }
    45     void AddRef()
    46     {
    47         ++mRefCnt;
    48         NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this));
    49     }
    51     void Release(); // Implemented in txResultRecycler.cpp
    53     /**
    54      * Returns the type of ExprResult represented
    55      * @return the type of ExprResult represented
    56     **/
    57     virtual short getResultType()      = 0;
    59     /**
    60      * Creates a String representation of this ExprResult
    61      * @param aResult the destination string to append the String
    62      *                representation to.
    63     **/
    64     virtual void stringValue(nsString& aResult) = 0;
    66     /**
    67      * Returns a pointer to the stringvalue if possible. Otherwise null is
    68      * returned.
    69      */
    70     virtual const nsString* stringValuePointer() = 0;
    72     /**
    73      * Converts this ExprResult to a Boolean (bool) value
    74      * @return the Boolean value
    75     **/
    76     virtual bool booleanValue()          = 0;
    78     /**
    79      * Converts this ExprResult to a Number (double) value
    80      * @return the Number value
    81     **/
    82     virtual double numberValue()          = 0;
    84 private:
    85     nsAutoRefCnt mRefCnt;
    86     nsRefPtr<txResultRecycler> mRecycler;
    87 };
    89 #define TX_DECL_EXPRRESULT                                        \
    90     virtual short getResultType();                                \
    91     virtual void stringValue(nsString& aString);                  \
    92     virtual const nsString* stringValuePointer();                 \
    93     virtual bool booleanValue();                                \
    94     virtual double numberValue();                                 \
    97 class BooleanResult : public txAExprResult {
    99 public:
   100     BooleanResult(bool aValue);
   102     TX_DECL_EXPRRESULT
   104 private:
   105     bool value;
   106 };
   108 class NumberResult : public txAExprResult {
   110 public:
   111     NumberResult(double aValue, txResultRecycler* aRecycler);
   113     TX_DECL_EXPRRESULT
   115     double value;
   117 };
   120 class StringResult : public txAExprResult {
   121 public:
   122     StringResult(txResultRecycler* aRecycler);
   123     StringResult(const nsAString& aValue, txResultRecycler* aRecycler);
   125     TX_DECL_EXPRRESULT
   127     nsString mValue;
   128 };
   130 #endif

mercurial