Qt 4.8
Public Types | Public Functions | Private Types | Private Functions | Properties | List of all members
QPatternist::AccelTreeBuilder< FromDocument > Class Template Reference

Builds an AccelTree from a stream of XML/Item events received through the NodeBuilder interface. More...

#include <qacceltree_p.h>

Inheritance diagram for QPatternist::AccelTreeBuilder< FromDocument >:
QPatternist::NodeBuilder QPatternist::SourceLocationReflection QPatternist::QAbstractXmlReceiver QSharedData

Public Types

enum  Feature { NoneFeature, SourceLocationsFeature = 1 }
 
typedef QExplicitlySharedDataPointer< AccelTreeBuilderPtr
 
- Public Types inherited from QPatternist::NodeBuilder
typedef AutoPtr< NodeBuilderPtr
 
- Public Types inherited from QPatternist::QAbstractXmlReceiver
typedef QExplicitlySharedDataPointer< QAbstractXmlReceiverPtr
 

Public Functions

 AccelTreeBuilder (const QUrl &docURI, const QUrl &baseURI, const NamePool::Ptr &np, ReportContext *const context, Features features=NoneFeature)
 
virtual const SourceLocationReflectionactualReflection () const
 
virtual void atomicValue (const QVariant &value)
 
virtual void attribute (const QXmlName &name, const QStringRef &value)
 
virtual QAbstractXmlNodeModel::Ptr builtDocument ()
 Returns the document that has been built. More...
 
AccelTree::Ptr builtDocument () const
 
virtual void characters (const QStringRef &ch)
 
virtual void comment (const QString &content)
 
virtual NodeBuilder::Ptr create (const QUrl &baseURI) const
 Creates a copy of this NodeBuilder, that operates independently of this NodeBuilder. More...
 
virtual void endDocument ()
 
virtual void endElement ()
 Signals the end of the current element. More...
 
virtual void endOfSequence ()
 
virtual void item (const Item &it)
 Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue. More...
 
virtual void namespaceBinding (const QXmlName &nb)
 Signals the presence of the namespace declaration nb. More...
 
virtual void processingInstruction (const QXmlName &target, const QString &data)
 
virtual QSourceLocation sourceLocation () const
 
virtual void startDocument ()
 
virtual void startElement (const QXmlName &name)
 
void startElement (const QXmlName &name, qint64 line, qint64 column)
 
virtual void startOfSequence ()
 
virtual void whitespaceOnly (const QStringRef &ch)
 
- Public Functions inherited from QPatternist::NodeBuilder
 NodeBuilder ()
 
- Public Functions inherited from QPatternist::QAbstractXmlReceiver
virtual void attribute (const QXmlName name, const QString &value)=0
 Signals the presence of an attribute node. More...
 
virtual void characters (const QString &value)=0
 
virtual void processingInstruction (const QXmlName name, const QString &value)=0
 
 QAbstractXmlReceiver ()
 
virtual void startElement (const QXmlName name)=0
 Signals the start of an element by name name. More...
 
virtual ~QAbstractXmlReceiver ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QString description () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Private Types

enum  Constants { DefaultNodeStackSize = 10, SizeIsEmpty = 0 }
 

Private Functions

AccelTree::PreNumber currentDepth () const
 
AccelTree::PreNumber currentParent () const
 
void startStructure ()
 

Properties

QStack< AccelTree::PreNumberm_ancestors
 
QSet< QStringm_attributeCompress
 
QString m_characters
 
ReportContext *const m_context
 
AccelTree::Ptr m_document
 
const QUrl m_documentURI
 
Features m_features
 
bool m_hasCharacters
 
bool m_isCharactersCompressed
 
bool m_isPreviousAtomic
 
NamePool::Ptr m_namePool
 
AccelTree::PreNumber m_preNumber
 
QStack< AccelTree::PreNumberm_size
 
