michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsXULTemplateResultSetRDF.h" michael@0: #include "nsXULTemplateQueryProcessorRDF.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator) michael@0: michael@0: NS_IMETHODIMP michael@0: nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult) michael@0: { michael@0: *aResult = true; michael@0: michael@0: nsCOMPtr node; michael@0: michael@0: if (! mInstantiations || ! mQuery) { michael@0: *aResult = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: if (mCheckedNext) { michael@0: if (!mCurrent || mCurrent == &(mInstantiations->mHead)) michael@0: *aResult = false; michael@0: return NS_OK; michael@0: } michael@0: michael@0: mCheckedNext = true; michael@0: michael@0: do { michael@0: if (mCurrent) { michael@0: mCurrent = mCurrent->mNext; michael@0: if (mCurrent == &(mInstantiations->mHead)) { michael@0: *aResult = false; michael@0: return NS_OK; michael@0: } michael@0: } michael@0: else { michael@0: *aResult = ! mInstantiations->Empty(); michael@0: if (*aResult) michael@0: mCurrent = mInstantiations->mHead.mNext; michael@0: } michael@0: michael@0: // get the value of the member variable. If it is not set, skip michael@0: // the result and move on to the next result michael@0: if (mCurrent) { michael@0: mCurrent->mInstantiation.mAssignments. michael@0: GetAssignmentFor(mQuery->mMemberVariable, getter_AddRefs(node)); michael@0: } michael@0: michael@0: // only resources may be used as results michael@0: mResource = do_QueryInterface(node); michael@0: } while (! mResource); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult) michael@0: { michael@0: if (!aResult) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: if (!mCurrent || !mCheckedNext) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsRefPtr nextresult = michael@0: new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource); michael@0: if (!nextresult) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: // add the supporting memory elements to the processor's map. These are michael@0: // used to remove the results when an assertion is removed from the graph michael@0: mProcessor->AddMemoryElements(mCurrent->mInstantiation, nextresult); michael@0: michael@0: mCheckedNext = false; michael@0: michael@0: *aResult = nextresult; michael@0: NS_ADDREF(*aResult); michael@0: michael@0: return NS_OK; michael@0: }