LCOV - code coverage report
Current view: top level - dom/xul/templates - nsTemplateMatch.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 22 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef nsTemplateMatch_h__
       7             : #define nsTemplateMatch_h__
       8             : 
       9             : #include "mozilla/Attributes.h"
      10             : #include "nsIContent.h"
      11             : #include "nsIXULTemplateQueryProcessor.h"
      12             : #include "nsIXULTemplateResult.h"
      13             : #include "nsRuleNetwork.h"
      14             : 
      15             : /**
      16             :  * A match object, where each match object is associated with one result.
      17             :  * There will be one match list for each unique id generated. However, since
      18             :  * there are multiple querysets and each may generate results with the same
      19             :  * id, they are all chained together in a linked list, ordered in the same
      20             :  * order as the respective <queryset> elements they were generated from.
      21             :  * A match can be identified by the container and id. The id is retrievable
      22             :  * from the result.
      23             :  *
      24             :  * Only one match per container and id pair is active at a time, but which
      25             :  * match is active may change as new results are added or removed. When a
      26             :  * match is active, content is generated for that match.
      27             :  *
      28             :  * Matches are stored and owned by the mMatchToMap hash in the template
      29             :  * builder.
      30             :  */
      31             : 
      32             : class nsTemplateRule;
      33             : class nsTemplateQuerySet;
      34             : 
      35             : class nsTemplateMatch {
      36             : private:
      37             :     // Hide so that only Create() and Destroy() can be used to
      38             :     // allocate and deallocate from the heap
      39             :     void* operator new(size_t) CPP_THROW_NEW { MOZ_ASSERT(0); return nullptr; }
      40             :     void operator delete(void*, size_t) { MOZ_ASSERT(0); }
      41             : 
      42             : public:
      43           0 :     nsTemplateMatch(uint16_t aQuerySetPriority,
      44             :                     nsIXULTemplateResult* aResult,
      45             :                     nsIContent* aContainer)
      46           0 :         : mRuleIndex(-1),
      47             :           mQuerySetPriority(aQuerySetPriority),
      48             :           mContainer(aContainer),
      49             :           mResult(aResult),
      50           0 :           mNext(nullptr)
      51             :     {
      52           0 :       MOZ_COUNT_CTOR(nsTemplateMatch);
      53           0 :     }
      54             : 
      55           0 :     ~nsTemplateMatch()
      56           0 :     {
      57           0 :       MOZ_COUNT_DTOR(nsTemplateMatch);
      58           0 :     }
      59             : 
      60             :     static nsTemplateMatch*
      61           0 :     Create(uint16_t aQuerySetPriority,
      62             :            nsIXULTemplateResult* aResult,
      63             :            nsIContent* aContainer) {
      64           0 :         return ::new nsTemplateMatch(aQuerySetPriority, aResult, aContainer);
      65             :     }
      66             : 
      67             :     static void Destroy(nsTemplateMatch*& aMatch, bool aRemoveResult);
      68             : 
      69             :     // return true if the the match is active, and has generated output
      70           0 :     bool IsActive() {
      71           0 :         return mRuleIndex >= 0;
      72             :     }
      73             : 
      74             :     // indicate that a rule is no longer active, used when a query with a
      75             :     // lower priority has overriden the match
      76           0 :     void SetInactive() {
      77           0 :         mRuleIndex = -1;
      78           0 :     }
      79             : 
      80             :     // return matching rule index
      81           0 :     int16_t RuleIndex() {
      82           0 :         return mRuleIndex;
      83             :     }
      84             : 
      85             :     // return priority of query set
      86           0 :     uint16_t QuerySetPriority() {
      87           0 :         return mQuerySetPriority;
      88             :     }
      89             : 
      90             :     // return container, not addrefed. May be null.
      91           0 :     nsIContent* GetContainer() {
      92           0 :         return mContainer;
      93             :     }
      94             : 
      95             :     nsresult RuleMatched(nsTemplateQuerySet* aQuerySet,
      96             :                          nsTemplateRule* aRule,
      97             :                          int16_t aRuleIndex,
      98             :                          nsIXULTemplateResult* aResult);
      99             : 
     100             : private:
     101             : 
     102             :     /**
     103             :      * The index of the rule that matched, or -1 if the match is not active.
     104             :      */
     105             :     int16_t mRuleIndex;
     106             : 
     107             :     /**
     108             :      * The priority of the queryset for this rule
     109             :      */
     110             :     uint16_t mQuerySetPriority;
     111             : 
     112             :     /**
     113             :      * The container the content generated for the match is inside.
     114             :      */
     115             :     nsCOMPtr<nsIContent> mContainer;
     116             : 
     117             : public:
     118             : 
     119             :     /**
     120             :      * The result associated with this match
     121             :      */
     122             :     nsCOMPtr<nsIXULTemplateResult> mResult;
     123             : 
     124             :     /**
     125             :      * Matches are stored in a linked list, in priority order. This first
     126             :      * match that has a rule set (mRule) is the active match and generates
     127             :      * content. The next match is owned by the builder, which will delete
     128             :      * template matches when needed.
     129             :      */
     130             :     nsTemplateMatch *mNext;
     131             : 
     132             : private:
     133             : 
     134             :     nsTemplateMatch(const nsTemplateMatch& aMatch) = delete;
     135             :     void operator=(const nsTemplateMatch& aMatch) = delete;
     136             : };
     137             : 
     138             : #endif // nsTemplateMatch_h__
     139             : 

Generated by: LCOV version 1.13