Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
txResultRecycler Class Reference

#include <txResultRecycler.h>

Collaboration diagram for txResultRecycler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 txResultRecycler ()
 ~txResultRecycler ()
nsresult init ()
void AddRef ()
void Release ()
void recycle (txAExprResult *aResult)
 Returns an txAExprResult to this recycler for reuse.
nsresult getStringResult (StringResult **aResult)
 Functions to return results that will be fully used by the caller.
nsresult getStringResult (const nsAString &aValue, txAExprResult **aResult)
nsresult getNodeSet (txNodeSet **aResult)
nsresult getNodeSet (txNodeSet *aNodeSet, txNodeSet **aResult)
nsresult getNodeSet (const txXPathNode &aNode, txAExprResult **aResult)
nsresult getNodeSet (const txXPathNode &aNode, txNodeSet **aResult)
nsresult getNumberResult (double aValue, txAExprResult **aResult)
void getEmptyStringResult (txAExprResult **aResult)
 Functions to return a txAExprResult that is shared across several clients and must not be modified.
void getBoolResult (PRBool aValue, txAExprResult **aResult)
nsresult getNonSharedNodeSet (txNodeSet *aNodeSet, txNodeSet **aResult)
 Functions that return non-shared resultsobjects.

Private Attributes

nsAutoRefCnt mRefCnt
txStack mStringResults
txStack mNodeSetResults
txStack mNumberResults
StringResultmEmptyStringResult
BooleanResultmTrueResult
BooleanResultmFalseResult

Detailed Description

Definition at line 52 of file txResultRecycler.h.


Constructor & Destructor Documentation

Definition at line 50 of file txResultRecycler.cpp.

