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: #ifndef nsRDFQuery_h__ michael@0: #define nsRDFQuery_h__ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #define NS_ITEMPLATERDFQUERY_IID \ michael@0: {0x8929ff60, 0x1c9c, 0x4d87, \ michael@0: { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }} michael@0: michael@0: /** michael@0: * A compiled query in the RDF query processor. This interface should not be michael@0: * used directly outside of the RDF query processor. michael@0: */ michael@0: class nsITemplateRDFQuery : public nsISupports michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID) michael@0: michael@0: // return the processor the query was created from michael@0: virtual nsXULTemplateQueryProcessorRDF* Processor() = 0; // not addrefed michael@0: michael@0: // return the member variable for the query michael@0: virtual nsIAtom* GetMemberVariable() = 0; // not addrefed michael@0: michael@0: // return the node the query was compiled from michael@0: virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0; michael@0: michael@0: // remove any results that are cached by the query michael@0: virtual void ClearCachedResults() = 0; michael@0: }; michael@0: michael@0: class nsRDFQuery MOZ_FINAL : public nsITemplateRDFQuery michael@0: { michael@0: public: michael@0: michael@0: nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor) michael@0: : mProcessor(aProcessor), michael@0: mSimple(false), michael@0: mRoot(nullptr), michael@0: mCachedResults(nullptr) michael@0: { } michael@0: michael@0: ~nsRDFQuery() { Finish(); } michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery) michael@0: michael@0: /** michael@0: * Retrieve the root node in the rule network michael@0: * @return the root node in the rule network michael@0: */ michael@0: TestNode* GetRoot() { return mRoot; } michael@0: michael@0: void SetRoot(TestNode* aRoot) { mRoot = aRoot; } michael@0: michael@0: void GetQueryNode(nsIDOMNode** aQueryNode) MOZ_OVERRIDE michael@0: { michael@0: *aQueryNode = mQueryNode; michael@0: NS_IF_ADDREF(*aQueryNode); michael@0: } michael@0: michael@0: void SetQueryNode(nsIDOMNode* aQueryNode) michael@0: { michael@0: mQueryNode = aQueryNode; michael@0: } michael@0: michael@0: // an optimization is used when several queries all use the simple query michael@0: // syntax. Since simple queries can only generate one possible set of michael@0: // results, they only need to be calculated once and reused for every michael@0: // simple query. The results may be cached in the query for this purpose. michael@0: // If successful, this method takes ownership of aInstantiations. michael@0: nsresult SetCachedResults(nsXULTemplateQueryProcessorRDF* aProcessor, michael@0: const InstantiationSet& aInstantiations); michael@0: michael@0: // grab the cached results, if any, causing the caller to take ownership michael@0: // of them. This also has the effect of setting the cached results in this michael@0: // nsRDFQuery to null. michael@0: void UseCachedResults(nsISimpleEnumerator** aResults); michael@0: michael@0: // clear the cached results michael@0: void ClearCachedResults() MOZ_OVERRIDE michael@0: { michael@0: mCachedResults = nullptr; michael@0: } michael@0: michael@0: nsXULTemplateQueryProcessorRDF* Processor() MOZ_OVERRIDE { return mProcessor; } michael@0: michael@0: nsIAtom* GetMemberVariable() MOZ_OVERRIDE { return mMemberVariable; } michael@0: michael@0: bool IsSimple() { return mSimple; } michael@0: michael@0: void SetSimple() { mSimple = true; } michael@0: michael@0: // the reference and member variables for the query michael@0: nsCOMPtr mRefVariable; michael@0: nsCOMPtr mMemberVariable; michael@0: michael@0: protected: michael@0: michael@0: nsXULTemplateQueryProcessorRDF* mProcessor; michael@0: michael@0: // true if the query is a simple rule (one with a default query) michael@0: bool mSimple; michael@0: michael@0: /** michael@0: * The root node in the network for this query michael@0: */ michael@0: TestNode *mRoot; michael@0: michael@0: // the node michael@0: nsCOMPtr mQueryNode; michael@0: michael@0: // used for simple rules since their results are all determined in one step michael@0: nsCOMPtr mCachedResults; michael@0: michael@0: void Finish(); michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsITemplateRDFQuery, NS_ITEMPLATERDFQUERY_IID) michael@0: michael@0: #endif // nsRDFQuery_h__