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
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/
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
15 * The Original Code is Mozilla Communicator client code.
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.
23 * Chris Waterson <waterson@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsTemplateMatch_h__
40 #define nsTemplateMatch_h__
42 #include "nsFixedSizeAllocator.h"
43 #include "nsIContent.h"
44 #include "nsIXULTemplateQueryProcessor.h"
45 #include "nsIXULTemplateResult.h"
46 #include "nsRuleNetwork.h"
50 * A match object, where each match object is associated with one result.
51 * There will be one match list for each unique id generated. However, since
52 * there are multiple querysets and each may generate results with the same
53 * id, they are all chained together in a linked list, ordered in the same
54 * order as the respective <queryset> elements they were generated from.
55 * A match can be identified by the container and id. The id is retrievable
58 * Only one match per container and id pair is active at a time, but which
59 * match is active may change as new results are added or removed. When a
60 * match is active, content is generated for that match.
62 * Matches are stored and owned by the mMatchToMap hash in the template
67 class nsTemplateQuerySet
;
69 class nsTemplateMatch
{
71 // Hide so that only Create() and Destroy() can be used to
72 // allocate and deallocate from the heap
73 void* operator new(size_t) CPP_THROW_NEW
{ return 0; }
74 void operator delete(void*, size_t) {}
77 nsTemplateMatch(PRUint16 aQuerySetPriority
,
78 nsIXULTemplateResult
* aResult
,
79 nsIContent
* aContainer
)
81 mQuerySetPriority(aQuerySetPriority
),
82 mContainer(aContainer
),
88 static nsTemplateMatch
*
89 Create(nsFixedSizeAllocator
& aPool
,
90 PRUint16 aQuerySetPriority
,
91 nsIXULTemplateResult
* aResult
,
92 nsIContent
* aContainer
) {
93 void* place
= aPool
.Alloc(sizeof(nsTemplateMatch
));
94 return place
? ::new (place
) nsTemplateMatch(aQuerySetPriority
,
98 static void Destroy(nsFixedSizeAllocator
& aPool
,
99 nsTemplateMatch
*& aMatch
,
100 PRBool aRemoveResult
);
102 // return true if the the match is active, and has generated output
104 return mRuleIndex
>= 0;
107 // indicate that a rule is no longer active, used when a query with a
108 // lower priority has overriden the match
113 // return matching rule index
114 PRInt16
RuleIndex() {
118 // return priority of query set
119 PRUint16
QuerySetPriority() {
120 return mQuerySetPriority
;
123 // return container, not addrefed. May be null.
124 nsIContent
* GetContainer() {
128 nsresult
RuleMatched(nsTemplateQuerySet
* aQuerySet
,
129 nsTemplateRule
* aRule
,
131 nsIXULTemplateResult
* aResult
);
136 * The index of the rule that matched, or -1 if the match is not active.
141 * The priority of the queryset for this rule
143 PRUint16 mQuerySetPriority
;
146 * The container the content generated for the match is inside.
148 nsCOMPtr
<nsIContent
> mContainer
;
153 * The result associated with this match
155 nsCOMPtr
<nsIXULTemplateResult
> mResult
;
158 * Matches are stored in a linked list, in priority order. This first
159 * match that has a rule set (mRule) is the active match and generates
160 * content. The next match is owned by the builder, which will delete
161 * template matches when needed.
163 nsTemplateMatch
*mNext
;
167 nsTemplateMatch(const nsTemplateMatch
& aMatch
); // not to be implemented
168 void operator=(const nsTemplateMatch
& aMatch
); // not to be implemented
171 #endif // nsTemplateMatch_h__