AccelTree::PreNumber m_skippedDocumentNodes
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::QAbstractXmlReceiver
void sendAsNode (const Item &outputItem)
 

Detailed Description

template<bool FromDocument>
class QPatternist::AccelTreeBuilder< FromDocument >

Builds an AccelTree from a stream of XML/Item events received through the NodeBuilder interface.

If FromDocument is true, it is assumed that AccelTreeBuilder is fed events from an XML document, otherwise it is assumed the events are from node constructor expressions.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 69 of file qacceltree_p.h.

Typedefs

◆ Ptr

template<bool FromDocument>
typedef QExplicitlySharedDataPointer<AccelTreeBuilder> QPatternist::AccelTreeBuilder< FromDocument >::Ptr

Definition at line 90 of file qacceltreebuilder_p.h.

Enumerations

◆ Constants

template<bool FromDocument>
enum QPatternist::AccelTreeBuilder::Constants
private
Enumerator
DefaultNodeStackSize 
SizeIsEmpty 

Definition at line 152 of file qacceltreebuilder_p.h.

◆ Feature

template<bool FromDocument>
enum QPatternist::AccelTreeBuilder::Feature

Describes the memory relevant features the builder shall support.

Enumerator
NoneFeature 

No special features are enabled.

SourceLocationsFeature 

The accel tree builder will store source locations for each start element.

Definition at line 95 of file qacceltreebuilder_p.h.

96  {
97  NoneFeature,
99  };
The accel tree builder will store source locations for each start element.
No special features are enabled.

Constructors and Destructors

◆ AccelTreeBuilder()

template<bool FromDocument>
QPatternist::AccelTreeBuilder< FromDocument >::AccelTreeBuilder ( const QUrl docURI,
const QUrl baseURI,
const NamePool::Ptr np,
ReportContext *const  context,
Features  features = NoneFeature 
)
Parameters
contextmay be null.

Definition at line 49 of file qacceltreebuilder.cpp.

53  : m_preNumber(-1)
54  , m_isPreviousAtomic(false)
55  , m_hasCharacters(false)
57  , m_namePool(np)
58  , m_document(new AccelTree(docURI, baseURI))
60  , m_documentURI(docURI)
61  , m_context(context)
62  , m_features(features)
63 {
65 
66  /* TODO Perhaps we can merge m_ancestors and m_size
67  * into one, and store a struct for the two instead? */
69  m_ancestors.push(-1);
70 
72  m_size.push(0);
73 }
QStack< AccelTree::PreNumber > m_ancestors
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AccelTree::PreNumber m_skippedDocumentNodes
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QStack< AccelTree::PreNumber > m_size
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339

Functions

◆ actualReflection()

template<bool FromDocument>
const SourceLocationReflection * QPatternist::AccelTreeBuilder< FromDocument >::actualReflection ( ) const
virtual

Implements QPatternist::SourceLocationReflection.

Definition at line 427 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeBuilder< true >::builtDocument().

428 {
429  return this;
430 }

◆ atomicValue()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::atomicValue ( const QVariant value)
virtual

Definition at line 393 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeBuilder< true >::builtDocument().

