2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-02 10:40:48 +03:00
|
|
|
|
|
|
|
#ifndef txResultRecycler_h__
|
|
|
|
#define txResultRecycler_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "txStack.h"
|
|
|
|
|
|
|
|
class txAExprResult;
|
|
|
|
class StringResult;
|
2005-11-02 10:41:38 +03:00
|
|
|
class txNodeSet;
|
2005-11-02 10:41:43 +03:00
|
|
|
class txXPathNode;
|
2005-11-02 10:40:48 +03:00
|
|
|
class NumberResult;
|
|
|
|
class BooleanResult;
|
|
|
|
|
|
|
|
class txResultRecycler {
|
|
|
|
public:
|
|
|
|
txResultRecycler();
|
|
|
|
~txResultRecycler();
|
|
|
|
|
|
|
|
void AddRef() {
|
|
|
|
++mRefCnt;
|
2007-09-01 21:47:39 +04:00
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this));
|
2005-11-02 10:40:48 +03:00
|
|
|
}
|
|
|
|
void Release() {
|
2007-09-01 21:47:39 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler");
|
|
|
|
if (mRefCnt == 0) {
|
2005-11-02 10:40:48 +03:00
|
|
|
mRefCnt = 1; // stabilize
|
|
|
|
delete this;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-11-02 10:40:48 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an txAExprResult to this recycler for reuse.
|
|
|
|
* @param aResult result to recycle
|
|
|
|
*/
|
|
|
|
void recycle(txAExprResult* aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to return results that will be fully used by the caller.
|
2012-07-30 18:20:58 +04:00
|
|
|
* Returns nullptr on out-of-memory and an inited result otherwise.
|
2005-11-02 10:40:48 +03:00
|
|
|
*/
|
|
|
|
nsresult getStringResult(StringResult** aResult);
|
|
|
|
nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult);
|
2005-11-02 10:41:38 +03:00
|
|
|
nsresult getNodeSet(txNodeSet** aResult);
|
|
|
|
nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
|
2005-11-02 10:41:43 +03:00
|
|
|
nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult);
|
2005-11-02 10:40:48 +03:00
|
|
|
nsresult getNumberResult(double aValue, txAExprResult** aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to return a txAExprResult that is shared across several
|
2012-07-30 18:20:58 +04:00
|
|
|
* clients and must not be modified. Never returns nullptr.
|
2005-11-02 10:40:48 +03:00
|
|
|
*/
|
|
|
|
void getEmptyStringResult(txAExprResult** aResult);
|
2011-09-29 10:19:26 +04:00
|
|
|
void getBoolResult(bool aValue, txAExprResult** aResult);
|
2005-11-02 10:40:48 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions that return non-shared resultsobjects
|
|
|
|
*/
|
2005-11-02 10:41:38 +03:00
|
|
|
nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
|
2005-11-02 10:40:48 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
txStack mStringResults;
|
|
|
|
txStack mNodeSetResults;
|
|
|
|
txStack mNumberResults;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<StringResult> mEmptyStringResult;
|
|
|
|
RefPtr<BooleanResult> mTrueResult;
|
|
|
|
RefPtr<BooleanResult> mFalseResult;
|
2005-11-02 10:40:48 +03:00
|
|
|
};
|
|
|
|
|
2005-11-02 10:40:57 +03:00
|
|
|
#endif // txResultRecycler_h__
|