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 : * IBM Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2002
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * IBM Corporation
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef txResultRecycler_h__
40 : #define txResultRecycler_h__
41 :
42 : #include "nsCOMPtr.h"
43 : #include "txStack.h"
44 :
45 : class txAExprResult;
46 : class StringResult;
47 : class txNodeSet;
48 : class txXPathNode;
49 : class NumberResult;
50 : class BooleanResult;
51 :
52 : class txResultRecycler
53 : {
54 : public:
55 : txResultRecycler();
56 : ~txResultRecycler();
57 : nsresult init();
58 :
59 130 : void AddRef()
60 : {
61 130 : ++mRefCnt;
62 130 : NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this));
63 130 : }
64 130 : void Release()
65 : {
66 130 : --mRefCnt;
67 130 : NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler");
68 130 : if (mRefCnt == 0) {
69 2 : mRefCnt = 1; //stabilize
70 2 : delete this;
71 : }
72 130 : }
73 :
74 : /**
75 : * Returns an txAExprResult to this recycler for reuse.
76 : * @param aResult result to recycle
77 : */
78 : void recycle(txAExprResult* aResult);
79 :
80 : /**
81 : * Functions to return results that will be fully used by the caller.
82 : * Returns nsnull on out-of-memory and an inited result otherwise.
83 : */
84 : nsresult getStringResult(StringResult** aResult);
85 : nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult);
86 : nsresult getNodeSet(txNodeSet** aResult);
87 : nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
88 : nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult);
89 : nsresult getNumberResult(double aValue, txAExprResult** aResult);
90 :
91 : /**
92 : * Functions to return a txAExprResult that is shared across several
93 : * clients and must not be modified. Never returns nsnull.
94 : */
95 : void getEmptyStringResult(txAExprResult** aResult);
96 : void getBoolResult(bool aValue, txAExprResult** aResult);
97 :
98 : /**
99 : * Functions that return non-shared resultsobjects
100 : */
101 : nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
102 :
103 : private:
104 : nsAutoRefCnt mRefCnt;
105 : txStack mStringResults;
106 : txStack mNodeSetResults;
107 : txStack mNumberResults;
108 : StringResult* mEmptyStringResult;
109 : BooleanResult* mTrueResult;
110 : BooleanResult* mFalseResult;
111 : };
112 :
113 : #endif //txResultRecycler_h__
|