LCOV - code coverage report
Current view: directory - content/xul/templates/src - nsRDFQuery.h (source / functions) Found Hit Coverage
Test: app.info Lines: 23 1 4.3 %
Date: 2012-06-02 Functions: 17 1 5.9 %

       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
       4                 :  *
       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/
       9                 :  *
      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.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      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.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      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.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #ifndef nsRDFQuery_h__
      38                 : #define nsRDFQuery_h__
      39                 : 
      40                 : #include "nsAutoPtr.h"
      41                 : #include "nsISimpleEnumerator.h"
      42                 : #include "nsCycleCollectionParticipant.h"
      43                 : 
      44                 : #define NS_ITEMPLATERDFQUERY_IID \
      45                 :   {0x8929ff60, 0x1c9c, 0x4d87, \
      46                 :     { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }}
      47                 : 
      48                 : /**
      49                 :  * A compiled query in the RDF query processor. This interface should not be
      50                 :  * used directly outside of the RDF query processor.
      51                 :  */
      52                 : class nsITemplateRDFQuery : public nsISupports
      53               0 : {
      54                 : public:
      55                 :     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID)
      56                 : 
      57                 :     // return the processor the query was created from
      58                 :     virtual nsXULTemplateQueryProcessorRDF* Processor() = 0;  // not addrefed
      59                 : 
      60                 :     // return the member variable for the query
      61                 :     virtual nsIAtom* GetMemberVariable() = 0; // not addrefed
      62                 : 
      63                 :     // return the <query> node the query was compiled from
      64                 :     virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0;
      65                 : 
      66                 :     // remove any results that are cached by the query
      67                 :     virtual void ClearCachedResults() = 0;
      68                 : };
      69                 : 
      70                 : class nsRDFQuery : public nsITemplateRDFQuery
      71                 : {
      72                 : public:
      73                 : 
      74               0 :     nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor)
      75                 :       : mProcessor(aProcessor),
      76                 :         mSimple(false),
      77                 :         mRoot(nsnull),
      78               0 :         mCachedResults(nsnull)
      79               0 :     { }
      80                 : 
      81               0 :     ~nsRDFQuery() { Finish(); }
      82                 : 
      83               0 :     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      84            1464 :     NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery)
      85                 : 
      86                 :     /**
      87                 :      * Retrieve the root node in the rule network
      88                 :      * @return the root node in the rule network
      89                 :      */
      90               0 :     TestNode* GetRoot() { return mRoot; }
      91                 : 
      92               0 :     void SetRoot(TestNode* aRoot) { mRoot = aRoot; }
      93                 : 
      94               0 :     void GetQueryNode(nsIDOMNode** aQueryNode)
      95                 :     {
      96               0 :        *aQueryNode = mQueryNode;
      97               0 :        NS_IF_ADDREF(*aQueryNode);
      98               0 :     }
      99                 : 
     100               0 :     void SetQueryNode(nsIDOMNode* aQueryNode)
     101                 :     {
     102               0 :        mQueryNode = aQueryNode;
     103               0 :     }
     104                 : 
     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);
     112                 : 
     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);
     117                 : 
     118                 :     // clear the cached results
     119               0 :     void ClearCachedResults()
     120                 :     {
     121               0 :         mCachedResults = nsnull;
     122               0 :     }
     123                 : 
     124               0 :     nsXULTemplateQueryProcessorRDF* Processor() { return mProcessor; }
     125                 : 
     126               0 :     nsIAtom* GetMemberVariable() { return mMemberVariable; }
     127                 : 
     128               0 :     bool IsSimple() { return mSimple; }
     129                 : 
     130               0 :     void SetSimple() { mSimple = true; }
     131                 : 
     132                 :     // the reference and member variables for the query
     133                 :     nsCOMPtr<nsIAtom> mRefVariable;
     134                 :     nsCOMPtr<nsIAtom> mMemberVariable;
     135                 : 
     136                 : protected:
     137                 : 
     138                 :     nsXULTemplateQueryProcessorRDF* mProcessor;
     139                 : 
     140                 :     // true if the query is a simple rule (one with a default query)
     141                 :     bool mSimple;
     142                 : 
     143                 :     /**
     144                 :      * The root node in the network for this query
     145                 :      */
     146                 :     TestNode *mRoot;
     147                 : 
     148                 :     // the <query> node
     149                 :     nsCOMPtr<nsIDOMNode> mQueryNode;
     150                 : 
     151                 :     // used for simple rules since their results are all determined in one step
     152                 :     nsCOMPtr<nsISimpleEnumerator> mCachedResults;
     153                 : 
     154                 :     void Finish();
     155                 : };
     156                 : 
     157                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsRDFQuery, NS_ITEMPLATERDFQUERY_IID)
     158                 : 
     159                 : #endif // nsRDFQuery_h__

Generated by: LCOV version 1.7