michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef txResultRecycler_h__ michael@0: #define txResultRecycler_h__ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "txStack.h" michael@0: michael@0: class txAExprResult; michael@0: class StringResult; michael@0: class txNodeSet; michael@0: class txXPathNode; michael@0: class NumberResult; michael@0: class BooleanResult; michael@0: michael@0: class txResultRecycler michael@0: { michael@0: public: michael@0: txResultRecycler(); michael@0: ~txResultRecycler(); michael@0: nsresult init(); michael@0: michael@0: void AddRef() michael@0: { michael@0: ++mRefCnt; michael@0: NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this)); michael@0: } michael@0: void Release() michael@0: { michael@0: --mRefCnt; michael@0: NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler"); michael@0: if (mRefCnt == 0) { michael@0: mRefCnt = 1; //stabilize michael@0: delete this; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Returns an txAExprResult to this recycler for reuse. michael@0: * @param aResult result to recycle michael@0: */ michael@0: void recycle(txAExprResult* aResult); michael@0: michael@0: /** michael@0: * Functions to return results that will be fully used by the caller. michael@0: * Returns nullptr on out-of-memory and an inited result otherwise. michael@0: */ michael@0: nsresult getStringResult(StringResult** aResult); michael@0: nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult); michael@0: nsresult getNodeSet(txNodeSet** aResult); michael@0: nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); michael@0: nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult); michael@0: nsresult getNumberResult(double aValue, txAExprResult** aResult); michael@0: michael@0: /** michael@0: * Functions to return a txAExprResult that is shared across several michael@0: * clients and must not be modified. Never returns nullptr. michael@0: */ michael@0: void getEmptyStringResult(txAExprResult** aResult); michael@0: void getBoolResult(bool aValue, txAExprResult** aResult); michael@0: michael@0: /** michael@0: * Functions that return non-shared resultsobjects michael@0: */ michael@0: nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult); michael@0: michael@0: private: michael@0: nsAutoRefCnt mRefCnt; michael@0: txStack mStringResults; michael@0: txStack mNodeSetResults; michael@0: txStack mNumberResults; michael@0: StringResult* mEmptyStringResult; michael@0: BooleanResult* mTrueResult; michael@0: BooleanResult* mFalseResult; michael@0: }; michael@0: michael@0: #endif //txResultRecycler_h__