~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/xul/templates/src/nsTemplateMatch.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
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
 *
 
25
 *
 
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.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#ifndef nsTemplateMatch_h__
 
41
#define nsTemplateMatch_h__
 
42
 
 
43
#include "nsFixedSizeAllocator.h"
 
44
#include "nsResourceSet.h"
 
45
#include "nsRuleNetwork.h"
 
46
#include NEW_H
 
47
 
 
48
/**
 
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
 
51
 * condition elements.
 
52
 *
 
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.
 
56
 */
 
57
 
 
58
class nsConflictSet;
 
59
class nsTemplateRule;
 
60
 
 
61
class nsTemplateMatch {
 
62
private:
 
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) {}
 
67
 
 
68
protected:
 
69
    PRInt32 mRefCnt;
 
70
 
 
71
    nsTemplateMatch(const nsTemplateRule* aRule,
 
72
                    const Instantiation& aInstantiation,
 
73
                    const nsAssignmentSet& aAssignments)
 
74
        : mRefCnt(0),
 
75
          mRule(aRule),
 
76
          mInstantiation(aInstantiation),
 
77
          mAssignments(aAssignments) {}
 
78
 
 
79
public:
 
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; }
 
87
 
 
88
    static void
 
89
    Destroy(nsFixedSizeAllocator& aPool, nsTemplateMatch* aMatch) {
 
90
        aMatch->~nsTemplateMatch();
 
91
        aPool.Free(aMatch, sizeof(*aMatch)); }
 
92
 
 
93
    PRBool operator==(const nsTemplateMatch& aMatch) const {
 
94
        return mRule == aMatch.mRule && mInstantiation == aMatch.mInstantiation; }
 
95
 
 
96
    PRBool operator!=(const nsTemplateMatch& aMatch) const {
 
97
        return !(*this == aMatch); }
 
98
 
 
99
    /**
 
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
 
105
     *   aVariable.
 
106
     * @return PR_TRUE if aVariable has an assignment, PR_FALSE otherwise.
 
107
     */
 
108
    PRBool GetAssignmentFor(nsConflictSet& aConflictSet, PRInt32 aVariable, Value* aValue);
 
109
 
 
110
    /**
 
111
     * The rule that this match applies for.
 
112
     */
 
113
    const nsTemplateRule* mRule;
 
114
 
 
115
    /**
 
116
     * The fully bound instantiation (variable-to-value assignments, with
 
117
     * memory element support) that match the rule's conditions.
 
118
     */
 
119
    Instantiation mInstantiation;
 
120
 
 
121
    /**
 
122
     * Any additional assignments that apply because of the rule's
 
123
     * bindings. These are computed lazily.
 
124
     */
 
125
    nsAssignmentSet mAssignments;
 
126
 
 
127
    /**
 
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
 
132
     * rule's bindings.
 
133
     */
 
134
    nsResourceSet mBindingDependencies;
 
135
 
 
136
    PRInt32 AddRef() {
 
137
        ++mRefCnt;
 
138
        NS_LOG_ADDREF(this, mRefCnt, "nsTemplateMatch", sizeof(*this));
 
139
        return mRefCnt; }
 
140
 
 
141
    PRInt32 Release(nsFixedSizeAllocator& aPool) {
 
142
        NS_PRECONDITION(mRefCnt > 0, "bad refcnt");
 
143
        PRInt32 refcnt = --mRefCnt;
 
144
        NS_LOG_RELEASE(this, mRefCnt, "nsTemplateMatch");
 
145
        if (refcnt == 0)
 
146
            Destroy(aPool, this);
 
147
        return refcnt; }
 
148
 
 
149
private:
 
150
    nsTemplateMatch(const nsTemplateMatch& aMatch); // not to be implemented
 
151
    void operator=(const nsTemplateMatch& aMatch); // not to be implemented
 
152
};
 
153
 
 
154
#endif // nsConflictSet_h__
 
155