1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The MITRE Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Keith Visco <kvisco@ziplink.net> (Original Author)
24 : * Larry Fitzpatrick, OpenText <lef@opentext.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef TRANSFRMX_EXPRRESULT_H
41 : #define TRANSFRMX_EXPRRESULT_H
42 :
43 : #include "nsString.h"
44 : #include "nsAutoPtr.h"
45 : #include "txCore.h"
46 : #include "txResultRecycler.h"
47 :
48 : /*
49 : * ExprResult
50 : *
51 : * Classes Represented:
52 : * BooleanResult, ExprResult, NumberResult, StringResult
53 : *
54 : * Note: for NodeSet, see NodeSet.h
55 : */
56 :
57 : class txAExprResult
58 : {
59 : public:
60 : friend class txResultRecycler;
61 :
62 : // Update txLiteralExpr::getReturnType and sTypes in txEXSLTFunctions.cpp if
63 : // this enum is changed.
64 : enum ResultType {
65 : NODESET = 0,
66 : BOOLEAN,
67 : NUMBER,
68 : STRING,
69 : RESULT_TREE_FRAGMENT
70 : };
71 :
72 8 : txAExprResult(txResultRecycler* aRecycler) : mRecycler(aRecycler)
73 : {
74 8 : }
75 8 : virtual ~txAExprResult()
76 8 : {
77 16 : }
78 :
79 132 : void AddRef()
80 : {
81 132 : ++mRefCnt;
82 132 : NS_LOG_ADDREF(this, mRefCnt, "txAExprResult", sizeof(*this));
83 132 : }
84 :
85 : void Release(); // Implemented in txResultRecycler.cpp
86 :
87 : /**
88 : * Returns the type of ExprResult represented
89 : * @return the type of ExprResult represented
90 : **/
91 : virtual short getResultType() = 0;
92 :
93 : /**
94 : * Creates a String representation of this ExprResult
95 : * @param aResult the destination string to append the String
96 : * representation to.
97 : **/
98 : virtual void stringValue(nsString& aResult) = 0;
99 :
100 : /**
101 : * Returns a pointer to the stringvalue if possible. Otherwise null is
102 : * returned.
103 : */
104 : virtual const nsString* stringValuePointer() = 0;
105 :
106 : /**
107 : * Converts this ExprResult to a Boolean (bool) value
108 : * @return the Boolean value
109 : **/
110 : virtual bool booleanValue() = 0;
111 :
112 : /**
113 : * Converts this ExprResult to a Number (double) value
114 : * @return the Number value
115 : **/
116 : virtual double numberValue() = 0;
117 :
118 : private:
119 : nsAutoRefCnt mRefCnt;
120 : nsRefPtr<txResultRecycler> mRecycler;
121 : };
122 :
123 : #define TX_DECL_EXPRRESULT \
124 : virtual short getResultType(); \
125 : virtual void stringValue(nsString& aString); \
126 : virtual const nsString* stringValuePointer(); \
127 : virtual bool booleanValue(); \
128 : virtual double numberValue(); \
129 :
130 :
131 16 : class BooleanResult : public txAExprResult {
132 :
133 : public:
134 : BooleanResult(bool aValue);
135 :
136 : TX_DECL_EXPRRESULT
137 :
138 : private:
139 : bool value;
140 : };
141 :
142 0 : class NumberResult : public txAExprResult {
143 :
144 : public:
145 : NumberResult(double aValue, txResultRecycler* aRecycler);
146 :
147 : TX_DECL_EXPRRESULT
148 :
149 : double value;
150 :
151 : };
152 :
153 :
154 8 : class StringResult : public txAExprResult {
155 : public:
156 : StringResult(txResultRecycler* aRecycler);
157 : StringResult(const nsAString& aValue, txResultRecycler* aRecycler);
158 :
159 : TX_DECL_EXPRRESULT
160 :
161 : nsString mValue;
162 : };
163 :
164 : #endif
165 :
|