content/xul/templates/src/nsXULTemplateResultSetRDF.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsXULTemplateResultSetRDF.h"
     7 #include "nsXULTemplateQueryProcessorRDF.h"
     9 NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator)
    11 NS_IMETHODIMP
    12 nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult)
    13 {
    14     *aResult = true;
    16     nsCOMPtr<nsIRDFNode> node;
    18     if (! mInstantiations || ! mQuery) {
    19         *aResult = false;
    20         return NS_OK;
    21     }
    23     if (mCheckedNext) {
    24         if (!mCurrent || mCurrent == &(mInstantiations->mHead))
    25             *aResult = false;
    26         return NS_OK;
    27     }
    29     mCheckedNext = true;
    31     do {
    32         if (mCurrent) {
    33             mCurrent = mCurrent->mNext;
    34             if (mCurrent == &(mInstantiations->mHead)) {
    35                 *aResult = false;
    36                 return NS_OK;
    37             }
    38         }
    39         else {
    40             *aResult = ! mInstantiations->Empty();
    41             if (*aResult)
    42                 mCurrent = mInstantiations->mHead.mNext;
    43         }
    45         // get the value of the member variable. If it is not set, skip
    46         // the result and move on to the next result
    47         if (mCurrent) {
    48             mCurrent->mInstantiation.mAssignments.
    49                 GetAssignmentFor(mQuery->mMemberVariable, getter_AddRefs(node));
    50         }
    52         // only resources may be used as results
    53         mResource = do_QueryInterface(node);
    54     } while (! mResource);
    56     return NS_OK;
    57 }
    59 NS_IMETHODIMP
    60 nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult)
    61 {
    62     if (!aResult)
    63         return NS_ERROR_NULL_POINTER;
    65     if (!mCurrent || !mCheckedNext)
    66         return NS_ERROR_FAILURE;
    68     nsRefPtr<nsXULTemplateResultRDF> nextresult =
    69         new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource);
    70     if (!nextresult)
    71         return NS_ERROR_OUT_OF_MEMORY;
    73     // add the supporting memory elements to the processor's map. These are
    74     // used to remove the results when an assertion is removed from the graph
    75     mProcessor->AddMemoryElements(mCurrent->mInstantiation, nextresult);
    77     mCheckedNext = false;
    79     *aResult = nextresult;
    80     NS_ADDREF(*aResult);
    82     return NS_OK;
    83 }

mercurial