source: trunk/src/xmlpatterns/expr/qevaluationcache_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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_EvaluationCache_H
53#define Patternist_EvaluationCache_H
54
55#include "qcachingiterator_p.h"
56#include "qcommonsequencetypes_p.h"
57#include "qnodebuilder_p.h"
58#include "qoperandsiterator_p.h"
59#include "qsinglecontainer_p.h"
60#include "qvariabledeclaration_p.h"
61
62QT_BEGIN_HEADER
63
64QT_BEGIN_NAMESPACE
65
66namespace QPatternist
67{
68 /**
69 * @short Evaluates to the same result as its operand, but ensures the
70 * operand is evaluated once even if this Expression is evaluated several
71 * times.
72 *
73 * EvaluationCache does this in a pipelined way, by delivering items from
74 * its cache, which is stored in the DynamicContext. If the cache has less
75 * items than what the caller requests, EvaluationCache continues to
76 * deliver but this time from the source, which it also populates into the
77 * cache.
78 *
79 * EvaluationCache is used as an optimization in order to avoid running
80 * expensive code paths multiple times, but also is sometimes a necessity:
81 * for instance, when objects must be unique, such as potentially in the
82 * case of node identity.
83 *
84 * EvaluationCache is in particular used for variables, whose sole purpose
85 * is to store it once(at least conceptually) and then use it in multiple
86 * places.
87 *
88 * In some cases an EvaluationCache isn't necessary. For instance, when a
89 * variable is only referenced once. In those cases EvaluationCache removes
90 * itself as an optimization; implemented in compress().
91 *
92 * @author Frans Englich <[email protected]>
93 * @ingroup Patternist_expressions
94 */
95 template<bool IsForGlobal>
96 class EvaluationCache : public SingleContainer
97 {
98 public:
99 EvaluationCache(const Expression::Ptr &operand,
100 const VariableDeclaration::Ptr &varDecl,
101 const VariableSlotID slot);
102
103 virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
104 virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
105 virtual Expression::Ptr compress(const StaticContext::Ptr &context);
106
107 virtual SequenceType::Ptr staticType() const;
108
109 /**
110 * The first operand must be exactly one @c xs:string.
111 */
112 virtual SequenceType::List expectedOperandTypes() const;
113
114 virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const;
115 virtual Properties properties() const;
116 virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
117 const SequenceType::Ptr &reqType);
118 virtual const SourceLocationReflection *actualReflection() const;
119
120 inline VariableSlotID slot() const
121 {
122 return m_varSlot;
123 }
124
125 private:
126 static DynamicContext::Ptr topFocusContext(const DynamicContext::Ptr &context);
127 const VariableDeclaration::Ptr m_declaration;
128 /**
129 * This variable must not be called m_slot. If it so, a compiler bug on
130 * HP-UX-aCC-64 is triggered in the constructor initializor. See the
131 * preprocessor output.
132 *
133 * Note that this is the cache slot, and is disjoint to any variable's
134 * regular slot.
135 */
136 const VariableSlotID m_varSlot;
137 };
138
139#include "qevaluationcache.cpp"
140}
141
142QT_END_NAMESPACE
143
144QT_END_HEADER
145
146#endif
Note: See TracBrowser for help on using the repository browser.