394 {
395  Q_UNUSED(value);
396  // TODO
397 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ attribute()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::attribute ( const QXmlName name,
const QStringRef value 
)
virtual

In the case that we're called for doc-available(), m_context is null, and we need to flag somehow that we failed to load this document.

In the case that we're called for doc-available(), m_context is null, and we need to flag somehow that we failed to load this document.

Definition at line 178 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

179 {
180  /* Attributes adds a namespace binding, so lets synthesize one.
181  *
182  * We optimize by checking whether we have a namespace for which a binding would
183  * be generated. Happens relatively rarely. */
184  if(name.hasPrefix())
185  namespaceBinding(QXmlName(name.namespaceURI(), 0, name.prefix()));
186 
187  m_document->basicData.append(AccelTree::BasicNodeData(currentDepth(), currentParent(), QXmlNodeModelIndex::Attribute, 0, name));
188  ++m_preNumber;
189  ++m_size.top();
190 
191  m_isPreviousAtomic = false;
192 
194  {
195  const QString normalized(value.toString().simplified());
196 
197  if(QXmlUtils::isNCName(normalized))
198  {
199  const QXmlName::LocalNameCode id = m_namePool->allocateLocalName(normalized);
200 
201  const int oldSize = m_document->m_IDs.count();
202  m_document->m_IDs.insert(id, currentParent());
203  /* We don't run the value through m_attributeCompress here, because
204  * the likelyhood of it deing identical to another attribute is
205  * very small. */
206  m_document->data.insert(m_preNumber, normalized);
207 
213  if(oldSize == m_document->m_IDs.count() && m_context) // TODO
214  {
216  m_context->error(QtXmlPatterns::tr("An %1-attribute with value %2 has already been declared.")
217  .arg(formatKeyword("xml:id"),
218  formatData(normalized)),
220  this);
221  }
222  }
223  else if(m_context) // TODO
224  {
226 
227  /* If we're building from an XML Document(e.g, we're fed from QXmlStreamReader, we raise FODC0002,
228  * otherwise XQDY0091. */
229  m_context->error(QtXmlPatterns::tr("An %1-attribute must have a "
230  "valid %2 as value, which %3 isn't.").arg(formatKeyword("xml:id"),
232  formatData(value.toString())),
234  this);
235  }
236  }
237  else
239 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
QString formatKeyword(const QString &keyword)
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
bool hasPrefix() const
Returns true if this QXmlName has a non-empty prefix.
Definition: qnamepool_p.h:493
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
virtual void namespaceBinding(const QXmlName &nb)
Signals the presence of the namespace declaration nb.
const_iterator insert(const T &value)
Definition: qset.h:179
static QString formatData(const QString &data)
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QStack< AccelTree::PreNumber > m_size
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
static const AtomicType::Ptr xsNCName
AccelTree::PreNumber currentDepth() const
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
AccelTree::PreNumber currentParent() const
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ builtDocument() [1/2]

template<bool FromDocument>
QAbstractXmlNodeModel::Ptr QPatternist::AccelTreeBuilder< FromDocument >::builtDocument ( )
virtual

Returns the document that has been built.

If this function is called before any events have been received, the result is undefined.

The top node that was constructed can be retrieved by calling NodeModel::root() on the returned NodeModel.

This function is not const, because some implementations delay the node construction until the node is needed. Also, text nodes are difficult, at best, to construct until one knows that all text content has been received(which a call to this function in a natural way signals).

Implements QPatternist::NodeBuilder.

Definition at line 400 of file qacceltreebuilder.cpp.

401 {
402  /* Create a text node, if we have received text in some way. */
403  startStructure();
404  m_document->printStats(m_namePool);
405 
406  return m_document;
407 }

◆ builtDocument() [2/2]

template<bool FromDocument>
AccelTree::Ptr QPatternist::AccelTreeBuilder< FromDocument >::builtDocument ( ) const
inline

Definition at line 129 of file qacceltreebuilder_p.h.

130  {
131  return m_document;
132  }

◆ characters()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::characters ( const QStringRef ch)
virtual

Definition at line 242 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

243 {
244 
245  /* If a text node constructor appears by itself, a node needs to
246  * be created. Therefore, we set m_hasCharacters
247  * if we're the only node.
248  * However, if the text node appears as a child of a document or element
249  * node it is discarded if it's empty.
250  */
252  {
254  m_isCharactersCompressed = false;
255  }
256 
257  m_characters += ch;
258 
259  m_isPreviousAtomic = false;
260  m_hasCharacters = !m_characters.isEmpty() || m_preNumber == -1; /* -1 is our start value. */
261 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString decompress(const QString &input)
Decompresses input into a usual QString.

◆ comment()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::comment ( const QString content)
virtual

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 314 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

315 {
316  startStructure();
317  m_document->basicData.append(AccelTree::BasicNodeData(currentDepth(), currentParent(), QXmlNodeModelIndex::Comment, 0));
318  ++m_preNumber;
319  m_document->data.insert(m_preNumber, content);
320  ++m_size.top();
321 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QStack< AccelTree::PreNumber > m_size
AccelTree::PreNumber currentDepth() const
AccelTree::PreNumber currentParent() const
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ create()

template<bool FromDocument>
NodeBuilder::Ptr QPatternist::AccelTreeBuilder< FromDocument >::create ( const QUrl baseURI) const
virtual

Creates a copy of this NodeBuilder, that operates independently of this NodeBuilder.

The caller owns the returned instance.

Implements QPatternist::NodeBuilder.

Definition at line 410 of file qacceltreebuilder.cpp.

411 {
412  Q_UNUSED(baseURI);
413  return NodeBuilder::Ptr(new AccelTreeBuilder(QUrl(), baseURI, m_namePool, m_context));
414 }
AccelTreeBuilder(const QUrl &docURI, const QUrl &baseURI, const NamePool::Ptr &np, ReportContext *const context, Features features=NoneFeature)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
AutoPtr< NodeBuilder > Ptr
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ currentDepth()

template<bool FromDocument>
AccelTree::PreNumber QPatternist::AccelTreeBuilder< FromDocument >::currentDepth ( ) const
inlineprivate

Definition at line 142 of file qacceltreebuilder_p.h.

143  {
144  return m_ancestors.count() -1;
145  }
QStack< AccelTree::PreNumber > m_ancestors
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742

◆ currentParent()

template<bool FromDocument>
AccelTree::PreNumber QPatternist::AccelTreeBuilder< FromDocument >::currentParent ( ) const
inlineprivate

Definition at line 147 of file qacceltreebuilder_p.h.

148  {
149  return m_ancestors.isEmpty() ? -1 : m_ancestors.top();
150  }
QStack< AccelTree::PreNumber > m_ancestors
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ endDocument()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::endDocument ( )
virtual

End of a document node.

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 370 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

371 {
372  if(m_skippedDocumentNodes == 0)
373  {
374  /* Create text nodes, if we've received any. We do this only if we're the
375  * top node because if we're getting this event as being a child of an element,
376  * text nodes or atomic values can appear after us, and which must get
377  * merged with the previous text.
378  *
379  * We call startStructure() before we pop the ancestor, such that the text node becomes
380  * a child of this document node. */
381  startStructure();
382 
383  m_document->basicData.first().setSize(m_size.pop());
384  m_ancestors.pop();
385  }
386  else
388 
389  m_isPreviousAtomic = false;
390 }
QStack< AccelTree::PreNumber > m_ancestors
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
AccelTree::PreNumber m_skippedDocumentNodes
QStack< AccelTree::PreNumber > m_size

◆ endElement()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::endElement ( )
virtual

Signals the end of the current element.

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 163 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

164 {
165  startStructure();
167  AccelTree::BasicNodeData &data = m_document->basicData[index];
168 
169  /* Sub trees needs to be included in upper trees, so we add the count of this element
170  * to our parent. */
171  m_size[m_size.count() - 2] += m_size.top();
172 
173  data.setSize(m_size.pop());
174  m_isPreviousAtomic = false;
175 }
QStack< AccelTree::PreNumber > m_ancestors
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
static const char * data(const QByteArray &arr)
QStack< AccelTree::PreNumber > m_size
quint16 index
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ endOfSequence()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::endOfSequence ( )
virtual

Definition at line 422 of file qacceltreebuilder.cpp.

423 {
424 }

◆ item()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::item ( const Item item)
virtual

Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue.

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 101 of file qacceltreebuilder.cpp.

102 {
103  Q_ASSERT(it);
104 
105  if(it.isAtomicValue())
106  {
108  {
109  m_characters += QLatin1Char(' ');
110  m_characters += it.stringValue();
111  }
112  else
113  {
114  m_isPreviousAtomic = true;
115  const QString sv(it.stringValue());
116 
117  if(!sv.isEmpty())
118  {
119  m_characters += sv;
120  m_hasCharacters = true;
121  }
122  }
123  }
124  else
125  sendAsNode(it);
126 }
#define it(className, varName)
The QString class provides a Unicode character string.
Definition: qstring.h:83
void sendAsNode(const Item &outputItem)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ namespaceBinding()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::namespaceBinding ( const QXmlName nb)
virtual

Signals the presence of the namespace declaration nb.

This event is received after startElement(), as opposed to SAX, and before any attribute() events.

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 324 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

325 {
326  /* Note, because attribute() sometimes generate namespaceBinding() calls, this function
327  * can be called after attributes, in contrast to what the class documentation says. This is ok,
328  * as long as we're not dealing with public API. */
329 
330  /* If we've received attributes, it means the element's size have changed and m_preNumber have advanced,
331  * so "reverse back" to the actual element. */
333 
334  QVector<QXmlName> &nss = m_document->namespaces[pn];
335 
336  /* "xml" hasn't been declared for each node, AccelTree::namespaceBindings() adds it, so avoid it
337  * such that we don't get duplicates. */
338  if(nb.prefix() == StandardPrefixes::xml)
339  return;
340 
341  /* If we already have the binding, skip it. */
342  const int len = nss.count();
343  for(int i = 0; i < len; ++i)
344  {
345  if(nss.at(i).prefix() == nb.prefix())
346  return;
347  }
348 
349  nss.append(nb);
350 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QStack< AccelTree::PreNumber > m_size
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ processingInstruction()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::processingInstruction ( const QXmlName target,
const QString data 
)
virtual

Definition at line 297 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

299 {
300  startStructure();
301  ++m_preNumber;
302  m_document->data.insert(m_preNumber, data);
303 
304  m_document->basicData.append(AccelTree::BasicNodeData(currentDepth(),
305  currentParent(),
307  0,
308  target));
309  ++m_size.top();
310  m_isPreviousAtomic = false;
311 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QStack< AccelTree::PreNumber > m_size
AccelTree::PreNumber currentDepth() const
AccelTree::PreNumber currentParent() const
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ sourceLocation()

template<bool FromDocument>
QSourceLocation QPatternist::AccelTreeBuilder< FromDocument >::sourceLocation ( ) const
virtual

Reimplemented from QPatternist::SourceLocationReflection.

Definition at line 433 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeBuilder< true >::builtDocument().

434 {
435  if(m_documentURI.isEmpty())
436  return QSourceLocation(QUrl(QLatin1String("AnonymousNodeTree")));
437  else
439 }
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QSourceLocation class identifies a location in a resource by URI, line, and column.

◆ startDocument()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::startDocument ( )
virtual

Start of a document node.

Implements QPatternist::QAbstractXmlReceiver.

Definition at line 353 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

354 {
355  /* If we have already received nodes, we can't add a document node. */
356  if(m_preNumber == -1) /* -1 is our start value. */
357  {
358  m_size.push(0);
359  m_document->basicData.append(AccelTree::BasicNodeData(0, -1, QXmlNodeModelIndex::Document, -1));
360  ++m_preNumber;
362  }
363  else
365 
366  m_isPreviousAtomic = false;
367 }
QStack< AccelTree::PreNumber > m_ancestors
AccelTree::PreNumber m_skippedDocumentNodes
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QStack< AccelTree::PreNumber > m_size

◆ startElement() [1/2]

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::startElement ( const QXmlName name)
virtual

Definition at line 129 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

130 {
131  startElement(name, 1, 1);
132 }
virtual void startElement(const QXmlName &name)

◆ startElement() [2/2]

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::startElement ( const QXmlName name,
qint64  line,
qint64  column 
)

Definition at line 135 of file qacceltreebuilder.cpp.

136 {
137  startStructure();
138 
139  AccelTree::BasicNodeData data(currentDepth(), currentParent(), QXmlNodeModelIndex::Element, -1, name);
140  m_document->basicData.append(data);
142  m_document->sourcePositions.insert(m_document->maximumPreNumber(), qMakePair(line, column));
143 
144  ++m_preNumber;
146 
147  ++m_size.top();
148  m_size.push(0);
149 
150  /* With node constructors, we can receive names for which we have no namespace
151  * constructors, such as in the query '<xs:space/>'. Since the 'xs' prefix has no
152  * NamespaceConstructor in this case, we synthesize the namespace.
153  *
154  * In case we're constructing from an XML document we avoid the call because
155  * although it's redundant, it's on extra virtual call for each element. */
156  if(!FromDocument)
157  namespaceBinding(QXmlName(name.namespaceURI(), 0, name.prefix()));
158 
159  m_isPreviousAtomic = false;
160 }
QStack< AccelTree::PreNumber > m_ancestors
The accel tree builder will store source locations for each start element.
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
virtual void namespaceBinding(const QXmlName &nb)
Signals the presence of the namespace declaration nb.
static const char * data(const QByteArray &arr)
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QStack< AccelTree::PreNumber > m_size
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
AccelTree::PreNumber currentDepth() const
AccelTree::PreNumber currentParent() const
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ startOfSequence()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::startOfSequence ( )
virtual

Definition at line 417 of file qacceltreebuilder.cpp.

418 {
419 }

◆ startStructure()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::startStructure ( )
inlineprivate

Definition at line 76 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeBuilder< true >::builtDocument().

77 {
78  if(m_hasCharacters)
79  {
80  /* We create a node even if m_characters is empty.
81  * Remember that `text {""}' creates one text node
82  * with string value "". */
83 
84  ++m_preNumber;
85  m_document->basicData.append(AccelTree::BasicNodeData(currentDepth(),
86  currentParent(),
90  ++m_size.top();
91 
92  m_characters.clear(); /* We don't want it added twice. */
93  m_hasCharacters = false;
94 
97  }
98 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
QStack< AccelTree::PreNumber > m_size
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
AccelTree::PreNumber currentDepth() const
AccelTree::PreNumber currentParent() const
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ whitespaceOnly()

template<bool FromDocument>
void QPatternist::AccelTreeBuilder< FromDocument >::whitespaceOnly ( const QStringRef value)
virtual

This function may be called instead of characters() if, and only if, value consists only of whitespace.

The caller gurantees that value, is not empty.

By whitespace is meant a sequence of characters that are either spaces, tabs, or the two new line characters, in any order. In other words, the whole of Unicode's whitespace category is not considered whitespace.

However, there's no guarantee or requirement that whitespaceOnly() is called for text nodes containing whitespace only, characters() may be called just as well. This is why the default implementation for whitespaceOnly() calls characters().

See also
characters()

Reimplemented from QPatternist::QAbstractXmlReceiver.

Definition at line 264 of file qacceltreebuilder.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

265 {
266  Q_ASSERT(!ch.isEmpty());
267  Q_ASSERT(ch.toString().trimmed().isEmpty());
268 
269  /* This gets problematic due to how QXmlStreamReader works(which
270  * is the only one we get whitespaceOnly() events from). Namely, text intermingled
271  * with CDATA gets reported as individual Characters events, and
272  * QXmlStreamReader::isWhitespace() can return differently for each of those. However,
273  * it will occur very rarely, so this workaround of 1) mistakenly compressing 2) decompressing 3)
274  * appending, will happen infrequently.
275  */
276  if(m_hasCharacters)
277  {
279  {
281  m_isCharactersCompressed = false;
282  }
283 
284  m_characters.append(ch.toString());
285  }
286  else
287  {
288  /* We haven't received a text node previously. */
291  m_isPreviousAtomic = false;
292  m_hasCharacters = true;
293  }
294 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QString compress(const QStringRef &input)
Compresses input into a compressed format, returned as a QString.
QString & append(QChar c)
Definition: qstring.cpp:1777
static QString decompress(const QString &input)
Decompresses input into a usual QString.

Properties

◆ m_ancestors

template<bool FromDocument>
QStack<AccelTree::PreNumber> QPatternist::AccelTreeBuilder< FromDocument >::m_ancestors
private

◆ m_attributeCompress

template<bool FromDocument>
QSet<QString> QPatternist::AccelTreeBuilder< FromDocument >::m_attributeCompress
private

All attribute values goes through this set such that we store only one QString for identical attribute values.

Definition at line 182 of file qacceltreebuilder_p.h.

◆ m_characters

template<bool FromDocument>
QString QPatternist::AccelTreeBuilder< FromDocument >::m_characters
private

Definition at line 166 of file qacceltreebuilder_p.h.

◆ m_context

template<bool FromDocument>
ReportContext* const QPatternist::AccelTreeBuilder< FromDocument >::m_context
private

We don't store a reference pointer here because then we get a circular reference with GenericDynamicContext, when it stores us as a member.

Definition at line 189 of file qacceltreebuilder_p.h.

◆ m_document

template<bool FromDocument>
AccelTree::Ptr QPatternist::AccelTreeBuilder< FromDocument >::m_document
private

◆ m_documentURI

template<bool FromDocument>
const QUrl QPatternist::AccelTreeBuilder< FromDocument >::m_documentURI
private

Definition at line 183 of file qacceltreebuilder_p.h.

◆ m_features

template<bool FromDocument>
Features QPatternist::AccelTreeBuilder< FromDocument >::m_features
private

Definition at line 191 of file qacceltreebuilder_p.h.

◆ m_hasCharacters

template<bool FromDocument>
bool QPatternist::AccelTreeBuilder< FromDocument >::m_hasCharacters
private

Definition at line 160 of file qacceltreebuilder_p.h.

◆ m_isCharactersCompressed

template<bool FromDocument>
bool QPatternist::AccelTreeBuilder< FromDocument >::m_isCharactersCompressed
private

Whether m_characters has been run through CompressedWhitespace::compress().

Definition at line 165 of file qacceltreebuilder_p.h.

◆ m_isPreviousAtomic

template<bool FromDocument>
bool QPatternist::AccelTreeBuilder< FromDocument >::m_isPreviousAtomic
private

Definition at line 159 of file qacceltreebuilder_p.h.

◆ m_namePool

template<bool FromDocument>
NamePool::Ptr QPatternist::AccelTreeBuilder< FromDocument >::m_namePool
private

Definition at line 167 of file qacceltreebuilder_p.h.

◆ m_preNumber

template<bool FromDocument>
AccelTree::PreNumber QPatternist::AccelTreeBuilder< FromDocument >::m_preNumber
private

Definition at line 158 of file qacceltreebuilder_p.h.

◆ m_size

template<bool FromDocument>
QStack<AccelTree::PreNumber> QPatternist::AccelTreeBuilder< FromDocument >::m_size
private

Definition at line 170 of file qacceltreebuilder_p.h.

◆ m_skippedDocumentNodes

template<bool FromDocument>
AccelTree::PreNumber QPatternist::AccelTreeBuilder< FromDocument >::m_skippedDocumentNodes
private

If we have already commenced a document, we don't want to add more document nodes. We keep track of them with this counter, which ensures that startDocument() and endDocument() are skipped consistently.

Definition at line 176 of file qacceltreebuilder_p.h.


The documentation for this class was generated from the following files: