source: trunk/src/xmlpatterns/acceltree/qacceltreebuilder_p.h@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 7.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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_AccelTreeBuilder_H
53#define Patternist_AccelTreeBuilder_H
54
55#include <QSet>
56#include <QStack>
57
58#include "private/qxmlutils_p.h"
59#include "qacceltree_p.h"
60#include "qbuiltintypes_p.h"
61#include "qcompressedwhitespace_p.h"
62#include "qnamepool_p.h"
63#include "qnodebuilder_p.h"
64#include "qreportcontext_p.h"
65#include "qsourcelocationreflection_p.h"
66#include "qpatternistlocale_p.h"
67#include <QtDebug>
68
69QT_BEGIN_HEADER
70
71QT_BEGIN_NAMESPACE
72
73namespace QPatternist
74{
75 /**
76 * @short Builds an AccelTree from a stream of XML/Item events
77 * received through the NodeBuilder interface.
78 *
79 * If FromDocument is @c true, it is assumed that AccelTreeBuilder is fed
80 * events from an XML document, otherwise it is assumed the events
81 * are from node constructor expressions.
82 *
83 * @author Frans Englich <[email protected]>
84 */
85 template<bool FromDocument>
86 class AccelTreeBuilder : public NodeBuilder
87 , public SourceLocationReflection
88 {
89 public:
90 typedef QExplicitlySharedDataPointer<AccelTreeBuilder> Ptr;
91
92 /**
93 * Describes the memory relevant features the builder shall support.
94 */
95 enum Feature
96 {
97 NoneFeature, ///< No special features are enabled.
98 SourceLocationsFeature = 1 ///< The accel tree builder will store source locations for each start element.
99 };
100 Q_DECLARE_FLAGS(Features, Feature)
101
102 /**
103 * @param context may be @c null.
104 */
105 AccelTreeBuilder(const QUrl &docURI,
106 const QUrl &baseURI,
107 const NamePool::Ptr &np,
108 ReportContext *const context,
109 Features features = NoneFeature);
110 virtual void startDocument();
111 virtual void endDocument();
112 virtual void startElement(const QXmlName &name);
113 void startElement(const QXmlName &name, qint64 line, qint64 column);
114 virtual void endElement();
115 virtual void attribute(const QXmlName &name, const QStringRef &value);
116 virtual void characters(const QStringRef &ch);
117 virtual void whitespaceOnly(const QStringRef &ch);
118 virtual void processingInstruction(const QXmlName &target,
119 const QString &data);
120 virtual void namespaceBinding(const QXmlName &nb);
121 virtual void comment(const QString &content);
122 virtual void item(const Item &it);
123
124 virtual QAbstractXmlNodeModel::Ptr builtDocument();
125 virtual NodeBuilder::Ptr create(const QUrl &baseURI) const;
126 virtual void startOfSequence();
127 virtual void endOfSequence();
128
129 inline AccelTree::Ptr builtDocument() const
130 {
131 return m_document;
132 }
133
134 virtual void atomicValue(const QVariant &value);
135
136 virtual const SourceLocationReflection *actualReflection() const;
137 virtual QSourceLocation sourceLocation() const;
138
139 private:
140 inline void startStructure();
141
142 inline AccelTree::PreNumber currentDepth() const
143 {
144 return m_ancestors.count() -1;
145 }
146
147 inline AccelTree::PreNumber currentParent() const
148 {
149 return m_ancestors.isEmpty() ? -1 : m_ancestors.top();
150 }
151
152 enum Constants
153 {
154 DefaultNodeStackSize = 10,
155 SizeIsEmpty = 0
156 };
157
158 AccelTree::PreNumber m_preNumber;
159 bool m_isPreviousAtomic;
160 bool m_hasCharacters;
161 /**
162 * Whether m_characters has been run through
163 * CompressedWhitespace::compress().
164 */
165 bool m_isCharactersCompressed;
166 QString m_characters;
167 NamePool::Ptr m_namePool;
168 AccelTree::Ptr m_document;
169 QStack<AccelTree::PreNumber> m_ancestors;
170 QStack<AccelTree::PreNumber> m_size;
171
172 /** If we have already commenced a document, we don't want to
173 * add more document nodes. We keep track of them with this
174 * counter, which ensures that startDocument() and endDocument()
175 * are skipped consistently. */
176 AccelTree::PreNumber m_skippedDocumentNodes;
177
178 /**
179 * All attribute values goes through this set such that we store only
180 * one QString for identical attribute values.
181 */
182 QSet<QString> m_attributeCompress;
183 const QUrl m_documentURI;
184 /**
185 * We don't store a reference pointer here because then we get a
186 * circular reference with GenericDynamicContext, when it stores us as
187 * a member.
188 */
189 ReportContext *const m_context;
190
191 Features m_features;
192 };
193
194 Q_DECLARE_OPERATORS_FOR_FLAGS(AccelTreeBuilder<true>::Features)
195 Q_DECLARE_OPERATORS_FOR_FLAGS(AccelTreeBuilder<false>::Features)
196
197#include "qacceltreebuilder.cpp"
198}
199
200QT_END_NAMESPACE
201
202QT_END_HEADER
203
204#endif
Note: See TracBrowser for help on using the repository browser.