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: #ifndef TRANSFRMX_EXPRRESULT_H michael@0: #define TRANSFRMX_EXPRRESULT_H michael@0: michael@0: #include "nsString.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "txCore.h" michael@0: #include "txResultRecycler.h" michael@0: michael@0: /* michael@0: * ExprResult michael@0: * michael@0: * Classes Represented: michael@0: * BooleanResult, ExprResult, NumberResult, StringResult michael@0: * michael@0: * Note: for NodeSet, see NodeSet.h michael@0: */ michael@0: michael@0: class txAExprResult michael@0: { michael@0: public: michael@0: friend class txResultRecycler; michael@0: michael@0: // Update txLiteralExpr::getReturnType and sTypes in txEXSLTFunctions.cpp if michael@0: // this enum is changed. michael@0: enum ResultType { michael@0: NODESET = 0, michael@0: BOOLEAN, michael@0: NUMBER, michael@0: STRING, michael@0: RESULT_TREE_FRAGMENT michael@0: }; michael@0: michael@0: txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler) michael@0: { michael@0: } michael@0: virtual ~txAExprResult() michael@0: { michael@0: } michael@0: michael@0: void AddRef() michael@0: { michael@0: ++mRefCnt; michael@0: NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this)); michael@0: } michael@0: michael@0: void Release(); // Implemented in txResultRecycler.cpp michael@0: michael@0: /** michael@0: * Returns the type of ExprResult represented michael@0: * @return the type of ExprResult represented michael@0: **/ michael@0: virtual short getResultType() = 0; michael@0: michael@0: /** michael@0: * Creates a String representation of this ExprResult michael@0: * @param aResult the destination string to append the String michael@0: * representation to. michael@0: **/ michael@0: virtual void stringValue(nsString& aResult) = 0; michael@0: michael@0: /** michael@0: * Returns a pointer to the stringvalue if possible. Otherwise null is michael@0: * returned. michael@0: */ michael@0: virtual const nsString* stringValuePointer() = 0; michael@0: michael@0: /** michael@0: * Converts this ExprResult to a Boolean (bool) value michael@0: * @return the Boolean value michael@0: **/ michael@0: virtual bool booleanValue() = 0; michael@0: michael@0: /** michael@0: * Converts this ExprResult to a Number (double) value michael@0: * @return the Number value michael@0: **/ michael@0: virtual double numberValue() = 0; michael@0: michael@0: private: michael@0: nsAutoRefCnt mRefCnt; michael@0: nsRefPtr mRecycler; michael@0: }; michael@0: michael@0: #define TX_DECL_EXPRRESULT \ michael@0: virtual short getResultType(); \ michael@0: virtual void stringValue(nsString& aString); \ michael@0: virtual const nsString* stringValuePointer(); \ michael@0: virtual bool booleanValue(); \ michael@0: virtual double numberValue(); \ michael@0: michael@0: michael@0: class BooleanResult : public txAExprResult { michael@0: michael@0: public: michael@0: BooleanResult(bool aValue); michael@0: michael@0: TX_DECL_EXPRRESULT michael@0: michael@0: private: michael@0: bool value; michael@0: }; michael@0: michael@0: class NumberResult : public txAExprResult { michael@0: michael@0: public: michael@0: NumberResult(double aValue, txResultRecycler* aRecycler); michael@0: michael@0: TX_DECL_EXPRRESULT michael@0: michael@0: double value; michael@0: michael@0: }; michael@0: michael@0: michael@0: class StringResult : public txAExprResult { michael@0: public: michael@0: StringResult(txResultRecycler* aRecycler); michael@0: StringResult(const nsAString& aValue, txResultRecycler* aRecycler); michael@0: michael@0: TX_DECL_EXPRRESULT michael@0: michael@0: nsString mValue; michael@0: }; michael@0: michael@0: #endif michael@0: