1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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>
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* 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 NPL, 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 NPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
40
#ifndef nsTemplateMatch_h__
41
#define nsTemplateMatch_h__
43
#include "nsFixedSizeAllocator.h"
44
#include "nsResourceSet.h"
45
#include "nsRuleNetwork.h"
49
* A "match" is a fully instantiated rule; that is, a complete and
50
* consistent set of variable-to-value assignments for all the rule's
53
* Each match also contains information about the "optional"
54
* variable-to-value assignments that can be specified using the
55
* <bindings> element in a rule.
61
class nsTemplateMatch {
63
// Hide so that only Create() and Destroy() can be used to
64
// allocate and deallocate from the heap
65
void* operator new(size_t) CPP_THROW_NEW { return 0; }
66
void operator delete(void*, size_t) {}
71
nsTemplateMatch(const nsTemplateRule* aRule,
72
const Instantiation& aInstantiation,
73
const nsAssignmentSet& aAssignments)
76
mInstantiation(aInstantiation),
77
mAssignments(aAssignments) {}
80
static nsTemplateMatch*
81
Create(nsFixedSizeAllocator& aPool,
82
const nsTemplateRule* aRule,
83
const Instantiation& aInstantiation,
84
const nsAssignmentSet& aAssignments) {
85
void* place = aPool.Alloc(sizeof(nsTemplateMatch));
86
return place ? ::new (place) nsTemplateMatch(aRule, aInstantiation, aAssignments) : nsnull; }
89
Destroy(nsFixedSizeAllocator& aPool, nsTemplateMatch* aMatch) {
90
aMatch->~nsTemplateMatch();
91
aPool.Free(aMatch, sizeof(*aMatch)); }
93
PRBool operator==(const nsTemplateMatch& aMatch) const {
94
return mRule == aMatch.mRule && mInstantiation == aMatch.mInstantiation; }
96
PRBool operator!=(const nsTemplateMatch& aMatch) const {
97
return !(*this == aMatch); }
100
* Get the assignment for the specified variable, computing the
101
* value using the rule's bindings, if necessary.
102
* @param aConflictSet
103
* @param aVariable the variable for which to determine the assignment
104
* @param aValue an out parameter that receives the value assigned to
106
* @return PR_TRUE if aVariable has an assignment, PR_FALSE otherwise.
108
PRBool GetAssignmentFor(nsConflictSet& aConflictSet, PRInt32 aVariable, Value* aValue);
111
* The rule that this match applies for.
113
const nsTemplateRule* mRule;
116
* The fully bound instantiation (variable-to-value assignments, with
117
* memory element support) that match the rule's conditions.
119
Instantiation mInstantiation;
122
* Any additional assignments that apply because of the rule's
123
* bindings. These are computed lazily.
125
nsAssignmentSet mAssignments;
128
* The set of resources that the nsTemplateMatch's bindings depend on. Should the
129
* assertions relating to these resources change, then the rule will
130
* still match (i.e., this match object is still "good"); however, we
131
* may need to recompute the assignments that have been made using the
134
nsResourceSet mBindingDependencies;
138
NS_LOG_ADDREF(this, mRefCnt, "nsTemplateMatch", sizeof(*this));
141
PRInt32 Release(nsFixedSizeAllocator& aPool) {
142
NS_PRECONDITION(mRefCnt > 0, "bad refcnt");
143
PRInt32 refcnt = --mRefCnt;
144
NS_LOG_RELEASE(this, mRefCnt, "nsTemplateMatch");
146
Destroy(aPool, this);
150
nsTemplateMatch(const nsTemplateMatch& aMatch); // not to be implemented
151
void operator=(const nsTemplateMatch& aMatch); // not to be implemented
154
#endif // nsConflictSet_h__