Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / xul / templates / src / nsXMLBinding.h
bloba304e1172c06f0715322eb2e63e459849d72c0f1
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is Neil Deakin
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either of the GNU General Public License Version 2 or later (the "GPL"),
25 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsXMLBinding_h__
38 #define nsXMLBinding_h__
40 #include "nsAutoPtr.h"
41 #include "nsIAtom.h"
43 class nsXULTemplateResultXML;
44 class nsXMLBindingValues;
46 /**
47 * Classes related to storing bindings for XML handling.
50 /**
51 * a <binding> description
53 struct nsXMLBinding {
54 nsCOMPtr<nsIAtom> mVar;
55 nsCOMPtr<nsIDOMXPathExpression> mExpr;
57 nsAutoPtr<nsXMLBinding> mNext;
59 nsXMLBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr)
60 : mVar(aVar), mExpr(aExpr), mNext(nsnull)
62 MOZ_COUNT_CTOR(nsXMLBinding);
65 ~nsXMLBinding()
67 MOZ_COUNT_DTOR(nsXMLBinding);
71 /**
72 * a collection of <binding> descriptors. This object is refcounted by
73 * nsXMLBindingValues objects and the query processor.
75 class nsXMLBindingSet
77 public:
79 // results hold a reference to a binding set in their
80 // nsXMLBindingValues fields
81 nsAutoRefCnt mRefCnt;
83 // pointer to the first binding in a linked list
84 nsAutoPtr<nsXMLBinding> mFirst;
86 public:
88 NS_IMETHOD_(nsrefcnt) AddRef();
89 NS_IMETHOD_(nsrefcnt) Release();
90 NS_DECL_OWNINGTHREAD
92 /**
93 * Add a binding to the set
95 nsresult
96 AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr);
98 /**
99 * The nsXMLBindingValues class stores an array of values, one for each
100 * target symbol that could be set by the bindings in the set.
101 * LookupTargetIndex determines the index into the array for a given
102 * target symbol.
104 PRInt32
105 LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding);
109 * a set of values of bindings. This object is used once per result.
111 class nsXMLBindingValues
113 protected:
115 // the binding set
116 nsRefPtr<nsXMLBindingSet> mBindings;
119 * A set of values for variable bindings. To look up a binding value,
120 * scan through the binding set in mBindings for the right target atom.
121 * Its index will correspond to the index in this array.
123 nsCOMArray<nsIDOMXPathResult> mValues;
125 public:
127 nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues); }
128 ~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues); }
130 nsXMLBindingSet* GetBindingSet() { return mBindings; }
132 void SetBindingSet(nsXMLBindingSet* aBindings) { mBindings = aBindings; }
134 PRInt32
135 LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding)
137 return mBindings ?
138 mBindings->LookupTargetIndex(aTargetVariable, aBinding) : -1;
142 * Retrieve the assignment for a particular variable
144 * aResult the result generated from the template
145 * aBinding the binding looked up using LookupTargetIndex
146 * aIndex the index of the assignment to retrieve
147 * aType the type of result expected
148 * aValue the value of the assignment
150 void
151 GetAssignmentFor(nsXULTemplateResultXML* aResult,
152 nsXMLBinding* aBinding,
153 PRInt32 idx,
154 PRUint16 type,
155 nsIDOMXPathResult** aValue);
157 void
158 GetNodeAssignmentFor(nsXULTemplateResultXML* aResult,
159 nsXMLBinding* aBinding,
160 PRInt32 idx,
161 nsIDOMNode** aValue);
163 void
164 GetStringAssignmentFor(nsXULTemplateResultXML* aResult,
165 nsXMLBinding* aBinding,
166 PRInt32 idx,
167 nsAString& aValue);
170 #endif // nsXMLBinding_h__