Line data Source code
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/. */
5 :
6 : #ifndef TRANSFRMX_EXPRRESULT_H
7 : #define TRANSFRMX_EXPRRESULT_H
8 :
9 : #include "nsString.h"
10 : #include "nsAutoPtr.h"
11 : #include "txCore.h"
12 : #include "txResultRecycler.h"
13 :
14 : /*
15 : * ExprResult
16 : *
17 : * Classes Represented:
18 : * BooleanResult, ExprResult, NumberResult, StringResult
19 : *
20 : * Note: for NodeSet, see NodeSet.h
21 : */
22 :
23 : class txAExprResult
24 : {
25 : public:
26 : friend class txResultRecycler;
27 :
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 : };
37 :
38 0 : explicit txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler)
39 : {
40 0 : }
41 0 : virtual ~txAExprResult()
42 0 : {
43 0 : }
44 :
45 0 : void AddRef()
46 : {
47 0 : ++mRefCnt;
48 0 : NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this));
49 0 : }
50 :
51 : void Release(); // Implemented in txResultRecycler.cpp
52 :
53 : /**
54 : * Returns the type of ExprResult represented
55 : * @return the type of ExprResult represented
56 : **/
57 : virtual short getResultType() = 0;
58 :
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;
65 :
66 : /**
67 : * Returns a pointer to the stringvalue if possible. Otherwise null is
68 : * returned.
69 : */
70 : virtual const nsString* stringValuePointer() = 0;
71 :
72 : /**
73 : * Converts this ExprResult to a Boolean (bool) value
74 : * @return the Boolean value
75 : **/
76 : virtual bool booleanValue() = 0;
77 :
78 : /**
79 : * Converts this ExprResult to a Number (double) value
80 : * @return the Number value
81 : **/
82 : virtual double numberValue() = 0;
83 :
84 : private:
85 : nsAutoRefCnt mRefCnt;
86 : RefPtr<txResultRecycler> mRecycler;
87 : };
88 :
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(); \
95 :
96 :
97 0 : class BooleanResult : public txAExprResult {
98 :
99 : public:
100 : explicit BooleanResult(bool aValue);
101 :
102 : TX_DECL_EXPRRESULT
103 :
104 : private:
105 : bool value;
106 : };
107 :
108 0 : class NumberResult : public txAExprResult {
109 :
110 : public:
111 : NumberResult(double aValue, txResultRecycler* aRecycler);
112 :
113 : TX_DECL_EXPRRESULT
114 :
115 : double value;
116 :
117 : };
118 :
119 :
120 0 : class StringResult : public txAExprResult {
121 : public:
122 : explicit StringResult(txResultRecycler* aRecycler);
123 : StringResult(const nsAString& aValue, txResultRecycler* aRecycler);
124 :
125 : TX_DECL_EXPRRESULT
126 :
127 : nsString mValue;
128 : };
129 :
130 : #endif
131 :
|