|
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 #ifndef nsRDFQuery_h__ |
|
7 #define nsRDFQuery_h__ |
|
8 |
|
9 #include "nsAutoPtr.h" |
|
10 #include "nsISimpleEnumerator.h" |
|
11 #include "nsCycleCollectionParticipant.h" |
|
12 #include "mozilla/Attributes.h" |
|
13 |
|
14 #define NS_ITEMPLATERDFQUERY_IID \ |
|
15 {0x8929ff60, 0x1c9c, 0x4d87, \ |
|
16 { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }} |
|
17 |
|
18 /** |
|
19 * A compiled query in the RDF query processor. This interface should not be |
|
20 * used directly outside of the RDF query processor. |
|
21 */ |
|
22 class nsITemplateRDFQuery : public nsISupports |
|
23 { |
|
24 public: |
|
25 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID) |
|
26 |
|
27 // return the processor the query was created from |
|
28 virtual nsXULTemplateQueryProcessorRDF* Processor() = 0; // not addrefed |
|
29 |
|
30 // return the member variable for the query |
|
31 virtual nsIAtom* GetMemberVariable() = 0; // not addrefed |
|
32 |
|
33 // return the <query> node the query was compiled from |
|
34 virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0; |
|
35 |
|
36 // remove any results that are cached by the query |
|
37 virtual void ClearCachedResults() = 0; |
|
38 }; |
|
39 |
|
40 class nsRDFQuery MOZ_FINAL : public nsITemplateRDFQuery |
|
41 { |
|
42 public: |
|
43 |
|
44 nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor) |
|
45 : mProcessor(aProcessor), |
|
46 mSimple(false), |
|
47 mRoot(nullptr), |
|
48 mCachedResults(nullptr) |
|
49 { } |
|
50 |
|
51 ~nsRDFQuery() { Finish(); } |
|
52 |
|
53 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
54 NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery) |
|
55 |
|
56 /** |
|
57 * Retrieve the root node in the rule network |
|
58 * @return the root node in the rule network |
|
59 */ |
|
60 TestNode* GetRoot() { return mRoot; } |
|
61 |
|
62 void SetRoot(TestNode* aRoot) { mRoot = aRoot; } |
|
63 |
|
64 void GetQueryNode(nsIDOMNode** aQueryNode) MOZ_OVERRIDE |
|
65 { |
|
66 *aQueryNode = mQueryNode; |
|
67 NS_IF_ADDREF(*aQueryNode); |
|
68 } |
|
69 |
|
70 void SetQueryNode(nsIDOMNode* aQueryNode) |
|
71 { |
|
72 mQueryNode = aQueryNode; |
|
73 } |
|
74 |
|
75 // an optimization is used when several queries all use the simple query |
|
76 // syntax. Since simple queries can only generate one possible set of |
|
77 // results, they only need to be calculated once and reused for every |
|
78 // simple query. The results may be cached in the query for this purpose. |
|
79 // If successful, this method takes ownership of aInstantiations. |
|
80 nsresult SetCachedResults(nsXULTemplateQueryProcessorRDF* aProcessor, |
|
81 const InstantiationSet& aInstantiations); |
|
82 |
|
83 // grab the cached results, if any, causing the caller to take ownership |
|
84 // of them. This also has the effect of setting the cached results in this |
|
85 // nsRDFQuery to null. |
|
86 void UseCachedResults(nsISimpleEnumerator** aResults); |
|
87 |
|
88 // clear the cached results |
|
89 void ClearCachedResults() MOZ_OVERRIDE |
|
90 { |
|
91 mCachedResults = nullptr; |
|
92 } |
|
93 |
|
94 nsXULTemplateQueryProcessorRDF* Processor() MOZ_OVERRIDE { return mProcessor; } |
|
95 |
|
96 nsIAtom* GetMemberVariable() MOZ_OVERRIDE { return mMemberVariable; } |
|
97 |
|
98 bool IsSimple() { return mSimple; } |
|
99 |
|
100 void SetSimple() { mSimple = true; } |
|
101 |
|
102 // the reference and member variables for the query |
|
103 nsCOMPtr<nsIAtom> mRefVariable; |
|
104 nsCOMPtr<nsIAtom> mMemberVariable; |
|
105 |
|
106 protected: |
|
107 |
|
108 nsXULTemplateQueryProcessorRDF* mProcessor; |
|
109 |
|
110 // true if the query is a simple rule (one with a default query) |
|
111 bool mSimple; |
|
112 |
|
113 /** |
|
114 * The root node in the network for this query |
|
115 */ |
|
116 TestNode *mRoot; |
|
117 |
|
118 // the <query> node |
|
119 nsCOMPtr<nsIDOMNode> mQueryNode; |
|
120 |
|
121 // used for simple rules since their results are all determined in one step |
|
122 nsCOMPtr<nsISimpleEnumerator> mCachedResults; |
|
123 |
|
124 void Finish(); |
|
125 }; |
|
126 |
|
127 NS_DEFINE_STATIC_IID_ACCESSOR(nsITemplateRDFQuery, NS_ITEMPLATERDFQUERY_IID) |
|
128 |
|
129 #endif // nsRDFQuery_h__ |