author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 <frans.englich@nokia.com> |
|
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 |
||
200 |
QT_END_NAMESPACE |
|
201 |
||
202 |
QT_END_HEADER |
|
203 |
||
204 |
#endif |