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

Last change on this file since 317 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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;