1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
52 #ifndef Patternist_DynamicContext_H
53 #define Patternist_DynamicContext_H
55 #include <private/qautoptr_p.h>
56 #include <private/qcachecells_p.h>
57 #include <private/qexternalvariableloader_p.h>
58 #include <private/qitem_p.h>
59 #include <private/qnamepool_p.h>
60 #include <private/qnodebuilder_p.h>
61 #include <private/qprimitives_p.h>
62 #include <private/qreportcontext_p.h>
63 #include <private/qresourceloader_p.h>
70 template<typename T> class QVector;
74 class DayTimeDuration;
79 * @short Carries information and facilities used at runtime, and hence
80 * provides a state for that stage in a thread-safe manner.
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>
88 class DynamicContext : public ReportContext
92 * @short Carries template parameters at runtime.
94 * The key is the name of the parameter, and the value the Expression
95 * which supplies the value.
97 typedef QHash<QXmlName, QExplicitlySharedDataPointer<Expression> > TemplateParameterHash;
98 typedef QExplicitlySharedDataPointer<DynamicContext> Ptr;
100 virtual ~DynamicContext()
105 * This function intentionally returns by reference.
107 * @see globalItemCacheCell()
109 virtual ItemCacheCell &itemCacheCell(const VariableSlotID slot) = 0;
112 * This function intentionally returns by reference.
114 * @see globalItemSequenceCacheCells
116 virtual ItemSequenceCacheCell::Vector &itemSequenceCacheCells(const VariableSlotID slot) = 0;
118 virtual xsInteger contextPosition() const = 0;
119 virtual Item contextItem() const = 0;
120 virtual xsInteger contextSize() = 0;
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;
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;
134 virtual void setFocusIterator(const Item::Iterator::Ptr &it) = 0;
135 virtual Item::Iterator::Ptr focusIterator() const = 0;
137 virtual QExplicitlySharedDataPointer<DayTimeDuration> implicitTimezone() const = 0;
138 virtual QDateTime currentDateTime() const = 0;
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;
147 * @short Returns the item that @c fn:current() returns.
149 * Hence, this is not the focus, and very different from the focus.
151 * @see CurrentItemStore
154 virtual Item currentItem() const = 0;
156 DynamicContext::Ptr createFocus();
157 DynamicContext::Ptr createStack();
158 DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver);
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.
165 * I think this is currently only used for temporary node trees. In
166 * other cases they are stored in the ExternalResourceLoader.
168 * The caller guarantees that @p nm is not @c null.
170 virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm) = 0;
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.
180 * This has two effects:
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
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.
189 virtual ItemCacheCell &globalItemCacheCell(const VariableSlotID slot) = 0;
192 * @short When a template is called, this member carries the template
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
201 virtual TemplateParameterHash &templateParameterStore() = 0;
204 * Same as itemSequenceCacheCells() but applies only for global
207 * @see globalItemCacheCell()
209 virtual ItemSequenceCacheCell::Vector &globalItemSequenceCacheCells(const VariableSlotID slot) = 0;
212 * @short Returns the previous DynamicContext. If this context is the
213 * top-level one, @c null is returned.
215 virtual DynamicContext::Ptr previousContext() const = 0;
218 * @short Returns the current template mode that is in effect.
220 * If @c null is returned, it means that the default mode should be
221 * used as the current mode.
223 virtual QExplicitlySharedDataPointer<TemplateMode> currentTemplateMode() const = 0;