content/xul/templates/src/nsXULTemplateResultSetRDF.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/templates/src/nsXULTemplateResultSetRDF.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     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 +#include "nsXULTemplateResultSetRDF.h"
    1.10 +#include "nsXULTemplateQueryProcessorRDF.h"
    1.11 +
    1.12 +NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator)
    1.13 +
    1.14 +NS_IMETHODIMP
    1.15 +nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult)
    1.16 +{
    1.17 +    *aResult = true;
    1.18 +
    1.19 +    nsCOMPtr<nsIRDFNode> node;
    1.20 +
    1.21 +    if (! mInstantiations || ! mQuery) {
    1.22 +        *aResult = false;
    1.23 +        return NS_OK;
    1.24 +    }
    1.25 +
    1.26 +    if (mCheckedNext) {
    1.27 +        if (!mCurrent || mCurrent == &(mInstantiations->mHead))
    1.28 +            *aResult = false;
    1.29 +        return NS_OK;
    1.30 +    }
    1.31 +
    1.32 +    mCheckedNext = true;
    1.33 +                
    1.34 +    do {
    1.35 +        if (mCurrent) {
    1.36 +            mCurrent = mCurrent->mNext;
    1.37 +            if (mCurrent == &(mInstantiations->mHead)) {
    1.38 +                *aResult = false;
    1.39 +                return NS_OK;
    1.40 +            }
    1.41 +        }
    1.42 +        else {
    1.43 +            *aResult = ! mInstantiations->Empty();
    1.44 +            if (*aResult)
    1.45 +                mCurrent = mInstantiations->mHead.mNext;
    1.46 +        }
    1.47 +
    1.48 +        // get the value of the member variable. If it is not set, skip
    1.49 +        // the result and move on to the next result
    1.50 +        if (mCurrent) {
    1.51 +            mCurrent->mInstantiation.mAssignments.
    1.52 +                GetAssignmentFor(mQuery->mMemberVariable, getter_AddRefs(node));
    1.53 +        }
    1.54 +
    1.55 +        // only resources may be used as results
    1.56 +        mResource = do_QueryInterface(node);
    1.57 +    } while (! mResource);
    1.58 +
    1.59 +    return NS_OK;
    1.60 +}
    1.61 +
    1.62 +NS_IMETHODIMP
    1.63 +nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult)
    1.64 +{
    1.65 +    if (!aResult)
    1.66 +        return NS_ERROR_NULL_POINTER;
    1.67 +
    1.68 +    if (!mCurrent || !mCheckedNext)
    1.69 +        return NS_ERROR_FAILURE;
    1.70 +
    1.71 +    nsRefPtr<nsXULTemplateResultRDF> nextresult =
    1.72 +        new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource);
    1.73 +    if (!nextresult)
    1.74 +        return NS_ERROR_OUT_OF_MEMORY;
    1.75 +
    1.76 +    // add the supporting memory elements to the processor's map. These are
    1.77 +    // used to remove the results when an assertion is removed from the graph
    1.78 +    mProcessor->AddMemoryElements(mCurrent->mInstantiation, nextresult);
    1.79 +
    1.80 +    mCheckedNext = false;
    1.81 +
    1.82 +    *aResult = nextresult;
    1.83 +    NS_ADDREF(*aResult);
    1.84 +
    1.85 +    return NS_OK;
    1.86 +}

mercurial