Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef txResultRecycler_h__ |
michael@0 | 7 | #define txResultRecycler_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "txStack.h" |
michael@0 | 11 | |
michael@0 | 12 | class txAExprResult; |
michael@0 | 13 | class StringResult; |
michael@0 | 14 | class txNodeSet; |
michael@0 | 15 | class txXPathNode; |
michael@0 | 16 | class NumberResult; |
michael@0 | 17 | class BooleanResult; |
michael@0 | 18 | |
michael@0 | 19 | class txResultRecycler |
michael@0 | 20 | { |
michael@0 | 21 | public: |
michael@0 | 22 | txResultRecycler(); |
michael@0 | 23 | ~txResultRecycler(); |
michael@0 | 24 | nsresult init(); |
michael@0 | 25 | |
michael@0 | 26 | void AddRef() |
michael@0 | 27 | { |
michael@0 | 28 | ++mRefCnt; |
michael@0 | 29 | NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this)); |
michael@0 | 30 | } |
michael@0 | 31 | void Release() |
michael@0 | 32 | { |
michael@0 | 33 | --mRefCnt; |
michael@0 | 34 | NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler"); |
michael@0 | 35 | if (mRefCnt == 0) { |
michael@0 | 36 | mRefCnt = 1; //stabilize |
michael@0 | 37 | delete this; |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * Returns an txAExprResult to this recycler for reuse. |
michael@0 | 43 | * @param aResult result to recycle |
michael@0 | 44 | */ |
michael@0 | 45 | void recycle(txAExprResult* aResult); |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Functions to return results that will be fully used by the caller. |
michael@0 | 49 | * Returns nullptr on out-of-memory and an inited result otherwise. |
michael@0 | 50 | */ |
michael@0 | 51 | nsresult getStringResult(StringResult** aResult); |
michael@0 | 52 | nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult); |
michael@0 | 53 | nsresult getNodeSet(txNodeSet** aResult); |
michael@0 | 54 | nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); |
michael@0 | 55 | nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult); |
michael@0 | 56 | nsresult getNumberResult(double aValue, txAExprResult** aResult); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Functions to return a txAExprResult that is shared across several |
michael@0 | 60 | * clients and must not be modified. Never returns nullptr. |
michael@0 | 61 | */ |
michael@0 | 62 | void getEmptyStringResult(txAExprResult** aResult); |
michael@0 | 63 | void getBoolResult(bool aValue, txAExprResult** aResult); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Functions that return non-shared resultsobjects |
michael@0 | 67 | */ |
michael@0 | 68 | nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); |
michael@0 | 69 | |
michael@0 | 70 | private: |
michael@0 | 71 | nsAutoRefCnt mRefCnt; |
michael@0 | 72 | txStack mStringResults; |
michael@0 | 73 | txStack mNodeSetResults; |
michael@0 | 74 | txStack mNumberResults; |
michael@0 | 75 | StringResult* mEmptyStringResult; |
michael@0 | 76 | BooleanResult* mTrueResult; |
michael@0 | 77 | BooleanResult* mFalseResult; |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | #endif //txResultRecycler_h__ |