|
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 |
|
6 #include "nsXULTemplateResultSetRDF.h" |
|
7 #include "nsXULTemplateQueryProcessorRDF.h" |
|
8 |
|
9 NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator) |
|
10 |
|
11 NS_IMETHODIMP |
|
12 nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult) |
|
13 { |
|
14 *aResult = true; |
|
15 |
|
16 nsCOMPtr<nsIRDFNode> node; |
|
17 |
|
18 if (! mInstantiations || ! mQuery) { |
|
19 *aResult = false; |
|
20 return NS_OK; |
|
21 } |
|
22 |
|
23 if (mCheckedNext) { |
|
24 if (!mCurrent || mCurrent == &(mInstantiations->mHead)) |
|
25 *aResult = false; |
|
26 return NS_OK; |
|
27 } |
|
28 |
|
29 mCheckedNext = true; |
|
30 |
|
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 } |
|
44 |
|
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 } |
|
51 |
|
52 // only resources may be used as results |
|
53 mResource = do_QueryInterface(node); |
|
54 } while (! mResource); |
|
55 |
|
56 return NS_OK; |
|
57 } |
|
58 |
|
59 NS_IMETHODIMP |
|
60 nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult) |
|
61 { |
|
62 if (!aResult) |
|
63 return NS_ERROR_NULL_POINTER; |
|
64 |
|
65 if (!mCurrent || !mCheckedNext) |
|
66 return NS_ERROR_FAILURE; |
|
67 |
|
68 nsRefPtr<nsXULTemplateResultRDF> nextresult = |
|
69 new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource); |
|
70 if (!nextresult) |
|
71 return NS_ERROR_OUT_OF_MEMORY; |
|
72 |
|
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); |
|
76 |
|
77 mCheckedNext = false; |
|
78 |
|
79 *aResult = nextresult; |
|
80 NS_ADDREF(*aResult); |
|
81 |
|
82 return NS_OK; |
|
83 } |