Qt 4.8
qacceltree_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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_AccelTree_H
53 #define Patternist_AccelTree_H
54 
55 #include <QHash>
56 #include <QUrl>
57 #include <QVector>
58 #include <QXmlName>
59 
60 #include "qitem_p.h"
61 #include "qnamepool_p.h"
62 
64 
66 
67 namespace QPatternist
68 {
69  template<bool> class AccelTreeBuilder;
70 
93  {
94  friend class AccelTreePrivate;
95  public:
97 
99  typedef qint32 PreNumber;
100  typedef PreNumber PostNumber;
101  typedef qint8 Depth;
102 
103  AccelTree(const QUrl &docURI, const QUrl &bURI);
104 
122  {
123  public:
124  /* No need to initialize the members. See AccelTreeBuilder. */
125  inline BasicNodeData()
126  {
127  }
128 
129  inline BasicNodeData(const PreNumber aDepth,
130  const PreNumber aParent,
132  const PreNumber s,
133  const QXmlName n = QXmlName()) : m_parent(aParent)
134  , m_size(s)
135  , m_name(n)
136  , m_depth(aDepth)
137  , m_kind(k)
138  {
139  }
140 
141  inline Depth depth() const
142  {
143  return m_depth;
144  }
145 
146  inline PreNumber parent() const
147  {
148  return m_parent;
149  }
150 
154  inline PreNumber size() const
155  {
156  /* Remember that we use the m_size to signal compression if
157  * we're a text node. */
158  if(m_kind == QXmlNodeModelIndex::Text)
159  return 0;
160  else
161  return m_size;
162  }
163 
164  inline void setSize(const PreNumber aSize)
165  {
166  m_size = aSize;
167  }
168 
170  {
171  return m_kind;
172  }
173 
174  inline QXmlName name() const
175  {
176  return m_name;
177  }
178 
179  inline bool isCompressed() const
180  {
182  "Currently, only text nodes are compressed.");
183  /* Note, we don't call size() here, since it has logic for text
184  * nodes. */
185  return m_size == IsCompressed;
186  }
187 
188  private:
192  PreNumber m_parent;
193 
202  PreNumber m_size;
203 
209 
210  Depth m_depth;
211 
220  };
221 
222  virtual QUrl baseUri(const QXmlNodeModelIndex &ni) const;
223  virtual QUrl documentUri(const QXmlNodeModelIndex &ni) const;
224  virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const;
225  virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &ni1,
226  const QXmlNodeModelIndex &ni2) const;
227 
234  virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const;
235 
236  virtual QXmlNodeModelIndex parent(const QXmlNodeModelIndex &ni) const;
237  virtual QXmlNodeModelIndex::Iterator::Ptr iterate(const QXmlNodeModelIndex &ni,
238  QXmlNodeModelIndex::Axis axis) const;
239  virtual QXmlName name(const QXmlNodeModelIndex &ni) const;
240  virtual QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &n) const;
241  virtual void sendNamespaces(const QXmlNodeModelIndex &n,
242  QAbstractXmlReceiver *const receiver) const;
243  virtual QString stringValue(const QXmlNodeModelIndex &n) const;
244  virtual QVariant typedValue(const QXmlNodeModelIndex &n) const;
245  virtual Item::Iterator::Ptr sequencedTypedValue(const QXmlNodeModelIndex &n) const;
246  virtual ItemType::Ptr type(const QXmlNodeModelIndex &ni) const;
247  virtual QXmlNodeModelIndex elementById(const QXmlName &id) const;
248  virtual QVector<QXmlNodeModelIndex> nodesByIdref(const QXmlName &idref) const;
249  virtual void copyNodeTo(const QXmlNodeModelIndex &node,
250  QAbstractXmlReceiver *const receiver,
251  const NodeCopySettings &settings) const;
252 
253  friend class AccelTreeBuilder<false>;
254  friend class AccelTreeBuilder<true>;
255 
257  {
258  IsCompressed = 1
259  };
260 
269 
275 
278 
279  inline QUrl documentUri() const
280  {
281  return m_documentURI;
282  }
283 
284  inline QUrl baseUri() const
285  {
286  return m_baseURI;
287  }
288 
294  inline bool hasChildren(const PreNumber pre) const
295  {
296  return basicData.at(pre).size() > 0;
297  }
298 
307  inline PreNumber parent(const PreNumber pre) const
308  {
309  return basicData.at(pre).parent();
310  }
311 
312  inline bool hasParent(const PreNumber pre) const
313  {
314  return basicData.at(pre).depth() > 0;
315  }
316 
317  inline bool hasFollowingSibling(const PreNumber pre) const
318  {
319  return pre < maximumPreNumber();
320  }
321 
322  inline PostNumber postNumber(const PreNumber pre) const
323  {
324  const BasicNodeData &b = basicData.at(pre);
325  return pre + b.size() - b.depth();
326  }
327 
328  inline QXmlNodeModelIndex::NodeKind kind(const PreNumber pre) const
329  {
330  return basicData.at(pre).kind();
331  }
332 
333  inline PreNumber maximumPreNumber() const
334  {
335  return basicData.count() - 1;
336  }
337 
338  inline PreNumber toPreNumber(const QXmlNodeModelIndex n) const
339  {
340  return n.data();
341  }
342 
343  inline PreNumber size(const PreNumber pre) const
344  {
345  Q_ASSERT_X(basicData.at(pre).size() != -1, Q_FUNC_INFO,
346  "The size cannot be -1. That means an uninitialized value is attempted to be used.");
347  return basicData.at(pre).size();
348  }
349 
350  inline Depth depth(const PreNumber pre) const
351  {
352  return basicData.at(pre).depth();
353  }
354 
355  void printStats(const NamePool::Ptr &np) const;
356 
357  inline QXmlName name(const PreNumber pre) const
358  {
359  return basicData.at(pre).name();
360  }
361 
362  inline bool isCompressed(const PreNumber pre) const
363  {
364  return basicData.at(pre).isCompressed();
365  }
366 
367  static inline bool hasPrefix(const QVector<QXmlName> &nbs, const QXmlName::PrefixCode prefix);
368 
371 
372  protected:
373  virtual QXmlNodeModelIndex nextFromSimpleAxis(QAbstractXmlNodeModel::SimpleAxis,
374  const QXmlNodeModelIndex&) const;
375  virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const;
376 
377  private:
381  QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const;
382 
386  inline void copyChildren(const QXmlNodeModelIndex &node,
387  QAbstractXmlReceiver *const receiver,
388  const NodeCopySettings &settings) const;
389 
395  };
396 }
397 
399 
401 
403 
404 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
int type
Definition: qmetatype.cpp:239
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
Due to strong interdependencies, this file contains the definitions for the classes Item...
Builds an AccelTree from a stream of XML/Item events received through the NodeBuilder interface...
Definition: qacceltree_p.h:69
QXmlNodeModelIndex::NodeKind kind(const PreNumber pre) const
Definition: qacceltree_p.h:328
BasicNodeData(const PreNumber aDepth, const PreNumber aParent, const QXmlNodeModelIndex::NodeKind k, const PreNumber s, const QXmlName n=QXmlName())
Definition: qacceltree_p.h:129
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QHash< PreNumber, QVector< QXmlName > > namespaces
Definition: qacceltree_p.h:268
bool isCompressed(const PreNumber pre) const
Definition: qacceltree_p.h:362
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
PreNumber parent(const PreNumber pre) const
Returns the parent node of pre.
Definition: qacceltree_p.h:307
signed char qint8
Definition: qglobal.h:933
bool hasParent(const PreNumber pre) const
Definition: qacceltree_p.h:312
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qint64 data() const
Returns the first data value.
QXmlNodeModelIndex::NodeKind m_kind
Definition: qacceltree_p.h:219
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...
DocumentOrder
Identifies the specific node comparison operator that should be used.
const char * name
Q_DECLARE_TYPEINFO(QPatternist::AccelTree::BasicNodeData, Q_MOVABLE_TYPE)
The namespace for the internal API of QtXmlPatterns.
bool hasChildren(const PreNumber pre) const
Returns true if the node identified by pre has child nodes(in the sense of the XDM), but also if it has namespace nodes, or attribute nodes.
Definition: qacceltree_p.h:294
The QSourceLocation class identifies a location in a resource by URI, line, and column.
Depth depth(const PreNumber pre) const
Definition: qacceltree_p.h:350
QHash< PreNumber, QString > data
Definition: qacceltree_p.h:274
QXmlName name(const PreNumber pre) const
Definition: qacceltree_p.h:357
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
Stores an XML document using the XPath Accelerator scheme, also known as pre/post numbering...
Definition: qacceltree_p.h:92
NodeKind
Identifies a kind of node.
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.
SimpleAxis
Four axes that each contain one node only.
PostNumber postNumber(const PreNumber pre) const
Definition: qacceltree_p.h:322
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
quint16 index
Axis
Identify the axes emanating from a node.
QUrl documentUri() const
Definition: qacceltree_p.h:279
Houses data for a node, and that all node kinds have.
Definition: qacceltree_p.h:121
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333
PreNumber size(const PreNumber pre) const
Definition: qacceltree_p.h:343
QExplicitlySharedDataPointer< AccelTree > Ptr
Definition: qacceltree_p.h:98
#define QT_END_HEADER
Definition: qglobal.h:137
QHash< QXmlName::LocalNameCode, PreNumber > m_IDs
Definition: qacceltree_p.h:394
bool hasFollowingSibling(const PreNumber pre) const
Definition: qacceltree_p.h:317
void setSize(const PreNumber aSize)
Definition: qacceltree_p.h:164
QHash< PreNumber, QPair< qint64, qint64 > > sourcePositions
Definition: qacceltree_p.h:277
QXmlNodeModelIndex::NodeKind kind() const
Definition: qacceltree_p.h:169
#define Q_FUNC_INFO
Definition: qglobal.h:1871
NamespaceCode PrefixCode
Definition: qxmlname.h:83