dom/xslt/xpath/txResultRecycler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xslt/xpath/txResultRecycler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef txResultRecycler_h__
    1.10 +#define txResultRecycler_h__
    1.11 +
    1.12 +#include "nsCOMPtr.h"
    1.13 +#include "txStack.h"
    1.14 +
    1.15 +class txAExprResult;
    1.16 +class StringResult;
    1.17 +class txNodeSet;
    1.18 +class txXPathNode;
    1.19 +class NumberResult;
    1.20 +class BooleanResult;
    1.21 +
    1.22 +class txResultRecycler
    1.23 +{
    1.24 +public:
    1.25 +    txResultRecycler();
    1.26 +    ~txResultRecycler();
    1.27 +    nsresult init();
    1.28 +
    1.29 +    void AddRef()
    1.30 +    {
    1.31 +        ++mRefCnt;
    1.32 +        NS_LOG_ADDREF(this, mRefCnt, "txResultRecycler", sizeof(*this));
    1.33 +    }
    1.34 +    void Release()
    1.35 +    {
    1.36 +        --mRefCnt;
    1.37 +        NS_LOG_RELEASE(this, mRefCnt, "txResultRecycler");
    1.38 +        if (mRefCnt == 0) {
    1.39 +            mRefCnt = 1; //stabilize
    1.40 +            delete this;
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44 +    /**
    1.45 +     * Returns an txAExprResult to this recycler for reuse.
    1.46 +     * @param aResult  result to recycle
    1.47 +     */
    1.48 +    void recycle(txAExprResult* aResult);
    1.49 +
    1.50 +    /**
    1.51 +     * Functions to return results that will be fully used by the caller.
    1.52 +     * Returns nullptr on out-of-memory and an inited result otherwise.
    1.53 +     */
    1.54 +    nsresult getStringResult(StringResult** aResult);
    1.55 +    nsresult getStringResult(const nsAString& aValue, txAExprResult** aResult);
    1.56 +    nsresult getNodeSet(txNodeSet** aResult);
    1.57 +    nsresult getNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
    1.58 +    nsresult getNodeSet(const txXPathNode& aNode, txAExprResult** aResult);
    1.59 +    nsresult getNumberResult(double aValue, txAExprResult** aResult);
    1.60 +
    1.61 +    /**
    1.62 +     * Functions to return a txAExprResult that is shared across several
    1.63 +     * clients and must not be modified. Never returns nullptr.
    1.64 +     */
    1.65 +    void getEmptyStringResult(txAExprResult** aResult);
    1.66 +    void getBoolResult(bool aValue, txAExprResult** aResult);
    1.67 +
    1.68 +    /**
    1.69 +     * Functions that return non-shared resultsobjects
    1.70 +     */
    1.71 +    nsresult getNonSharedNodeSet(txNodeSet* aNodeSet, txNodeSet** aResult);
    1.72 +
    1.73 +private:
    1.74 +    nsAutoRefCnt mRefCnt;
    1.75 +    txStack mStringResults;
    1.76 +    txStack mNodeSetResults;
    1.77 +    txStack mNumberResults;
    1.78 +    StringResult* mEmptyStringResult;
    1.79 +    BooleanResult* mTrueResult;
    1.80 +    BooleanResult* mFalseResult;
    1.81 +};
    1.82 +
    1.83 +#endif //txResultRecycler_h__

mercurial