tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

txExprResult.h (2865B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      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/. */
      5 
      6 #ifndef TRANSFRMX_EXPRRESULT_H
      7 #define TRANSFRMX_EXPRRESULT_H
      8 
      9 #include "nsString.h"
     10 #include "txCore.h"
     11 #include "txResultRecycler.h"
     12 
     13 /*
     14 * ExprResult
     15 *
     16 * Classes Represented:
     17 * BooleanResult, ExprResult, NumberResult, StringResult
     18 *
     19 * Note: for NodeSet, see NodeSet.h
     20 */
     21 
     22 class txAExprResult {
     23 public:
     24  friend class txResultRecycler;
     25 
     26  // Update txLiteralExpr::getReturnType and sTypes in txEXSLTFunctions.cpp if
     27  // this enum is changed.
     28  enum ResultType {
     29    NODESET = 0,
     30    BOOLEAN,
     31    NUMBER,
     32    STRING,
     33    RESULT_TREE_FRAGMENT
     34  };
     35 
     36  explicit txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler) {}
     37  virtual ~txAExprResult() = default;
     38 
     39  void AddRef() {
     40    ++mRefCnt;
     41    NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this));
     42  }
     43 
     44  void Release();  // Implemented in txResultRecycler.cpp
     45 
     46  /**
     47   * Returns the type of ExprResult represented
     48   * @return the type of ExprResult represented
     49   **/
     50  virtual short getResultType() = 0;
     51 
     52  /**
     53   * Creates a String representation of this ExprResult
     54   * @param aResult the destination string to append the String
     55   *                representation to.
     56   **/
     57  virtual void stringValue(nsString& aResult) = 0;
     58 
     59  /**
     60   * Returns a pointer to the stringvalue if possible. Otherwise null is
     61   * returned.
     62   */
     63  virtual const nsString* stringValuePointer() = 0;
     64 
     65  /**
     66   * Converts this ExprResult to a Boolean (bool) value
     67   * @return the Boolean value
     68   **/
     69  virtual bool booleanValue() = 0;
     70 
     71  /**
     72   * Converts this ExprResult to a Number (double) value
     73   * @return the Number value
     74   **/
     75  virtual double numberValue() = 0;
     76 
     77 private:
     78  nsAutoRefCnt mRefCnt;
     79  RefPtr<txResultRecycler> mRecycler;
     80 };
     81 
     82 #define TX_DECL_EXPRRESULT                               \
     83  virtual short getResultType() override;                \
     84  virtual void stringValue(nsString& aString) override;  \
     85  virtual const nsString* stringValuePointer() override; \
     86  virtual bool booleanValue() override;                  \
     87  virtual double numberValue() override;
     88 
     89 class BooleanResult : public txAExprResult {
     90 public:
     91  explicit BooleanResult(bool aValue);
     92 
     93  TX_DECL_EXPRRESULT
     94 
     95 private:
     96  bool value;
     97 };
     98 
     99 class NumberResult : public txAExprResult {
    100 public:
    101  NumberResult(double aValue, txResultRecycler* aRecycler);
    102 
    103  TX_DECL_EXPRRESULT
    104 
    105  double value;
    106 };
    107 
    108 class StringResult : public txAExprResult {
    109 public:
    110  explicit StringResult(txResultRecycler* aRecycler);
    111  StringResult(const nsAString& aValue, txResultRecycler* aRecycler);
    112 
    113  TX_DECL_EXPRRESULT
    114 
    115  nsString mValue;
    116 };
    117 
    118 #endif