nsXULTemplateResultSetRDF.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/. */
  5. #include "nsXULTemplateResultSetRDF.h"
  6. #include "nsXULTemplateQueryProcessorRDF.h"
  7. NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator)
  8. NS_IMETHODIMP
  9. nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult)
  10. {
  11. *aResult = true;
  12. nsCOMPtr<nsIRDFNode> node;
  13. if (! mInstantiations || ! mQuery) {
  14. *aResult = false;
  15. return NS_OK;
  16. }
  17. if (mCheckedNext) {
  18. if (!mCurrent || mCurrent == &(mInstantiations->mHead))
  19. *aResult = false;
  20. return NS_OK;
  21. }
  22. mCheckedNext = true;
  23. do {
  24. if (mCurrent) {
  25. mCurrent = mCurrent->mNext;
  26. if (mCurrent == &(mInstantiations->mHead)) {
  27. *aResult = false;
  28. return NS_OK;
  29. }
  30. }
  31. else {
  32. *aResult = ! mInstantiations->Empty();
  33. if (*aResult)
  34. mCurrent = mInstantiations->mHead.mNext;
  35. }
  36. // get the value of the member variable. If it is not set, skip
  37. // the result and move on to the next result
  38. if (mCurrent) {
  39. mCurrent->mInstantiation.mAssignments.
  40. GetAssignmentFor(mQuery->mMemberVariable, getter_AddRefs(node));
  41. }
  42. // only resources may be used as results
  43. mResource = do_QueryInterface(node);
  44. } while (! mResource);
  45. return NS_OK;
  46. }
  47. NS_IMETHODIMP
  48. nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult)
  49. {
  50. if (!aResult)
  51. return NS_ERROR_NULL_POINTER;
  52. if (!mCurrent || !mCheckedNext)
  53. return NS_ERROR_FAILURE;
  54. RefPtr<nsXULTemplateResultRDF> nextresult =
  55. new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource);
  56. if (!nextresult)
  57. return NS_ERROR_OUT_OF_MEMORY;
  58. // add the supporting memory elements to the processor's map. These are
  59. // used to remove the results when an assertion is removed from the graph
  60. mProcessor->AddMemoryElements(mCurrent->mInstantiation, nextresult);
  61. mCheckedNext = false;
  62. nextresult.forget(aResult);
  63. return NS_OK;
  64. }