content/xul/templates/src/nsRDFQuery.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/templates/src/nsRDFQuery.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsRDFQuery_h__
    1.10 +#define nsRDFQuery_h__
    1.11 +
    1.12 +#include "nsAutoPtr.h"
    1.13 +#include "nsISimpleEnumerator.h"
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +#include "mozilla/Attributes.h"
    1.16 +
    1.17 +#define NS_ITEMPLATERDFQUERY_IID \
    1.18 +  {0x8929ff60, 0x1c9c, 0x4d87, \
    1.19 +    { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }}
    1.20 +
    1.21 +/**
    1.22 + * A compiled query in the RDF query processor. This interface should not be
    1.23 + * used directly outside of the RDF query processor.
    1.24 + */
    1.25 +class nsITemplateRDFQuery : public nsISupports
    1.26 +{
    1.27 +public:
    1.28 +    NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID)
    1.29 +
    1.30 +    // return the processor the query was created from
    1.31 +    virtual nsXULTemplateQueryProcessorRDF* Processor() = 0;  // not addrefed
    1.32 +
    1.33 +    // return the member variable for the query
    1.34 +    virtual nsIAtom* GetMemberVariable() = 0; // not addrefed
    1.35 +
    1.36 +    // return the <query> node the query was compiled from
    1.37 +    virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0;
    1.38 +
    1.39 +    // remove any results that are cached by the query
    1.40 +    virtual void ClearCachedResults() = 0;
    1.41 +};
    1.42 +
    1.43 +class nsRDFQuery MOZ_FINAL : public nsITemplateRDFQuery
    1.44 +{
    1.45 +public:
    1.46 +
    1.47 +    nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor)
    1.48 +      : mProcessor(aProcessor),
    1.49 +        mSimple(false),
    1.50 +        mRoot(nullptr),
    1.51 +        mCachedResults(nullptr)
    1.52 +    { }
    1.53 +
    1.54 +    ~nsRDFQuery() { Finish(); }
    1.55 +
    1.56 +    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.57 +    NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery)
    1.58 +
    1.59 +    /**
    1.60 +     * Retrieve the root node in the rule network
    1.61 +     * @return the root node in the rule network
    1.62 +     */
    1.63 +    TestNode* GetRoot() { return mRoot; }
    1.64 +
    1.65 +    void SetRoot(TestNode* aRoot) { mRoot = aRoot; }
    1.66 +
    1.67 +    void GetQueryNode(nsIDOMNode** aQueryNode) MOZ_OVERRIDE
    1.68 +    {
    1.69 +       *aQueryNode = mQueryNode;
    1.70 +       NS_IF_ADDREF(*aQueryNode);
    1.71 +    }
    1.72 +
    1.73 +    void SetQueryNode(nsIDOMNode* aQueryNode)
    1.74 +    {
    1.75 +       mQueryNode = aQueryNode;
    1.76 +    }
    1.77 +
    1.78 +    // an optimization is used when several queries all use the simple query
    1.79 +    // syntax. Since simple queries can only generate one possible set of
    1.80 +    // results, they only need to be calculated once and reused for every
    1.81 +    // simple query. The results may be cached in the query for this purpose.
    1.82 +    // If successful, this method takes ownership of aInstantiations.
    1.83 +    nsresult SetCachedResults(nsXULTemplateQueryProcessorRDF* aProcessor,
    1.84 +                              const InstantiationSet& aInstantiations);
    1.85 +
    1.86 +    // grab the cached results, if any, causing the caller to take ownership
    1.87 +    // of them. This also has the effect of setting the cached results in this
    1.88 +    // nsRDFQuery to null.
    1.89 +    void UseCachedResults(nsISimpleEnumerator** aResults);
    1.90 +
    1.91 +    // clear the cached results
    1.92 +    void ClearCachedResults() MOZ_OVERRIDE
    1.93 +    {
    1.94 +        mCachedResults = nullptr;
    1.95 +    }
    1.96 +
    1.97 +    nsXULTemplateQueryProcessorRDF* Processor() MOZ_OVERRIDE { return mProcessor; }
    1.98 +
    1.99 +    nsIAtom* GetMemberVariable() MOZ_OVERRIDE { return mMemberVariable; }
   1.100 +
   1.101 +    bool IsSimple() { return mSimple; }
   1.102 +
   1.103 +    void SetSimple() { mSimple = true; }
   1.104 +
   1.105 +    // the reference and member variables for the query
   1.106 +    nsCOMPtr<nsIAtom> mRefVariable;
   1.107 +    nsCOMPtr<nsIAtom> mMemberVariable;
   1.108 +
   1.109 +protected:
   1.110 +
   1.111 +    nsXULTemplateQueryProcessorRDF* mProcessor;
   1.112 +
   1.113 +    // true if the query is a simple rule (one with a default query)
   1.114 +    bool mSimple;
   1.115 +
   1.116 +    /**
   1.117 +     * The root node in the network for this query
   1.118 +     */
   1.119 +    TestNode *mRoot;
   1.120 +
   1.121 +    // the <query> node
   1.122 +    nsCOMPtr<nsIDOMNode> mQueryNode;
   1.123 +
   1.124 +    // used for simple rules since their results are all determined in one step
   1.125 +    nsCOMPtr<nsISimpleEnumerator> mCachedResults;
   1.126 +
   1.127 +    void Finish();
   1.128 +};
   1.129 +
   1.130 +NS_DEFINE_STATIC_IID_ACCESSOR(nsITemplateRDFQuery, NS_ITEMPLATERDFQUERY_IID)
   1.131 +
   1.132 +#endif // nsRDFQuery_h__

mercurial