|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
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 nsXMLBinding_h__ |
|
7 #define nsXMLBinding_h__ |
|
8 |
|
9 #include "nsAutoPtr.h" |
|
10 #include "nsIAtom.h" |
|
11 #include "nsCycleCollectionParticipant.h" |
|
12 #include "mozilla/Attributes.h" |
|
13 |
|
14 class nsXULTemplateResultXML; |
|
15 class nsXMLBindingValues; |
|
16 |
|
17 /** |
|
18 * Classes related to storing bindings for XML handling. |
|
19 */ |
|
20 |
|
21 /** |
|
22 * a <binding> description |
|
23 */ |
|
24 struct nsXMLBinding { |
|
25 nsCOMPtr<nsIAtom> mVar; |
|
26 nsCOMPtr<nsIDOMXPathExpression> mExpr; |
|
27 |
|
28 nsAutoPtr<nsXMLBinding> mNext; |
|
29 |
|
30 nsXMLBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr) |
|
31 : mVar(aVar), mExpr(aExpr), mNext(nullptr) |
|
32 { |
|
33 MOZ_COUNT_CTOR(nsXMLBinding); |
|
34 } |
|
35 |
|
36 ~nsXMLBinding() |
|
37 { |
|
38 MOZ_COUNT_DTOR(nsXMLBinding); |
|
39 } |
|
40 }; |
|
41 |
|
42 /** |
|
43 * a collection of <binding> descriptors. This object is refcounted by |
|
44 * nsXMLBindingValues objects and the query processor. |
|
45 */ |
|
46 class nsXMLBindingSet MOZ_FINAL |
|
47 { |
|
48 public: |
|
49 |
|
50 // results hold a reference to a binding set in their |
|
51 // nsXMLBindingValues fields |
|
52 nsCycleCollectingAutoRefCnt mRefCnt; |
|
53 |
|
54 // pointer to the first binding in a linked list |
|
55 nsAutoPtr<nsXMLBinding> mFirst; |
|
56 |
|
57 public: |
|
58 |
|
59 NS_METHOD_(MozExternalRefCountType) AddRef(); |
|
60 NS_METHOD_(MozExternalRefCountType) Release(); |
|
61 NS_DECL_OWNINGTHREAD |
|
62 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet) |
|
63 |
|
64 /** |
|
65 * Add a binding to the set |
|
66 */ |
|
67 nsresult |
|
68 AddBinding(nsIAtom* aVar, nsIDOMXPathExpression* aExpr); |
|
69 |
|
70 /** |
|
71 * The nsXMLBindingValues class stores an array of values, one for each |
|
72 * target symbol that could be set by the bindings in the set. |
|
73 * LookupTargetIndex determines the index into the array for a given |
|
74 * target symbol. |
|
75 */ |
|
76 int32_t |
|
77 LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding); |
|
78 }; |
|
79 |
|
80 /** |
|
81 * a set of values of bindings. This object is used once per result. |
|
82 */ |
|
83 class nsXMLBindingValues |
|
84 { |
|
85 protected: |
|
86 |
|
87 // the binding set |
|
88 nsRefPtr<nsXMLBindingSet> mBindings; |
|
89 |
|
90 /** |
|
91 * A set of values for variable bindings. To look up a binding value, |
|
92 * scan through the binding set in mBindings for the right target atom. |
|
93 * Its index will correspond to the index in this array. |
|
94 */ |
|
95 nsCOMArray<nsIDOMXPathResult> mValues; |
|
96 |
|
97 public: |
|
98 |
|
99 nsXMLBindingValues() { MOZ_COUNT_CTOR(nsXMLBindingValues); } |
|
100 ~nsXMLBindingValues() { MOZ_COUNT_DTOR(nsXMLBindingValues); } |
|
101 |
|
102 nsXMLBindingSet* GetBindingSet() { return mBindings; } |
|
103 |
|
104 void SetBindingSet(nsXMLBindingSet* aBindings) { mBindings = aBindings; } |
|
105 |
|
106 int32_t |
|
107 LookupTargetIndex(nsIAtom* aTargetVariable, nsXMLBinding** aBinding) |
|
108 { |
|
109 return mBindings ? |
|
110 mBindings->LookupTargetIndex(aTargetVariable, aBinding) : -1; |
|
111 } |
|
112 |
|
113 /** |
|
114 * Retrieve the assignment for a particular variable |
|
115 * |
|
116 * aResult the result generated from the template |
|
117 * aBinding the binding looked up using LookupTargetIndex |
|
118 * aIndex the index of the assignment to retrieve |
|
119 * aType the type of result expected |
|
120 * aValue the value of the assignment |
|
121 */ |
|
122 void |
|
123 GetAssignmentFor(nsXULTemplateResultXML* aResult, |
|
124 nsXMLBinding* aBinding, |
|
125 int32_t idx, |
|
126 uint16_t type, |
|
127 nsIDOMXPathResult** aValue); |
|
128 |
|
129 void |
|
130 GetNodeAssignmentFor(nsXULTemplateResultXML* aResult, |
|
131 nsXMLBinding* aBinding, |
|
132 int32_t idx, |
|
133 nsIDOMNode** aValue); |
|
134 |
|
135 void |
|
136 GetStringAssignmentFor(nsXULTemplateResultXML* aResult, |
|
137 nsXMLBinding* aBinding, |
|
138 int32_t idx, |
|
139 nsAString& aValue); |
|
140 }; |
|
141 |
|
142 #endif // nsXMLBinding_h__ |