Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / xul / templates / src / nsRDFQuery.h
blob7db9d3c6ad0787c0322b0ec20a3812232ce19987
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is Neil Deakin
18 * Portions created by the Initial Developer are Copyright (C) 2005
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either of the GNU General Public License Version 2 or later (the "GPL"),
25 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsRDFQuery_h__
38 #define nsRDFQuery_h__
40 #include "nsAutoPtr.h"
41 #include "nsISimpleEnumerator.h"
42 #include "nsCycleCollectionParticipant.h"
44 #define NS_ITEMPLATERDFQUERY_IID \
45 {0x8929ff60, 0x1c9c, 0x4d87, \
46 { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }}
48 /**
49 * A compiled query in the RDF query processor. This interface should not be
50 * used directly outside of the RDF query processor.
52 class nsITemplateRDFQuery : public nsISupports
54 public:
55 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID)
57 // return the processor the query was created from
58 virtual nsXULTemplateQueryProcessorRDF* Processor() = 0; // not addrefed
60 // return the member variable for the query
61 virtual nsIAtom* GetMemberVariable() = 0; // not addrefed
63 // return the <query> node the query was compiled from
64 virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0;
66 // remove any results that are cached by the query
67 virtual void ClearCachedResults() = 0;
70 class nsRDFQuery : public nsITemplateRDFQuery
72 public:
74 nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor)
75 : mProcessor(aProcessor),
76 mSimple(PR_FALSE),
77 mRoot(nsnull),
78 mCachedResults(nsnull)
79 { }
81 ~nsRDFQuery() { Finish(); }
83 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
84 NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery)
86 /**
87 * Retrieve the root node in the rule network
88 * @return the root node in the rule network
90 TestNode* GetRoot() { return mRoot; }
92 void SetRoot(TestNode* aRoot) { mRoot = aRoot; }
94 void GetQueryNode(nsIDOMNode** aQueryNode)
96 *aQueryNode = mQueryNode;
97 NS_IF_ADDREF(*aQueryNode);
100 void SetQueryNode(nsIDOMNode* aQueryNode)
102 mQueryNode = aQueryNode;
105 // an optimization is used when several queries all use the simple query
106 // syntax. Since simple queries can only generate one possible set of
107 // results, they only need to be calculated once and reused for every
108 // simple query. The results may be cached in the query for this purpose.
109 // If successful, this method takes ownership of aInstantiations.
110 nsresult SetCachedResults(nsXULTemplateQueryProcessorRDF* aProcessor,
111 const InstantiationSet& aInstantiations);
113 // grab the cached results, if any, causing the caller to take ownership
114 // of them. This also has the effect of setting the cached results in this
115 // nsRDFQuery to null.
116 void UseCachedResults(nsISimpleEnumerator** aResults);
118 // clear the cached results
119 void ClearCachedResults()
121 mCachedResults = nsnull;
124 nsXULTemplateQueryProcessorRDF* Processor() { return mProcessor; }
126 nsIAtom* GetMemberVariable() { return mMemberVariable; }
128 PRBool IsSimple() { return mSimple; }
130 void SetSimple() { mSimple = PR_TRUE; }
132 // the reference and member variables for the query
133 nsCOMPtr<nsIAtom> mRefVariable;
134 nsCOMPtr<nsIAtom> mMemberVariable;
136 protected:
138 nsXULTemplateQueryProcessorRDF* mProcessor;
140 // true if the query is a simple rule (one with a default query)
141 PRBool mSimple;
144 * The root node in the network for this query
146 TestNode *mRoot;
148 // the <query> node
149 nsCOMPtr<nsIDOMNode> mQueryNode;
151 // used for simple rules since their results are all determined in one step
152 nsCOMPtr<nsISimpleEnumerator> mCachedResults;
154 void Finish();
157 NS_DEFINE_STATIC_IID_ACCESSOR(nsRDFQuery, NS_ITEMPLATERDFQUERY_IID)
159 #endif // nsRDFQuery_h__