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_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 |
|
---|
69 | QT_BEGIN_HEADER
|
---|
70 |
|
---|
71 | QT_BEGIN_NAMESPACE
|
---|
72 |
|
---|
73 | namespace 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 | * @param context may be @c null.
|
---|
94 | */
|
---|
95 | AccelTreeBuilder(const QUrl &docURI,
|
---|
96 | const QUrl &baseURI,
|
---|
97 | const NamePool::Ptr &np,
|
---|
98 | ReportContext *const context);
|
---|
99 | virtual void startDocument();
|
---|
100 | virtual void endDocument();
|
---|
101 | virtual void startElement(const QXmlName &name);
|
---|
102 | virtual void endElement();
|
---|
103 | virtual void attribute(const QXmlName &name, const QStringRef &value);
|
---|
104 | virtual void characters(const QStringRef &ch);
|
---|
105 | virtual void whitespaceOnly(const QStringRef &ch);
|
---|
106 | virtual void processingInstruction(const QXmlName &target,
|
---|
107 | const QString &data);
|
---|
108 | virtual void namespaceBinding(const QXmlName &nb);
|
---|
109 | virtual void comment(const QString &content);
|
---|
110 | virtual void item(const Item &it);
|
---|
111 |
|
---|
112 | virtual QAbstractXmlNodeModel::Ptr builtDocument();
|
---|
113 | virtual NodeBuilder::Ptr create(const QUrl &baseURI) const;
|
---|
114 | virtual void startOfSequence();
|
---|
115 | virtual void endOfSequence();
|
---|
116 |
|
---|
117 | inline AccelTree::Ptr builtDocument() const
|
---|
118 | {
|
---|
119 | return m_document;
|
---|
120 | }
|
---|
121 |
|
---|
122 | virtual void atomicValue(const QVariant &value);
|
---|
123 |
|
---|
124 | virtual const SourceLocationReflection *actualReflection() const;
|
---|
125 | virtual QSourceLocation sourceLocation() const;
|
---|
126 |
|
---|
127 | private:
|
---|
128 | inline void startStructure();
|
---|
129 |
|
---|
130 | inline AccelTree::PreNumber currentDepth() const
|
---|
131 | {
|
---|
132 | return m_ancestors.count() -1;
|
---|
133 | }
|
---|
134 |
|
---|
135 | inline AccelTree::PreNumber currentParent() const
|
---|
136 | {
|
---|
137 | return m_ancestors.isEmpty() ? -1 : m_ancestors.top();
|
---|
138 | }
|
---|
139 |
|
---|
140 | enum Constants
|
---|
141 | {
|
---|
142 | DefaultNodeStackSize = 10,
|
---|
143 | SizeIsEmpty = 0
|
---|
144 | };
|
---|
145 |
|
---|
146 | AccelTree::PreNumber m_preNumber;
|
---|
147 | bool m_isPreviousAtomic;
|
---|
148 | bool m_hasCharacters;
|
---|
149 | /**
|
---|
150 | * Whether m_characters has been run through
|
---|
151 | * CompressedWhitespace::compress().
|
---|
152 | */
|
---|
153 | bool m_isCharactersCompressed;
|
---|
154 | QString m_characters;
|
---|
155 | NamePool::Ptr m_namePool;
|
---|
156 | AccelTree::Ptr m_document;
|
---|
157 | QStack<AccelTree::PreNumber> m_ancestors;
|
---|
158 | QStack<AccelTree::PreNumber> m_size;
|
---|
159 |
|
---|
160 | /** If we have already commenced a document, we don't want to
|
---|
161 | * add more document nodes. We keep track of them with this
|
---|
162 | * counter, which ensures that startDocument() and endDocument()
|
---|
163 | * are skipped consistently. */
|
---|
164 | AccelTree::PreNumber m_skippedDocumentNodes;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * All attribute values goes through this set such that we store only
|
---|
168 | * one QString for identical attribute values.
|
---|
169 | */
|
---|
170 | QSet<QString> m_attributeCompress;
|
---|
171 | const QUrl m_documentURI;
|
---|
172 | /**
|
---|
173 | * We don't store a reference pointer here because then we get a
|
---|
174 | * circular reference with GenericDynamicContext, when it stores us as
|
---|
175 | * a member.
|
---|
176 | */
|
---|
177 | ReportContext *const m_context;
|
---|
178 | };
|
---|
179 |
|
---|
180 | #include "qacceltreebuilder.cpp"
|
---|
181 | }
|
---|
182 |
|
---|
183 | QT_END_NAMESPACE
|
---|
184 |
|
---|
185 | QT_END_HEADER
|
---|
186 |
|
---|
187 | #endif
|
---|