{
    txStackIterator stringIter(&mStringResults);
    while (stringIter.hasNext()) {
        delete NS_STATIC_CAST(StringResult*, stringIter.next());
    }
    txStackIterator nodesetIter(&mNodeSetResults);
    while (nodesetIter.hasNext()) {
        delete NS_STATIC_CAST(txNodeSet*, nodesetIter.next());
    }
    txStackIterator numberIter(&mNumberResults);
    while (numberIter.hasNext()) {
        delete NS_STATIC_CAST(NumberResult*, numberIter.next());
    }

    NS_IF_RELEASE(mEmptyStringResult);
    NS_IF_RELEASE(mTrueResult);
    NS_IF_RELEASE(mFalseResult);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 59 of file txResultRecycler.h.

    {
        ++mRefCnt;
    }

Definition at line 271 of file txResultRecycler.cpp.

{
    *aResult = aValue ? mTrueResult : mFalseResult;
    NS_ADDREF(*aResult);
}

Here is the call graph for this function:

Functions to return a txAExprResult that is shared across several clients and must not be modified.

Never returns nsnull.

Definition at line 173 of file txResultRecycler.cpp.

{
    *aResult = mEmptyStringResult;
    NS_ADDREF(*aResult);
}

Here is the call graph for this function:

Definition at line 180 of file txResultRecycler.cpp.

{
    if (mNodeSetResults.isEmpty()) {
        *aResult = new txNodeSet(this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop());
        (*aResult)->clear();
        (*aResult)->mRecycler = this;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txResultRecycler::getNodeSet ( txNodeSet aNodeSet,
txNodeSet **  aResult 
)

Definition at line 197 of file txResultRecycler.cpp.

{
    if (mNodeSetResults.isEmpty()) {
        *aResult = new txNodeSet(*aNodeSet, this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop());
        (*aResult)->clear();
        (*aResult)->append(*aNodeSet);
        (*aResult)->mRecycler = this;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 215 of file txResultRecycler.cpp.

{
    if (mNodeSetResults.isEmpty()) {
        *aResult = new txNodeSet(aNode, this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        txNodeSet* nodes = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop());
        nodes->clear();
        nodes->append(aNode);
        nodes->mRecycler = this;
        *aResult = nodes;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 234 of file txResultRecycler.cpp.

{
    if (mNodeSetResults.isEmpty()) {
        *aResult = new txNodeSet(aNode, this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        *aResult = NS_STATIC_CAST(txNodeSet*, mNodeSetResults.pop());
        (*aResult)->clear();
        (*aResult)->append(aNode);
        (*aResult)->mRecycler = this;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Functions that return non-shared resultsobjects.

Definition at line 278 of file txResultRecycler.cpp.

{
    if (aNodeSet->mRefCnt > 1) {
        return getNodeSet(aNodeSet, aResult);
    }

    *aResult = aNodeSet;
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txResultRecycler::getNumberResult ( double  aValue,
txAExprResult **  aResult 
)

Definition at line 252 of file txResultRecycler.cpp.

{
    if (mNumberResults.isEmpty()) {
        *aResult = new NumberResult(aValue, this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        NumberResult* numRes =
            NS_STATIC_CAST(NumberResult*, mNumberResults.pop());
        numRes->value = aValue;
        numRes->mRecycler = this;
        *aResult = numRes;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Functions to return results that will be fully used by the caller.

Returns nsnull on out-of-memory and an inited result otherwise.

Definition at line 136 of file txResultRecycler.cpp.

{
    if (mStringResults.isEmpty()) {
        *aResult = new StringResult(this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        *aResult = NS_STATIC_CAST(StringResult*, mStringResults.pop());
        (*aResult)->mValue.Truncate();
        (*aResult)->mRecycler = this;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txResultRecycler::getStringResult ( const nsAString &  aValue,
txAExprResult **  aResult 
)

Definition at line 153 of file txResultRecycler.cpp.

{
    if (mStringResults.isEmpty()) {
        *aResult = new StringResult(aValue, this);
        NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    }
    else {
        StringResult* strRes =
            NS_STATIC_CAST(StringResult*, mStringResults.pop());
        strRes->mValue = aValue;
        strRes->mRecycler = this;
        *aResult = strRes;
    }
    NS_ADDREF(*aResult);

    return NS_OK;
}

Here is the call graph for this function:

Returns an txAExprResult to this recycler for reuse.

Parameters:
aResultresult to recycle

Definition at line 96 of file txResultRecycler.cpp.

{
    NS_ASSERTION(aResult->mRefCnt == 0, "In-use txAExprResult recycled");
    nsRefPtr<txResultRecycler> kungFuDeathGrip;
    aResult->mRecycler.swap(kungFuDeathGrip);

    nsresult rv = NS_OK;
    switch (aResult->getResultType()) {
        case txAExprResult::STRING:
        {
            rv = mStringResults.push(NS_STATIC_CAST(StringResult*, aResult));
            if (NS_FAILED(rv)) {
                delete aResult;
            }
            return;
        }
        case txAExprResult::NODESET:
        {
            rv = mNodeSetResults.push(NS_STATIC_CAST(txNodeSet*, aResult));
            if (NS_FAILED(rv)) {
                delete aResult;
            }
            return;
        }
        case txAExprResult::NUMBER:
        {
            rv = mNumberResults.push(NS_STATIC_CAST(NumberResult*, aResult));
            if (NS_FAILED(rv)) {
                delete aResult;
            }
            return;
        }
        default:
        {
            delete aResult;
        }
    }
}

Here is the call graph for this function:

Definition at line 63 of file txResultRecycler.h.

    {
        if (--mRefCnt == 0) {
            mRefCnt = 1; //stabilize
            delete this;
        }
    }

Member Data Documentation

Definition at line 106 of file txResultRecycler.h.

Definition at line 108 of file txResultRecycler.h.

Definition at line 104 of file txResultRecycler.h.

Definition at line 105 of file txResultRecycler.h.

Definition at line 102 of file txResultRecycler.h.

Definition at line 103 of file txResultRecycler.h.

Definition at line 107 of file txResultRecycler.h.


The documentation for this class was generated from the following files: