|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 // |
|
43 // W A R N I N G |
|
44 // ------------- |
|
45 // |
|
46 // This file is not part of the Qt API. It exists purely as an |
|
47 // implementation detail. This header file may change from version to |
|
48 // version without notice, or even be removed. |
|
49 // |
|
50 // We mean it. |
|
51 |
|
52 #ifndef Patternist_DynamicContext_H |
|
53 #define Patternist_DynamicContext_H |
|
54 |
|
55 #include "qautoptr_p.h" |
|
56 #include "qcachecells_p.h" |
|
57 #include "qexternalvariableloader_p.h" |
|
58 #include "qitem_p.h" |
|
59 #include "qnamepool_p.h" |
|
60 #include "qnodebuilder_p.h" |
|
61 #include "qprimitives_p.h" |
|
62 #include "qreportcontext_p.h" |
|
63 #include "qresourceloader_p.h" |
|
64 |
|
65 QT_BEGIN_HEADER |
|
66 |
|
67 QT_BEGIN_NAMESPACE |
|
68 |
|
69 class QDateTime; |
|
70 template<typename T> class QVector; |
|
71 |
|
72 namespace QPatternist |
|
73 { |
|
74 class DayTimeDuration; |
|
75 class Expression; |
|
76 class TemplateMode; |
|
77 |
|
78 /** |
|
79 * @short Carries information and facilities used at runtime, and hence |
|
80 * provides a state for that stage in a thread-safe manner. |
|
81 * |
|
82 * @see <a href="http://www.w3.org/TR/xquery/#eval_context">XQuery |
|
83 * 1.0: An XML Query Language, 2.1.2 Dynamic Context</a> |
|
84 * @see <a href="http://www.w3.org/TR/xquery/#id-dynamic-evaluation">XQuery |
|
85 * 1.0: An XML Query Language, 2.2.3.2 Dynamic Evaluation Phase</a> |
|
86 * @author Frans Englich <frans.englich@nokia.com> |
|
87 */ |
|
88 class DynamicContext : public ReportContext |
|
89 { |
|
90 public: |
|
91 /** |
|
92 * @short Carries template parameters at runtime. |
|
93 * |
|
94 * The key is the name of the parameter, and the value the Expression |
|
95 * which supplies the value. |
|
96 */ |
|
97 typedef QHash<QXmlName, QExplicitlySharedDataPointer<Expression> > TemplateParameterHash; |
|
98 typedef QExplicitlySharedDataPointer<DynamicContext> Ptr; |
|
99 |
|
100 virtual ~DynamicContext() |
|
101 { |
|
102 } |
|
103 |
|
104 /** |
|
105 * This function intentionally returns by reference. |
|
106 * |
|
107 * @see globalItemCacheCell() |
|
108 */ |
|
109 virtual ItemCacheCell &itemCacheCell(const VariableSlotID slot) = 0; |
|
110 |
|
111 /** |
|
112 * This function intentionally returns by reference. |
|
113 * |
|
114 * @see globalItemSequenceCacheCells |
|
115 */ |
|
116 virtual ItemSequenceCacheCell::Vector &itemSequenceCacheCells(const VariableSlotID slot) = 0; |
|
117 |
|
118 virtual xsInteger contextPosition() const = 0; |
|
119 virtual Item contextItem() const = 0; |
|
120 virtual xsInteger contextSize() = 0; |
|
121 |
|
122 virtual void setRangeVariable(const VariableSlotID slot, |
|
123 const Item &newValue) = 0; |
|
124 virtual Item rangeVariable(const VariableSlotID slot) const = 0; |
|
125 virtual void setExpressionVariable(const VariableSlotID slot, |
|
126 const QExplicitlySharedDataPointer<Expression> &newValue) = 0; |
|
127 virtual QExplicitlySharedDataPointer<Expression> |
|
128 expressionVariable(const VariableSlotID slot) const = 0; |
|
129 |
|
130 virtual Item::Iterator::Ptr positionIterator(const VariableSlotID slot) const = 0; |
|
131 virtual void setPositionIterator(const VariableSlotID slot, |
|
132 const Item::Iterator::Ptr &newValue) = 0; |
|
133 |
|
134 virtual void setFocusIterator(const Item::Iterator::Ptr &it) = 0; |
|
135 virtual Item::Iterator::Ptr focusIterator() const = 0; |
|
136 |
|
137 virtual QExplicitlySharedDataPointer<DayTimeDuration> implicitTimezone() const = 0; |
|
138 virtual QDateTime currentDateTime() const = 0; |
|
139 |
|
140 virtual QAbstractXmlReceiver *outputReceiver() const = 0; |
|
141 virtual NodeBuilder::Ptr nodeBuilder(const QUrl &baseURI) const = 0; |
|
142 virtual ResourceLoader::Ptr resourceLoader() const = 0; |
|
143 virtual ExternalVariableLoader::Ptr externalVariableLoader() const = 0; |
|
144 virtual NamePool::Ptr namePool() const = 0; |
|
145 |
|
146 /** |
|
147 * @short Returns the item that @c fn:current() returns. |
|
148 * |
|
149 * Hence, this is not the focus, and very different from the focus. |
|
150 * |
|
151 * @see CurrentItemStore |
|
152 * @see CurrentFN |
|
153 */ |
|
154 virtual Item currentItem() const = 0; |
|
155 |
|
156 DynamicContext::Ptr createFocus(); |
|
157 DynamicContext::Ptr createStack(); |
|
158 DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver); |
|
159 |
|
160 /** |
|
161 * Whenever a tree gets built, this function is called. DynamicContext |
|
162 * has the responsibility of keeping a copy of @p nm, such that it |
|
163 * doesn't go out of scope, since no one else will reference @p nm. |
|
164 * |
|
165 * I think this is currently only used for temporary node trees. In |
|
166 * other cases they are stored in the ExternalResourceLoader. |
|
167 * |
|
168 * The caller guarantees that @p nm is not @c null. |
|
169 */ |
|
170 virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm) = 0; |
|
171 |
|
172 /** |
|
173 * Same as itemCacheCell(), but is only used for global varibles. This |
|
174 * is needed because sometimes stack frames needs to be created for |
|
175 * other kinds of variables(such as in the case of user function |
|
176 * calls), while the global variable(s) needs to continue to use the |
|
177 * same cache, instead of one for each new stack frame, typically an |
|
178 * instance of StackContextBase. |
|
179 * |
|
180 * This has two effects: |
|
181 * |
|
182 * - It's an optimization. Instead of that a global variable gets evaluated each |
|
183 * time a user function is called, think recursive functions, it's done |
|
184 * only once. |
|
185 * - Query stability, hence affects things like node identity and |
|
186 * therefore conformance. Hence affects for instance what nodes a query |
|
187 * returns, since node identity affect node deduplication. |
|
188 */ |
|
189 virtual ItemCacheCell &globalItemCacheCell(const VariableSlotID slot) = 0; |
|
190 |
|
191 /** |
|
192 * @short When a template is called, this member carries the template |
|
193 * parameters. |
|
194 * |
|
195 * Hence this is similar to the other variable stack functions such as |
|
196 * rangeVariable() and expressionVariable(), the difference being that |
|
197 * the order of template parameters as well as its arguments can appear |
|
198 * in arbitrary order. Hence the name is used to make the order |
|
199 * insignificant. |
|
200 */ |
|
201 virtual TemplateParameterHash &templateParameterStore() = 0; |
|
202 |
|
203 /** |
|
204 * Same as itemSequenceCacheCells() but applies only for global |
|
205 * variables. |
|
206 * |
|
207 * @see globalItemCacheCell() |
|
208 */ |
|
209 virtual ItemSequenceCacheCell::Vector &globalItemSequenceCacheCells(const VariableSlotID slot) = 0; |
|
210 |
|
211 /** |
|
212 * @short Returns the previous DynamicContext. If this context is the |
|
213 * top-level one, @c null is returned. |
|
214 */ |
|
215 virtual DynamicContext::Ptr previousContext() const = 0; |
|
216 |
|
217 /** |
|
218 * @short Returns the current template mode that is in effect. |
|
219 * |
|
220 * If @c null is returned, it means that the default mode should be |
|
221 * used as the current mode. |
|
222 */ |
|
223 virtual QExplicitlySharedDataPointer<TemplateMode> currentTemplateMode() const = 0; |
|
224 }; |
|
225 } |
|
226 |
|
227 QT_END_NAMESPACE |
|
228 |
|
229 QT_END_HEADER |
|
230 |
|
231 #endif |