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 txResultRecycler_h__
7 : #define txResultRecycler_h__
8 :
9 : #include "nsCOMPtr.h"
10 : #include "nsAutoPtr.h"
11 : #include "txStack.h"
12 :
13 : class txAExprResult;
14 : class StringResult;
15 : class txNodeSet;
16 : class txXPathNode;
17 : class NumberResult;
18 : class BooleanResult;
19 :
20 : class txResultRecycler
21 : {
22 : public:
23 : txResultRecycler();
24 : ~txResultRecycler();
25 :
26 0 : void AddRef()
27 : {
28 0 : ++mRefCnt;
29 0 : NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this));
30 0 : }
31 0 : void Release()
32 : {
33 0 : --mRefCnt;
34 0 : NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler");
35 0 : if (mRefCnt == 0) {
36 0 : mRefCnt = 1; //stabilize
37 0 : delete this;
38 : }
39 0 : }
40 :
41 : /**
42 : * Returns an txAExprResult to this recycler for reuse.
43 : * @param aResult result to recycle
44 : */
45 : void recycle(txAExprResult* aResult);
46 :
47 : /**
48 : * Functions to return results that will be fully used by the caller.
49 : * Returns nullptr on out-of-memory and an inited result otherwise.
50 : */
51 : nsresult getStringResult(StringResult** aResult);
52 : nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult);
53 : nsresult getNodeSet(txNodeSet** aResult);
54 : nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
55 : nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult);
56 : nsresult getNumberResult(double aValue, txAExprResult** aResult);
57 :
58 : /**
59 : * Functions to return a txAExprResult that is shared across several
60 : * clients and must not be modified. Never returns nullptr.
61 : */
62 : void getEmptyStringResult(txAExprResult** aResult);
63 : void getBoolResult(bool aValue, txAExprResult** aResult);
64 :
65 : /**
66 : * Functions that return non-shared resultsobjects
67 : */
68 : nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
69 :
70 : private:
71 : nsAutoRefCnt mRefCnt;
72 : txStack mStringResults;
73 : txStack mNodeSetResults;
74 : txStack mNumberResults;
75 : RefPtr<StringResult> mEmptyStringResult;
76 : RefPtr<BooleanResult> mTrueResult;
77 : RefPtr<BooleanResult> mFalseResult;
78 : };
79 :
80 : #endif //txResultRecycler_h__
|