LCOV - code coverage report
Current view: directory - content/xul/templates/src - nsInstantiationNode.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 33 0 0.0 %
Date: 2012-06-02 Functions: 4 0 0.0 %

       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 Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Chris Waterson <waterson@netscape.com>
      24                 :  *   Neil Deakin <enndeakin@sympatico.ca>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "nsInstantiationNode.h"
      41                 : #include "nsTemplateRule.h"
      42                 : #include "nsXULTemplateQueryProcessorRDF.h"
      43                 : 
      44                 : #include "prlog.h"
      45                 : #ifdef PR_LOGGING
      46                 : extern PRLogModuleInfo* gXULTemplateLog;
      47                 : #endif
      48                 : 
      49               0 : nsInstantiationNode::nsInstantiationNode(nsXULTemplateQueryProcessorRDF* aProcessor,
      50                 :                                          nsRDFQuery* aQuery)
      51                 :         : mProcessor(aProcessor),
      52               0 :           mQuery(aQuery)
      53                 : {
      54                 : #ifdef PR_LOGGING
      55               0 :     PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
      56                 :            ("nsInstantiationNode[%p] query=%p", this, aQuery));
      57                 : #endif
      58                 : 
      59               0 :     MOZ_COUNT_CTOR(nsInstantiationNode);
      60               0 : }
      61                 : 
      62                 : 
      63               0 : nsInstantiationNode::~nsInstantiationNode()
      64                 : {
      65               0 :     MOZ_COUNT_DTOR(nsInstantiationNode);
      66               0 : }
      67                 : 
      68                 : nsresult
      69               0 : nsInstantiationNode::Propagate(InstantiationSet& aInstantiations,
      70                 :                                bool aIsUpdate, bool& aTakenInstantiations)
      71                 : {
      72                 :     // In update mode, iterate through the results and call the template
      73                 :     // builder to update them. In non-update mode, cache them in the processor
      74                 :     // to be used during processing. The results are cached in the processor
      75                 :     // so that the simple rules are only computed once. In this situation, all
      76                 :     // data for all queries are calculated at once.
      77               0 :     nsresult rv = NS_OK;
      78                 : 
      79               0 :     aTakenInstantiations = false;
      80                 : 
      81               0 :     if (aIsUpdate) {
      82                 :         // Iterate through newly added keys to determine which rules fired.
      83                 :         //
      84                 :         // XXXwaterson Unfortunately, this could also lead to retractions;
      85                 :         // e.g., (container ?a ^empty false) could become "unmatched". How
      86                 :         // to track those?
      87               0 :         nsCOMPtr<nsIDOMNode> querynode;
      88               0 :         mQuery->GetQueryNode(getter_AddRefs(querynode));
      89                 : 
      90               0 :         InstantiationSet::ConstIterator last = aInstantiations.Last();
      91               0 :         for (InstantiationSet::ConstIterator inst = aInstantiations.First(); inst != last; ++inst) {
      92               0 :             nsAssignmentSet assignments = inst->mAssignments;
      93                 : 
      94               0 :             nsCOMPtr<nsIRDFNode> node;
      95                 :             assignments.GetAssignmentFor(mQuery->mMemberVariable,
      96               0 :                                          getter_AddRefs(node));
      97               0 :             if (node) {
      98               0 :                 nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(node);
      99               0 :                 if (resource) {
     100                 :                     nsRefPtr<nsXULTemplateResultRDF> nextresult =
     101               0 :                         new nsXULTemplateResultRDF(mQuery, *inst, resource);
     102               0 :                     if (! nextresult)
     103               0 :                         return NS_ERROR_OUT_OF_MEMORY;
     104                 : 
     105               0 :                     rv = mProcessor->AddMemoryElements(*inst, nextresult);
     106               0 :                     if (NS_FAILED(rv))
     107               0 :                         return rv;
     108                 : 
     109               0 :                     mProcessor->GetBuilder()->AddResult(nextresult, querynode);
     110                 :                 }
     111                 :             }
     112                 :         }
     113                 :     }
     114                 :     else {
     115               0 :         nsresult rv = mQuery->SetCachedResults(mProcessor, aInstantiations);
     116               0 :         if (NS_SUCCEEDED(rv))
     117               0 :             aTakenInstantiations = true;
     118                 :     }
     119                 : 
     120               0 :     return rv;
     121                 : }

Generated by: LCOV version 1.7