/src/mozilla-central/dom/xslt/xpath/txExprResult.h
Line | Count | Source (jump to first uncovered line) |
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 | | explicit txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler) |
39 | 0 | { |
40 | 0 | } |
41 | | virtual ~txAExprResult() |
42 | 0 | { |
43 | 0 | } |
44 | | |
45 | | void AddRef() |
46 | 0 | { |
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() override; \ |
91 | | virtual void stringValue(nsString& aString) override; \ |
92 | | virtual const nsString* stringValuePointer() override; \ |
93 | | virtual bool booleanValue() override; \ |
94 | | virtual double numberValue() override; |
95 | | |
96 | | class BooleanResult : public txAExprResult { |
97 | | |
98 | | public: |
99 | | explicit BooleanResult(bool aValue); |
100 | | |
101 | | TX_DECL_EXPRRESULT |
102 | | |
103 | | private: |
104 | | bool value; |
105 | | }; |
106 | | |
107 | | class NumberResult : public txAExprResult { |
108 | | |
109 | | public: |
110 | | NumberResult(double aValue, txResultRecycler* aRecycler); |
111 | | |
112 | | TX_DECL_EXPRRESULT |
113 | | |
114 | | double value; |
115 | | |
116 | | }; |
117 | | |
118 | | |
119 | | class StringResult : public txAExprResult { |
120 | | public: |
121 | | explicit StringResult(txResultRecycler* aRecycler); |
122 | | StringResult(const nsAString& aValue, txResultRecycler* aRecycler); |
123 | | |
124 | | TX_DECL_EXPRRESULT |
125 | | |
126 | | nsString mValue; |
127 | | }; |
128 | | |
129 | | #endif |