Qt 4.8
Classes | Public Types | Public Functions | Static Public Functions | Public Variables | Protected Functions | Private Functions | Properties | Friends | List of all members
QPatternist::AccelTree Class Reference

Stores an XML document using the XPath Accelerator scheme, also known as pre/post numbering. More...

#include <qacceltree_p.h>

Inheritance diagram for QPatternist::AccelTree:
QAbstractXmlNodeModel QSharedData

Classes

class  BasicNodeData
 Houses data for a node, and that all node kinds have. More...
 

Public Types

enum  Constants { IsCompressed = 1 }
 
typedef qint8 Depth
 
typedef PreNumber PostNumber
 
typedef qint32 PreNumber
 
typedef QExplicitlySharedDataPointer< AccelTreePtr
 
- Public Types inherited from QAbstractXmlNodeModel
typedef QList< PtrList
 A list of smart pointers to instances of QAbstractXmlNodeModel. More...
 
enum  NodeCopySetting { InheritNamespaces = 0x1, PreserveNamespaces = 0x2 }
 
typedef QFlags< NodeCopySettingNodeCopySettings
 
typedef QExplicitlySharedDataPointer< QAbstractXmlNodeModelPtr
 A QExplicitlySharedDataPointer {smart pointer} to an instance of QAbstractXmlNodeModel. More...
 
enum  SimpleAxis { Parent, FirstChild, PreviousSibling, NextSibling }
 Four axes that each contain one node only. More...
 

Public Functions

 AccelTree (const QUrl &docURI, const QUrl &bURI)
 
virtual QUrl baseUri (const QXmlNodeModelIndex &ni) const
 Returns the base URI for the node whose index is n. More...
 
QUrl baseUri () const
 
virtual QXmlNodeModelIndex::DocumentOrder compareOrder (const QXmlNodeModelIndex &ni1, const QXmlNodeModelIndex &ni2) const
 This function returns the relative document order for the nodes indexed by ni1 and ni2. More...
 
virtual void copyNodeTo (const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &settings) const
 
Depth depth (const PreNumber pre) const
 
virtual QUrl documentUri (const QXmlNodeModelIndex &ni) const
 Returns the document URI of n. More...
 
QUrl documentUri () const
 
virtual QXmlNodeModelIndex elementById (const QXmlName &id) const
 Returns the index of the element identified as id. More...
 
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. More...
 
bool hasFollowingSibling (const PreNumber pre) const
 
bool hasParent (const PreNumber pre) const
 
bool isCompressed (const PreNumber pre) const
 
virtual QXmlNodeModelIndex::Iterator::Ptr iterate (const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
 Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes the axis emanating from ni. More...
 
virtual QXmlNodeModelIndex::NodeKind kind (const QXmlNodeModelIndex &ni) const
 Returns a value indicating the kind of node identified by ni. More...
 
QXmlNodeModelIndex::NodeKind kind (const PreNumber pre) const
 
PreNumber maximumPreNumber () const
 
virtual QXmlName name (const QXmlNodeModelIndex &ni) const
 Returns the name of ni. More...
 
QXmlName name (const PreNumber pre) const
 
virtual QVector< QXmlNamenamespaceBindings (const QXmlNodeModelIndex &n) const
 Returns the in-scope namespaces of n. More...
 
virtual QVector< QXmlNodeModelIndexnodesByIdref (const QXmlName &idref) const
 Returns the elements and/or attributes that have an IDREF value equal to idref. More...
 
virtual QXmlNodeModelIndex parent (const QXmlNodeModelIndex &ni) const
 
PreNumber parent (const PreNumber pre) const
 Returns the parent node of pre. More...
 
PostNumber postNumber (const PreNumber pre) const
 
void printStats (const NamePool::Ptr &np) const
 
virtual QXmlNodeModelIndex root (const QXmlNodeModelIndex &n) const
 Returns the root node. More...
 
virtual void sendNamespaces (const QXmlNodeModelIndex &n, QAbstractXmlReceiver *const receiver) const
 
virtual Item::Iterator::Ptr sequencedTypedValue (const QXmlNodeModelIndex &n) const
 
PreNumber size (const PreNumber pre) const
 
virtual QString stringValue (const QXmlNodeModelIndex &n) const
 Returns the string value for node n. More...
 
PreNumber toPreNumber (const QXmlNodeModelIndex n) const
 
virtual ItemType::Ptr type (const QXmlNodeModelIndex &ni) const
 
virtual QVariant typedValue (const QXmlNodeModelIndex &n) const
 Returns the typed value for node node. More...
 
- Public Functions inherited from QAbstractXmlNodeModel
virtual void copyNodeTo (const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &) const
 
virtual bool isDeepEqual (const QXmlNodeModelIndex &ni1, const QXmlNodeModelIndex &ni2) const
 Determines whether ni1 is deep equal to ni2. More...
 
virtual QXmlName::NamespaceCode namespaceForPrefix (const QXmlNodeModelIndex &ni, const QXmlName::PrefixCode prefix) const
 Returns the namespace URI on ni that corresponds to prefix. More...
 
 QAbstractXmlNodeModel ()
 Default constructor. More...
 
virtual void sendNamespaces (const QXmlNodeModelIndex &n, QAbstractXmlReceiver *const receiver) const
 Sends the namespaces declared on n to receiver. More...
 
QSourceLocation sourceLocation (const QXmlNodeModelIndex &index) const
 Returns the source location for the object with the given index or a default constructed QSourceLocation in case no location information is available. More...
 
virtual ~QAbstractXmlNodeModel ()
 Destructor. More...
 
- 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...
 

Static Public Functions

static bool hasPrefix (const QVector< QXmlName > &nbs, const QXmlName::PrefixCode prefix)
 

Public Variables

QVector< BasicNodeDatabasicData
 
QHash< PreNumber, QStringdata
 
QUrl m_baseURI
 
QUrl m_documentURI
 
QHash< PreNumber, QVector< QXmlName > > namespaces
 
QHash< PreNumber, QPair< qint64, qint64 > > sourcePositions
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Protected Functions

virtual QVector< QXmlNodeModelIndexattributes (const QXmlNodeModelIndex &element) const
 Returns the attributes of element. More...
 
virtual QXmlNodeModelIndex nextFromSimpleAxis (QAbstractXmlNodeModel::SimpleAxis, const QXmlNodeModelIndex &) const
 When QtXmlPatterns evaluate path expressions, it emulate them through a combination of calls with QSimpleXmlNodeModel::SimpleAxis values. More...
 
- Protected Functions inherited from QAbstractXmlNodeModel
QXmlNodeModelIndex createIndex (qint64 data) const
 Creates a node index with data as its internal data. More...
 
QXmlNodeModelIndex createIndex (void *pointer, qint64 additionalData=0) const
 Creates a node index with pointer and additionalData as its internal data. More...
 
QXmlNodeModelIndex createIndex (qint64 data, qint64 additionalData) const
 Creates a QXmlNodeModelIndex containing data and additionalData. More...
 
 QAbstractXmlNodeModel (QAbstractXmlNodeModelPrivate *d)
 

Private Functions

void copyChildren (const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &settings) const
 
QSourceLocation sourceLocation (const QXmlNodeModelIndex &index) const
 

Properties

QHash< QXmlName::LocalNameCode, PreNumberm_IDs
 

Friends

class AccelTreeBuilder< false >
 
class AccelTreeBuilder< true >
 
class AccelTreePrivate
 

Additional Inherited Members

- Protected Variables inherited from QAbstractXmlNodeModel
QScopedPointer< QAbstractXmlNodeModelPrivated_ptr
 

Detailed Description

Stores an XML document using the XPath Accelerator scheme, also known as pre/post numbering.

Working on this code will be destructive without a proper understanding of the Accelerator scheme, so do check out the links. We don't implement any form of staircase join, although that is only due to time constraints.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com
See also
XPath Accelerator
Accelerating XPath Location Steps, Torsten Grust
Staircase Join: Teach a Relational DBMS to Watch its (Axis) Steps
Loop-lifted staircase join: from XPath to XQuery, Torsten Grust
xmlstat, Frans Englich
<a href"http://www.inf.uni-konstanz.de/dbis/publications/download/accelerating-locsteps.pdf">Accelerating XPath Evaluation in Any RDBMS, Torsten Grust

Definition at line 92 of file qacceltree_p.h.

Typedefs

◆ Depth

Definition at line 101 of file qacceltree_p.h.

◆ PostNumber

Definition at line 100 of file qacceltree_p.h.

◆ PreNumber

Definition at line 99 of file qacceltree_p.h.

◆ Ptr

Definition at line 98 of file qacceltree_p.h.

Enumerations

◆ Constants

Enumerator
IsCompressed 

Definition at line 256 of file qacceltree_p.h.

Constructors and Destructors

◆ AccelTree()

AccelTree::AccelTree ( const QUrl docURI,
const QUrl bURI 
)

Definition at line 79 of file qacceltree.cpp.

81  , m_documentURI(docURI)
82  , m_baseURI(bURI)
83 {
84  /* Pre-allocate at least a little bit. */
85  // TODO. Do it according to what an average 4 KB doc contains.
86  basicData.reserve(100);
87  data.reserve(30);
88 }
void reserve(int size)
Ensures that the QHash&#39;s internal hash table consists of at least size buckets.
Definition: qhash.h:846
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
QHash< PreNumber, QString > data
Definition: qacceltree_p.h:274
friend class AccelTreePrivate
Definition: qacceltree_p.h:94
QAbstractXmlNodeModel()
Default constructor.

Functions

◆ attributes()

QVector< QXmlNodeModelIndex > AccelTree::attributes ( const QXmlNodeModelIndex element) const
protectedvirtual

Returns the attributes of element.

The caller guarantees that element is an element in this node model.

Implements QAbstractXmlNodeModel.

Definition at line 372 of file qacceltree.cpp.

Referenced by copyNodeTo().

373 {
374  Q_ASSERT_X(false, Q_FUNC_INFO, "This function is not supposed to be called.");
375  Q_UNUSED(element);
377 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#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
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ baseUri() [1/2]

QUrl AccelTree::baseUri ( const QXmlNodeModelIndex n) const
virtual

Returns the base URI for the node whose index is n.

The caller guarantees that n is not null and that it belongs to a node in this node model.

The base URI of a node can be extracted using the fn:base-uri() function. The base URI is typically used for resolving relative URIs that appear in the node or its children. It is conformant to just return the document URI, although that might not properly reflect the underlying data.

This function maps to the dm:base-uri accessor, which returns a base URI according to the following:

  • For document nodes, the base URI and the document URI are the same.

  • For elements, the base URI is the URI appearing in the element's xml:base attribute, if present, or it is resolved to the parent element's base URI.

  • Namespace nodes have no base URI.

  • The base URI for a processing instruction, comment, attribute, or text node is the base URI of the node's parent element.

The implementation guarantees to return a valid QUrl, or a default constructed QUrl. If a node has no base URI, as in the case where a comment has no parent, a default constructed QUrl is returned.

See also
{http://www.w3.org/TR/xpath-datamodel/#dm-base-uri}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 5.2 base-uri Accessor}

Implements QAbstractXmlNodeModel.

Definition at line 140 of file qacceltree.cpp.

141 {
142  switch(kind(toPreNumber(ni)))
143  {
145  return baseUri();
147  {
149  QXmlNodeModelIndex next(it->next());
150 
151  while(!next.isNull())
152  {
154  {
155  const QUrl candidate(next.stringValue());
156  // TODO. The xml:base spec says to do URI escaping here.
157 
158  if(!candidate.isValid())
159  return QUrl();
160  else if(candidate.isRelative())
161  {
162  const QXmlNodeModelIndex par(parent(ni));
163 
164  if(par.isNull())
165  return baseUri().resolved(candidate);
166  else
167  return par.baseUri().resolved(candidate);
168  }
169  else
170  return candidate;
171  }
172 
173  next = it->next();
174  }
175 
176  /* We have no xml:base-attribute. Can any parent supply us a base URI? */
177  const QXmlNodeModelIndex par(parent(ni));
178 
179  if(par.isNull())
180  return baseUri();
181  else
182  return par.baseUri();
183  }
185  /* Fallthrough. */
187  /* Fallthrough. */
189  /* Fallthrough. */
191  {
192  const QXmlNodeModelIndex par(ni.iterate(QXmlNodeModelIndex::AxisParent)->next());
193  if(par.isNull())
194  return QUrl();
195  else
196  return par.baseUri();
197  }
199  return QUrl();
200  }
201 
202  Q_ASSERT_X(false, Q_FUNC_INFO, "This line is never supposed to be reached.");
203  return QUrl();
204 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QXmlNodeModelIndex::Iterator::Ptr iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
Definition: qacceltree.cpp:251
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
#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
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
virtual QXmlNodeModelIndex parent(const QXmlNodeModelIndex &ni) const
Definition: qacceltree.cpp:241
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ baseUri() [2/2]

QUrl QPatternist::AccelTree::baseUri ( ) const
inline

Definition at line 284 of file qacceltree_p.h.

Referenced by baseUri().

285  {
286  return m_baseURI;
287  }

◆ compareOrder()

QXmlNodeModelIndex::DocumentOrder AccelTree::compareOrder ( const QXmlNodeModelIndex ni1,
const QXmlNodeModelIndex ni2 
) const
virtual

This function returns the relative document order for the nodes indexed by ni1 and ni2.

It is used for the Is operator and for sorting nodes in document order.

The caller guarantees that ni1 and ni2 are not null and that both identify nodes in this node model.

If ni1 is identical to ni2, QXmlNodeModelIndex::Is is returned. If ni1 precedes ni2 in document order, QXmlNodeModelIndex::Precedes is returned. If ni1 follows ni2 in document order, QXmlNodeModelIndex::Follows is returned.

See also
{http://www.w3.org/TR/xpath-datamodel/#document-order}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 2.4 Document Order}

Implements QAbstractXmlNodeModel.

Definition at line 219 of file qacceltree.cpp.

221 {
222  Q_ASSERT_X(ni1.model() == ni2.model(), Q_FUNC_INFO,
223  "The API docs guarantees the two nodes are from the same model");
224 
225  const PreNumber p1 = ni1.data();
226  const PreNumber p2 = ni2.data();
227 
228  if(p1 == p2)
229  return QXmlNodeModelIndex::Is;
230  else if(p1 < p2)
232  else
234 }
qint64 data() const
Returns the first data value.
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ copyChildren()

void AccelTree::copyChildren ( const QXmlNodeModelIndex node,
QAbstractXmlReceiver *const  receiver,
const NodeCopySettings settings 
) const
inlineprivate

Copies the children of node to receiver.

Definition at line 720 of file qacceltree.cpp.

Referenced by copyNodeTo().

723 {
725  QXmlNodeModelIndex child(children->next());
726 
727  while(!child.isNull())
728  {
729  copyNodeTo(child, receiver, settings);
730  child = children->next();
731  }
732 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual void copyNodeTo(const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &settings) const
Definition: qacceltree.cpp:622
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456

◆ copyNodeTo()

void AccelTree::copyNodeTo ( const QXmlNodeModelIndex node,
QAbstractXmlReceiver *const  receiver,
const NodeCopySettings settings 
) const
virtual

Definition at line 622 of file qacceltree.cpp.

Referenced by copyChildren().

625 {
626  /* This code piece can be seen as a customized version of
627  * QAbstractXmlReceiver::item/sendAsNode(). */
628  Q_ASSERT(receiver);
629  Q_ASSERT(!node.isNull());
630 
632  QStack<Binding> outputted;
633 
634  switch(node.kind())
635  {
637  {
638  outputted.push(Binding());
639 
640  /* Add the namespace for our element name. */
641  const QXmlName elementName(node.name());
642 
643  receiver->startElement(elementName);
644 
645  if(!settings.testFlag(InheritNamespaces))
648 
649  if(settings.testFlag(PreserveNamespaces))
650  node.sendNamespaces(receiver);
651  else
652  {
653  /* Find the namespaces that we actually use and add them to outputted. These are drawn
654  * from the element name, and the node's attributes. */
655  outputted.top().insert(elementName.prefix(), elementName.namespaceURI());
656 
658  QXmlNodeModelIndex attr(attributes->next());
659 
660  while(!attr.isNull())
661  {
662  const QXmlName &attrName = attr.name();
663  outputted.top().insert(attrName.prefix(), attrName.namespaceURI());
664  attr = attributes->next();
665  }
666 
667  Binding::const_iterator it(outputted.top().constBegin());
668  const Binding::const_iterator end(outputted.top().constEnd());
669 
670  for(; it != end; ++it)
671  receiver->namespaceBinding(QXmlName(it.value(), 0, it.key()));
672  }
673 
674  /* Send the attributes of the element. */
675  {
677  QXmlNodeModelIndex attribute(attributes->next());
678 
679  while(!attribute.isNull())
680  {
681  const QString &v = attribute.stringValue();
682  receiver->attribute(attribute.name(), QStringRef(&v));
683  attribute = attributes->next();
684  }
685  }
686 
687  /* Send the children of the element. */
688  copyChildren(node, receiver, settings);
689 
690  receiver->endElement();
691  outputted.pop();
692  break;
693  }
695  {
696  /* We need to intercept and grab the elements of the document node, such
697  * that we preserve/inherit preference applies to them. */
698  receiver->startDocument();
699  copyChildren(node, receiver, settings);
700  receiver->endDocument();
701  break;
702  }
703  default:
704  receiver->item(node);
705  }
706 
707 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
virtual void namespaceBinding(const QXmlName &nb)=0
Signals the presence of the namespace declaration nb.
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QXmlNodeModelIndex::Iterator::Ptr iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
Definition: qacceltree.cpp:251
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
virtual void startElement(const QXmlName name)=0
Signals the start of an element by name name.
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void endElement()=0
Signals the end of the current element.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
virtual void item(const Item &item)=0
Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue...
The Binding element allows arbitrary property bindings to be created.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
QXmlName name() const
Definition: qitem_p.h:446
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
void sendNamespaces(QAbstractXmlReceiver *const receiver) const
Definition: qitem_p.h:494
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
virtual QVector< QXmlNodeModelIndex > attributes(const QXmlNodeModelIndex &element) const
Returns the attributes of element.
Definition: qacceltree.cpp:372
void copyChildren(const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &settings) const
Definition: qacceltree.cpp:720
virtual void attribute(const QXmlName name, const QString &value)=0
Signals the presence of an attribute node.
static const KeyPair *const end
NodeKind kind() const
Definition: qitem_p.h:471
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ depth()

Depth QPatternist::AccelTree::depth ( const PreNumber  pre) const
inline

Definition at line 350 of file qacceltree_p.h.

Referenced by QPatternist::ChildIterator::ChildIterator(), QPatternist::ChildIterator::next(), and QPatternist::SiblingIterator< IsFollowing >::next().

351  {
352  return basicData.at(pre).depth();
353  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ documentUri() [1/2]

QUrl AccelTree::documentUri ( const QXmlNodeModelIndex n) const
virtual

Returns the document URI of n.

The document URI identifies the resource which is the document. For example, the document could be a regular file, e.g., file:/, or it could be the http:// URL of the location of a file. The document URI is used for resolving URIs and to simply know where the document is.

If the node model maps to a URI in a natural way, return that URI. Otherwise, return the company or product URI. The document URI can be any URI as long as its valid and absolute.

The caller guarantees that n is not null and that it belongs to this QAbstractXmlNodeModel.

This function maps to the dm:document-uri accessor, which returns a document URI according to the following:

  • If n is a document node, return an absolute QUrl containing the document URI, or a default constructed QUrl. The latter signals that no document URI is available for the document node.

  • For all other nodes, return a default constructed QUrl.

See also
{http://www.w3.org/TR/xpath-datamodel/#dm-document-uri}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 5.4 document-uri Accessor}
QUrl::isValid(), QUrl::isRelative()

Implements QAbstractXmlNodeModel.

Definition at line 206 of file qacceltree.cpp.

207 {
209  return documentUri();
210  else
211  return QUrl();
212 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
QUrl documentUri() const
Definition: qacceltree_p.h:279

◆ documentUri() [2/2]

QUrl QPatternist::AccelTree::documentUri ( ) const
inline

Definition at line 279 of file qacceltree_p.h.

Referenced by documentUri().

280  {
281  return m_documentURI;
282  }

◆ elementById()

QXmlNodeModelIndex AccelTree::elementById ( const QXmlName id) const
virtual

Returns the index of the element identified as id.

XQuery's id() function calls this function.

The node index returned will be the element node whose value is of type ID and equals id, or it will be the element node that has an attribute whose typed value is of type ID and equals id. If there is no such element, a default constructed QXmlNodeModelIndex instance is returned. The implementor guarantees that if the returned node index is not null, it identifies an element.

It is not sufficient for an attribute or element to merely be called id. Its value type must also be ID. However, the reserved name xml:id is sufficient.

In id, the namespace URI and the prefix are undefined, and the local name is the ID that should be looked up.

See also
{http://www.w3.org/TR/xpath-functions/#func-id}{XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.2 fn:id}

Implements QAbstractXmlNodeModel.

Definition at line 734 of file qacceltree.cpp.

735 {
736  const PreNumber pre = m_IDs.value(id.localName(), -1);
737  if(pre == -1)
738  return QXmlNodeModelIndex();
739  else
740  return createIndex(pre);
741 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.
QHash< QXmlName::LocalNameCode, PreNumber > m_IDs
Definition: qacceltree_p.h:394

◆ hasChildren()

bool QPatternist::AccelTree::hasChildren ( const PreNumber  pre) const
inline

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 at line 294 of file qacceltree_p.h.

Referenced by QPatternist::AttributeIterator::AttributeIterator(), QPatternist::ChildIterator::ChildIterator(), QPatternist::DescendantIterator< IncludeSelf >::DescendantIterator(), iterate(), and stringValue().

295  {
296  return basicData.at(pre).size() > 0;
297  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ hasFollowingSibling()

bool QPatternist::AccelTree::hasFollowingSibling ( const PreNumber  pre) const
inline

Definition at line 317 of file qacceltree_p.h.

318  {
319  return pre < maximumPreNumber();
320  }
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333

◆ hasParent()

bool QPatternist::AccelTree::hasParent ( const PreNumber  pre) const
inline

Definition at line 312 of file qacceltree_p.h.

Referenced by QPatternist::AncestorIterator< IncludeSelf >::AncestorIterator(), and iterate().

313  {
314  return basicData.at(pre).depth() > 0;
315  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ hasPrefix()

bool AccelTree::hasPrefix ( const QVector< QXmlName > &  nbs,
const QXmlName::PrefixCode  prefix 
)
inlinestatic

Definition at line 574 of file qacceltree.cpp.

Referenced by namespaceBindings().

575 {
576  const int size = nbs.size();
577 
578  for(int i = 0; i < size; ++i)
579  {
580  if(nbs.at(i).prefix() == prefix)
581  return true;
582  }
583 
584  return false;
585 }
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
PreNumber size(const PreNumber pre) const
Definition: qacceltree_p.h:343
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ isCompressed()

bool QPatternist::AccelTree::isCompressed ( const PreNumber  pre) const
inline

Definition at line 362 of file qacceltree_p.h.

Referenced by printStats(), and stringValue().

363  {
364  return basicData.at(pre).isCompressed();
365  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ iterate()

QXmlNodeModelIndex::Iterator::Ptr AccelTree::iterate ( const QXmlNodeModelIndex ni,
QXmlNodeModelIndex::Axis  axis 
) const
virtual

Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes the axis emanating from ni.

Warning
This function is not part of the public interface.

The implementation returns the nodes on the axis, without duplicates and in axis order. This means that if axis is a reverse axis, which is the case for the parent, ancestor, ancestor-or-self, preceding, and preceding-sibling, the nodes are delivered in reverse document order. Otherwise the nodes are delivered in document order.

The implementor guarantees that the nodes delivered for the axes are consistent with the XPath Data Model. This just implies common sense, e.g., The child axis for a comment node can't contain any children; a document node can't be a child of an element, etc. Attributes aren't considered children of an element, but are only available on AxisAttribute.

The value past in axis is not guaranteed based on what is used in a query. QtXmlPatterns may call this function arbitrarily with any value for axis. This is because QtXmlPatterns may rewrite queries to be more efficient, using axes in different ways from the original query.

QAbstractXmlNodeModel::Axis has a good overview of the axes and what they select.

The caller guarantees that ni is not null and that it belongs to this QAbstractXmlNodeModel instance.

Implementing iterate() can involve significant work, since it requires different iterators for all the axes used. In the worst case, it could require writing as many QAbstractXmlForwardIterator subclasses as there are axes, but the number can often be reduced with clever use of lists and template classes. It is better to use or subclass QSimpleXmlNodeModel, which makes it easier to write the node navigation code without loss of efficiency or flexibility.

See also
QSimpleXmlNodeModel
QXmlNodeModelIndex::Axis
{http://www.w3.org/TR/xquery/#axes}{XQuery 1.0: An XML Query Language, 3.2.1.1 Axes}
{http://www.w3.org/TR/xpath-datamodel/}{W3CXQuery 1.0 and XPath 2.0 Data Model (XDM)}

Reimplemented from QAbstractXmlNodeModel.

Definition at line 251 of file qacceltree.cpp.

Referenced by baseUri(), copyNodeTo(), and sendNamespaces().

253 {
254  const PreNumber preNumber = toPreNumber(ni);
255 
256  switch(axis)
257  {
259  {
260  if(!hasParent(preNumber))
261  {
262  switch(kind(preNumber))
263  {
265  /* Fallthrough. */
267  /* Fallthrough. */
269  /* Fallthrough. */
271  return makeSingletonIterator(ni);
273  /* Fallthrough. */
275  /* Fallthrough. */
277  /* Do nothing. */;
278  }
279  }
280  /* Else, fallthrough to AxisChild. */
281  }
283  {
284  if(hasChildren(preNumber))
285  return QXmlNodeModelIndex::Iterator::Ptr(new ChildIterator(this, preNumber));
286  else
287  return makeEmptyIterator<QXmlNodeModelIndex>();
288  }
290  {
291  if(hasParent(preNumber))
292  return QXmlNodeModelIndex::Iterator::Ptr(new AncestorIterator<false>(this, preNumber));
293  else
294  return makeEmptyIterator<QXmlNodeModelIndex>();
295  }
297  return QXmlNodeModelIndex::Iterator::Ptr(new AncestorIterator<true>(this, preNumber));
299  {
300  if(hasParent(preNumber))
301  return makeSingletonIterator(createIndex(parent(preNumber)));
302  else
303  return makeEmptyIterator<QXmlNodeModelIndex>();
304  }
306  {
307  if(hasChildren(preNumber))
309  else
310  return makeEmptyIterator<QXmlNodeModelIndex>();
311  }
313  return QXmlNodeModelIndex::Iterator::Ptr(new DescendantIterator<true>(this, preNumber));
315  {
316  if(preNumber == maximumPreNumber())
317  return makeEmptyIterator<QXmlNodeModelIndex>();
318  else
319  return QXmlNodeModelIndex::Iterator::Ptr(new FollowingIterator(this, preNumber));
320  }
322  {
323  if(!hasParent(preNumber) && kind(preNumber) == QXmlNodeModelIndex::Attribute)
324  return makeSingletonIterator(ni);
325  /* Else, falthrough to AxisAttribute. */
326  }
328  {
329  if(hasChildren(preNumber) && kind(preNumber + 1) == QXmlNodeModelIndex::Attribute)
330  return QXmlNodeModelIndex::Iterator::Ptr(new AttributeIterator(this, preNumber));
331  else
332  return makeEmptyIterator<QXmlNodeModelIndex>();
333  }
335  {
336  if(preNumber == 0)
337  return makeEmptyIterator<QXmlNodeModelIndex>();
338  else
339  return QXmlNodeModelIndex::Iterator::Ptr(new PrecedingIterator(this, preNumber));
340  }
342  return makeSingletonIterator(createIndex(toPreNumber(ni)));
344  {
345  if(preNumber == maximumPreNumber())
346  return makeEmptyIterator<QXmlNodeModelIndex>();
347  else
348  return QXmlNodeModelIndex::Iterator::Ptr(new SiblingIterator<true>(this, preNumber));
349  }
351  {
352  if(preNumber == 0)
353  return makeEmptyIterator<QXmlNodeModelIndex>();
354  else
355  return QXmlNodeModelIndex::Iterator::Ptr(new SiblingIterator<false>(this, preNumber));
356  }
358  return makeEmptyIterator<QXmlNodeModelIndex>();
359  }
360 
361  Q_ASSERT(false);
363 }
Iterates along the ancestor or ancestor-or-self axis in an AccelTree.
Implements axis attribute for the AccelTree.
Iterates along the sibling axes in an AccelTree.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
bool hasParent(const PreNumber pre) const
Definition: qacceltree_p.h:312
Implements axis following for the AccelTree.
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
Implements axis preceding for the AccelTree.
Implements axis descendant and descendant-or-self for the AccelTree.
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.
virtual QXmlNodeModelIndex parent(const QXmlNodeModelIndex &ni) const
Definition: qacceltree.cpp:241
Iterates along the child axis in an AccelTree.
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333

◆ kind() [1/2]

QXmlNodeModelIndex::NodeKind AccelTree::kind ( const QXmlNodeModelIndex ni) const
virtual

Returns a value indicating the kind of node identified by ni.

The caller guarantees that ni is not null and that it identifies a node in this node model. This function maps to the dm:node-kind() accessor.

See also
{http://www.w3.org/TR/xpath-datamodel/#dm-node-kind}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 5.10 node-kind Accessor}

Implements QAbstractXmlNodeModel.

Definition at line 214 of file qacceltree.cpp.

Referenced by QPatternist::AttributeIterator::AttributeIterator(), baseUri(), QPatternist::ChildIterator::ChildIterator(), QPatternist::DescendantIterator< IncludeSelf >::DescendantIterator(), documentUri(), iterate(), QPatternist::SiblingIterator< IsFollowing >::next(), QPatternist::DescendantIterator< IncludeSelf >::next(), QPatternist::FollowingIterator::next(), QPatternist::PrecedingIterator::next(), QPatternist::AttributeIterator::next(), sequencedTypedValue(), and stringValue().

215 {
216  return kind(toPreNumber(ni));
217 }
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214

◆ kind() [2/2]

QXmlNodeModelIndex::NodeKind QPatternist::AccelTree::kind ( const PreNumber  pre) const
inline

Definition at line 328 of file qacceltree_p.h.

329  {
330  return basicData.at(pre).kind();
331  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ maximumPreNumber()

PreNumber QPatternist::AccelTree::maximumPreNumber ( ) const
inline

◆ name() [1/2]

QXmlName AccelTree::name ( const QXmlNodeModelIndex ni) const
virtual

Returns the name of ni.

The caller guarantees that ni is not null and that it belongs to this QAbstractXmlNodeModel.

If a node does not have a name, e.g., comment nodes, a null QXmlName is returned. QXmlNames must be created with the instance of QXmlQuery that is being used for evaluating queries using this QAbstractXmlNodeModel.

This function maps to the dm:node-name() accessor.

If ni is a processing instruction, a QXmlName is returned with the local name as the target name and the namespace URI and prefix both empty.

See also
{http://www.w3.org/TR/xpath-datamodel/#dm-node-name}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 5.11 node-name Accessor}
QXmlName

Implements QAbstractXmlNodeModel.

Definition at line 379 of file qacceltree.cpp.

Referenced by sendNamespaces().

380 {
381  /* If this node type does not have a name(for instance, it's a comment)
382  * we will return the default constructed value, which is conformant with
383  * this function's contract. */
384  return name(toPreNumber(ni));
385 }
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
virtual QXmlName name(const QXmlNodeModelIndex &ni) const
Returns the name of ni.
Definition: qacceltree.cpp:379

◆ name() [2/2]

QXmlName QPatternist::AccelTree::name ( const PreNumber  pre) const
inline

Definition at line 357 of file qacceltree_p.h.

358  {
359  return basicData.at(pre).name();
360  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ namespaceBindings()

QVector< QXmlName > AccelTree::namespaceBindings ( const QXmlNodeModelIndex n) const
virtual

Returns the in-scope namespaces of n.

The caller guarantees that n is not null and that it belongs to this QAbstractXmlNodeModel.

This function corresponds to the dm:namespace-nodes accessor.

The returned vector of namespace declarations includes namespaces of the ancestors of n.

The caller guarantees that n is an Element that belongs to this QAbstractXmlNodeModel.

Implements QAbstractXmlNodeModel.

Definition at line 387 of file qacceltree.cpp.

388 {
389  /* We get a hold of the ancestor, and loop them in reverse document
390  * order(first the parent, then the parent's parent, etc). As soon
391  * we find a binding that hasn't already been added, we add it to the
392  * result list. In that way, declarations appearing further down override
393  * those further up. */
394 
395  const PreNumber preNumber = toPreNumber(ni);
396 
397  const QXmlNodeModelIndex::Iterator::Ptr it(new AncestorIterator<true>(this, preNumber));
398  QVector<QXmlName> result;
399  QXmlNodeModelIndex n(it->next());
400 
401  /* Whether xmlns="" has been encountered. */
402  bool hasUndeclaration = false;
403 
404  while(!n.isNull())
405  {
406  const QVector<QXmlName> &forNode = namespaces.value(toPreNumber(n));
407  const int len = forNode.size();
408  bool stopInheritance = false;
409 
410  for(int i = 0; i < len; ++i)
411  {
412  const QXmlName &nsb = forNode.at(i);
413 
415  {
416  stopInheritance = true;
417  continue;
418  }
419 
420  if(nsb.prefix() == StandardPrefixes::empty &&
422  {
423  hasUndeclaration = true;
424  continue;
425  }
426 
427  if(!hasPrefix(result, nsb.prefix()))
428  {
429  /* We've already encountered an undeclaration, so we're supposed to skip
430  * them. */
431  if(hasUndeclaration && nsb.prefix() == StandardPrefixes::empty)
432  continue;
433  else
434  result.append(nsb);
435  }
436  }
437 
438  if(stopInheritance)
439  break;
440  else
441  n = it->next();
442  }
443 
445 
446  return result;
447 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
Iterates along the ancestor or ancestor-or-self axis in an AccelTree.
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
static bool hasPrefix(const QVector< QXmlName > &nbs, const QXmlName::PrefixCode prefix)
Definition: qacceltree.cpp:574
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QHash< PreNumber, QVector< QXmlName > > namespaces
Definition: qacceltree_p.h:268
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
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
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
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ nextFromSimpleAxis()

QXmlNodeModelIndex AccelTree::nextFromSimpleAxis ( QAbstractXmlNodeModel::SimpleAxis  axis,
const QXmlNodeModelIndex origin 
) const
protectedvirtual

When QtXmlPatterns evaluate path expressions, it emulate them through a combination of calls with QSimpleXmlNodeModel::SimpleAxis values.

Therefore, the implementation of this function must return the node, if any, that appears on the axis emanating from the origin.

If no such node is available, a default constructed QXmlNodeModelIndex is returned.

QSimpleXmlNodeModel eliminates the need to handle redundant corner cases by guaranteeing that it will never ask for:

  • Children or siblings for attributes.
  • Children for comments, processing instructions, and text nodes.
  • Siblings or parents for document nodes.

A typical implementation performs a switch on the value of axis:

QXmlNodeModelIndex MyTreeModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const
{
// Convert the QXmlNodeModelIndex to a value that is specific to what we represent.
const MyValue value = toMyValue(ni);
switch(axis)
{
case Parent:
return toNodeIndex(value.parent());
case FirstChild:
// and so on
}
}

Implements QAbstractXmlNodeModel.

Definition at line 365 of file qacceltree.cpp.

367 {
368  Q_ASSERT_X(false, Q_FUNC_INFO, "This function is not supposed to be called.");
369  return QXmlNodeModelIndex();
370 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ nodesByIdref()

QVector< QXmlNodeModelIndex > AccelTree::nodesByIdref ( const QXmlName idref) const
virtual

Returns the elements and/or attributes that have an IDREF value equal to idref.

XQuery's idref() function calls this function.

The implementor guarantees that the nodes identified by the returned indexes are elements or attributes.

It is not sufficient for an attribute or element to merely be called idref. It must also be of type IDREF. Elements must be typed as xs:IDREF or xs:IDREFS, or, in the case of attributes, as IDREF or IDREFS in the schema.

In idref, the namespace URI and the prefix are undefined, and the local name is the ID that should be looked up.

See also
{http://www.w3.org/TR/xpath-functions/#func-idref}{XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.3 fn:idref}

Implements QAbstractXmlNodeModel.

Definition at line 743 of file qacceltree.cpp.

744 {
746 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64

◆ parent() [1/2]

QXmlNodeModelIndex AccelTree::parent ( const QXmlNodeModelIndex ni) const
virtual

Definition at line 241 of file qacceltree.cpp.

Referenced by baseUri(), and iterate().

242 {
243  const AccelTree::PreNumber p = basicData.at(toPreNumber(ni)).parent();
244 
245  if(p == -1)
246  return QXmlNodeModelIndex();
247  else
248  return createIndex(p);
249 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.

◆ parent() [2/2]

PreNumber QPatternist::AccelTree::parent ( const PreNumber  pre) const
inline

Returns the parent node of pre.

If pre parent doesn't have a parent node, the return value is undefined.

See also
hasParent()

Definition at line 307 of file qacceltree_p.h.

308  {
309  return basicData.at(pre).parent();
310  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ postNumber()

PostNumber QPatternist::AccelTree::postNumber ( const PreNumber  pre) const
inline

Definition at line 322 of file qacceltree_p.h.

Referenced by QPatternist::DescendantIterator< IncludeSelf >::DescendantIterator(), QPatternist::DescendantIterator< IncludeSelf >::next(), QPatternist::PrecedingIterator::next(), and printStats().

323  {
324  const BasicNodeData &b = basicData.at(pre);
325  return pre + b.size() - b.depth();
326  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276

◆ printStats()

void AccelTree::printStats ( const NamePool::Ptr np) const

Definition at line 90 of file qacceltree.cpp.

91 {
92  Q_ASSERT(np);
93 #ifdef QT_NO_DEBUG
94  Q_UNUSED(np); /* Needed when compiling in release mode. */
95 #else
96  const int len = basicData.count();
97 
98  pDebug() << "AccelTree stats for" << (m_documentURI.isEmpty() ? QString::fromLatin1("<empty URI>") : m_documentURI.toString());
99  pDebug() << "Maximum pre number:" << maximumPreNumber();
100  pDebug() << "+---------------+-------+-------+---------------+-------+--------------+-------+";
101  pDebug() << "| Pre number | Depth | Size | Post Number | Kind | Name | Value |";
102  pDebug() << "+---------------+-------+-------+---------------+-------+--------------+-------+";
103  for(int i = 0; i < len; ++i)
104  {
105  const BasicNodeData &v = basicData.at(i);
106  pDebug() << '|' << i
107  << "\t\t|" << v.depth()
108  << "\t|" << v.size()
109  << "\t|" << postNumber(i)
110  << "\t|" << v.kind()
111  << "\t\t|" << (v.name().isNull() ? QString::fromLatin1("(none)") : np->displayName(v.name()))
112  << "\t\t|" << ((v.kind() == QXmlNodeModelIndex::Text && isCompressed(i)) ? CompressedWhitespace::decompress(data.value(i))
113  : data.value(i))
114  << "\t|";
115  /*
116  pDebug() << '|' << QString().arg(i, 14)
117  << '|' << QString().arg(v.depth(), 6)
118  << '|' << QString().arg(v.size(), 6)
119  << '|' << QString().arg(postNumber(i), 14)
120  << '|' << QString().arg(v.kind(), 6)
121  << '|';
122  */
123  }
124  pDebug() << "+---------------+-------+-------+---------------+-------+--------------+";
125  pDebug() << "Namespaces(" << namespaces.count() << "):";
126 
127  QHashIterator<PreNumber, QVector<QXmlName> > it(namespaces);
128  while(it.hasNext())
129  {
130  it.next();
131 
132  pDebug() << "PreNumber: " << QString::number(it.key());
133  for(int i = 0; i < it.value().count(); ++i)
134  pDebug() << "\t\t" << np->stringForPrefix(it.value().at(i).prefix()) << " = " << np->stringForNamespace(it.value().at(i).namespaceURI());
135  }
136 
137 #endif
138 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
#define it(className, varName)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QHash< PreNumber, QVector< QXmlName > > namespaces
Definition: qacceltree_p.h:268
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isCompressed(const PreNumber pre) const
Definition: qacceltree_p.h:362
const QString & stringForPrefix(const QXmlName::PrefixCode code) const
Definition: qnamepool_p.h:174
static QString toString(Register *reg, int type, bool *ok=0)
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
A compression facility for whitespace nodes.
QHash< PreNumber, QString > data
Definition: qacceltree_p.h:274
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
const QString & stringForNamespace(const QXmlName::NamespaceCode code) const
Definition: qnamepool_p.h:180
PostNumber postNumber(const PreNumber pre) const
Definition: qacceltree_p.h:322
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
virtual QXmlName name(const QXmlNodeModelIndex &ni) const
Returns the name of ni.
Definition: qacceltree.cpp:379
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333
#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
The Text item allows you to add formatted text to a scene.
QNoDebug pDebug()
Definition: qdebug_p.h:99

◆ root()

QXmlNodeModelIndex AccelTree::root ( const QXmlNodeModelIndex n) const
virtual

Returns the root node.

This function does not use n, so a default constructed QXmlNodeModelIndex may be passed.

Implements QAbstractXmlNodeModel.

Definition at line 236 of file qacceltree.cpp.

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

237 {
238  return createIndex(qint64(0));
239 }
__int64 qint64
Definition: qglobal.h:942
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.

◆ sendNamespaces()

void AccelTree::sendNamespaces ( const QXmlNodeModelIndex n,
QAbstractXmlReceiver *const  receiver 
) const
virtual

Definition at line 449 of file qacceltree.cpp.

451 {
453 
455  QXmlNodeModelIndex next(it->next());
456  QVector<QXmlName::PrefixCode> alreadySent;
457 
458  while(!next.isNull())
459  {
460  const PreNumber preNumber = toPreNumber(next);
461 
462  const QVector<QXmlName> &nss = namespaces.value(preNumber);
463 
464  /* This is by far the most common case. */
465  if(nss.isEmpty())
466  {
467  next = it->next();
468  continue;
469  }
470 
471  const int len = nss.count();
472  bool stopInheritance = false;
473 
474  for(int i = 0; i < len; ++i)
475  {
476  const QXmlName &name = nss.at(i);
477 
479  {
480  stopInheritance = true;
481  continue;
482  }
483 
484  if(!alreadySent.contains(name.prefix()))
485  {
486  alreadySent.append(name.prefix());
487  receiver->namespaceBinding(name);
488  }
489  }
490 
491  if(stopInheritance)
492  break;
493  else
494  next = it->next();
495  }
496 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual void namespaceBinding(const QXmlName &nb)=0
Signals the presence of the namespace declaration nb.
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QXmlNodeModelIndex::Iterator::Ptr iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const
Performs navigation, starting from ni, by returning an QAbstractXmlForwardIterator that returns nodes...
Definition: qacceltree.cpp:251
QHash< PreNumber, QVector< QXmlName > > namespaces
Definition: qacceltree_p.h:268
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
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
virtual QXmlName name(const QXmlNodeModelIndex &ni) const
Returns the name of ni.
Definition: qacceltree.cpp:379
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
NodeKind kind() const
Definition: qitem_p.h:471

◆ sequencedTypedValue()

Item::Iterator::Ptr AccelTree::sequencedTypedValue ( const QXmlNodeModelIndex ni) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractXmlNodeModel.

Definition at line 593 of file qacceltree.cpp.

594 {
595  const PreNumber preNumber = toPreNumber(n);
596 
597  switch(kind(preNumber))
598  {
600  /* Fallthrough. */
602  /* Fallthrough. */
604  return makeSingletonIterator(Item(UntypedAtomic::fromValue(stringValue(n))));
605 
607  /* Fallthrough. */
609  /* Fallthrough. */
611  return makeSingletonIterator(Item(AtomicString::fromValue(stringValue(n))));
612  default:
613  {
614  Q_ASSERT_X(false, Q_FUNC_INFO,
615  qPrintable(QString::fromLatin1("A node type that doesn't exist "
616  "in the XPath Data Model was encountered.").arg(kind(preNumber))));
617  return Item::Iterator::Ptr(); /* Dummy, silence compiler warning. */
618  }
619  }
620 }
static UntypedAtomic::Ptr fromValue(const QString &value)
static AtomicString::Ptr fromValue(const QString &value)
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
virtual QString stringValue(const QXmlNodeModelIndex &n) const
Returns the string value for node n.
Definition: qacceltree.cpp:498
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ size()

PreNumber QPatternist::AccelTree::size ( const PreNumber  pre) const
inline

Definition at line 343 of file qacceltree_p.h.

Referenced by hasPrefix(), QPatternist::ChildIterator::next(), QPatternist::SiblingIterator< IsFollowing >::next(), QPatternist::FollowingIterator::next(), and stringValue().

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  }
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ sourceLocation()

QSourceLocation AccelTree::sourceLocation ( const QXmlNodeModelIndex index) const
private

Returns the source location for the object with the given index.

Definition at line 709 of file qacceltree.cpp.

Referenced by QPatternist::AccelTreePrivate::sourceLocation().

710 {
711  const PreNumber key = toPreNumber(index);
712  if (sourcePositions.contains(key)) {
714  return QSourceLocation(m_documentURI, position.first, position.second);
715  } else {
716  return QSourceLocation();
717  }
718 }
T1 first
Definition: qpair.h:65
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
T2 second
Definition: qpair.h:66
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
The QSourceLocation class identifies a location in a resource by URI, line, and column.
int key
QHash< PreNumber, QPair< qint64, qint64 > > sourcePositions
Definition: qacceltree_p.h:277

◆ stringValue()

QString AccelTree::stringValue ( const QXmlNodeModelIndex n) const
virtual

Returns the string value for node n.

The caller guarantees that n is not null and that it belong to this QAbstractXmlNodeModel instance.

This function maps to the dm:string-value() accessor, which the specification completely specifies. Here's a summary:

  • For processing instructions, the string value is the data section(excluding any whitespace appearing between the name and the data).

  • For text nodes, the string value equals the text node.

  • For comments, the content of the comment

  • For elements, the concatenation of all text nodes that are descendants. Note, this is not only the children, but the childrens' childrens' text nodes, and so forth.

  • For document nodes, the concatenation of all text nodes in the document.

See also
{http://www.w3.org/TR/xpath-datamodel/#dm-string-value}{XQuery 1.0 and XPath 2.0 Data Model (XDM), 5.13 string-value Accessor}

Implements QAbstractXmlNodeModel.

Definition at line 498 of file qacceltree.cpp.

Referenced by sequencedTypedValue(), and typedValue().

499 {
500  const PreNumber preNumber = toPreNumber(ni);
501 
502  switch(kind(preNumber))
503  {
505  {
506  /* Concatenate all text nodes that are descendants of this node. */
507  if(!hasChildren(preNumber))
508  return QString();
509 
510  const AccelTree::PreNumber stop = preNumber + size(preNumber);
511  AccelTree::PreNumber pn = preNumber + 1; /* Jump over ourselves. */
512  QString result;
513 
514  for(; pn <= stop; ++pn)
515  {
516  if(kind(pn) == QXmlNodeModelIndex::Text)
517  {
518  if(isCompressed(pn))
520  else
521  result += data.value(pn);
522  }
523  }
524 
525  return result;
526  }
528  {
529  if(isCompressed(preNumber))
530  return CompressedWhitespace::decompress(data.value(preNumber));
531  /* Else, fallthrough. It's not compressed so use it as it is. */
532  }
534  /* Fallthrough */
536  /* Fallthrough */
538  return data.value(preNumber);
540  {
541  /* Concatenate all text nodes in the whole document. */
542 
543  QString result;
544  // Perhaps we can QString::reserve() the result based on the size?
546 
547  for(AccelTree::PreNumber i = 0; i <= max; ++i)
548  {
550  {
551  if(isCompressed(i))
553  else
554  result += data.value(i);
555  }
556  }
557 
558  return result;
559  }
560  default:
561  {
562  Q_ASSERT_X(false, Q_FUNC_INFO,
563  "A node type that doesn't exist in the XPath Data Model was encountered.");
564  return QString(); /* Dummy, silence compiler warning. */
565  }
566  }
567 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isCompressed(const PreNumber pre) const
Definition: qacceltree_p.h:362
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
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
QHash< PreNumber, QString > data
Definition: qacceltree_p.h:274
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333
PreNumber size(const PreNumber pre) const
Definition: qacceltree_p.h:343
static QString decompress(const QString &input)
Decompresses input into a usual QString.
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ toPreNumber()

PreNumber QPatternist::AccelTree::toPreNumber ( const QXmlNodeModelIndex  n) const
inline

Definition at line 338 of file qacceltree_p.h.

Referenced by baseUri(), documentUri(), iterate(), kind(), name(), namespaceBindings(), parent(), sendNamespaces(), sequencedTypedValue(), sourceLocation(), stringValue(), and type().

339  {
340  return n.data();
341  }
qint64 data() const
Returns the first data value.

◆ type()

ItemType::Ptr AccelTree::type ( const QXmlNodeModelIndex ni) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractXmlNodeModel.

Definition at line 587 of file qacceltree.cpp.

588 {
589  /* kind() is manually inlined here to avoid a virtual call. */
590  return XPathHelper::typeFromKind(basicData.at(toPreNumber(ni)).kind());
591 }
PreNumber toPreNumber(const QXmlNodeModelIndex n) const
Definition: qacceltree_p.h:338
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
static QPatternist::ItemTypePtr typeFromKind(const QXmlNodeModelIndex::NodeKind nodeKind)

◆ typedValue()

QVariant AccelTree::typedValue ( const QXmlNodeModelIndex node) const
virtual

Returns the typed value for node node.

The typed value is an atomic value, which an element or attribute contains.

The caller guarantees that node is either an element or an attribute. The implementor guarantees that the returned QVariant has a value which is supported in XQuery. It cannot be an arbitrary QVariant value. The implementor also guarantees that stringValue() returns a lexical representation of typedValue()(this is guaranteed by QSimpleXmlNodeModel::stringValue()).

If the return QVariant is a default constructed variant, it signals that node has no typed value.

Implements QAbstractXmlNodeModel.

Definition at line 569 of file qacceltree.cpp.

570 {
571  return stringValue(n);
572 }
virtual QString stringValue(const QXmlNodeModelIndex &n) const
Returns the string value for node n.
Definition: qacceltree.cpp:498

Friends and Related Functions

◆ AccelTreeBuilder< false >

friend class AccelTreeBuilder< false >
friend

Definition at line 253 of file qacceltree_p.h.

◆ AccelTreeBuilder< true >

friend class AccelTreeBuilder< true >
friend

Definition at line 254 of file qacceltree_p.h.

◆ AccelTreePrivate

friend class AccelTreePrivate
friend

Definition at line 94 of file qacceltree_p.h.

Properties

◆ basicData

QVector<BasicNodeData> QPatternist::AccelTree::basicData

◆ data

QHash<PreNumber, QString> QPatternist::AccelTree::data

Stores data for nodes. The QHash's value is the data of the processing instruction, and the content of a text node or comment.

Definition at line 274 of file qacceltree_p.h.

Referenced by AccelTree(), printStats(), and stringValue().

◆ m_baseURI

QUrl QPatternist::AccelTree::m_baseURI

Definition at line 370 of file qacceltree_p.h.

◆ m_documentURI

QUrl QPatternist::AccelTree::m_documentURI

Definition at line 369 of file qacceltree_p.h.

Referenced by printStats(), and sourceLocation().

◆ m_IDs

QHash<QXmlName::LocalNameCode, PreNumber> QPatternist::AccelTree::m_IDs
private

The key is the xml:id value, and the value is the element with that value.

Definition at line 394 of file qacceltree_p.h.

Referenced by elementById().

◆ namespaces

QHash<PreNumber, QVector<QXmlName> > QPatternist::AccelTree::namespaces

The key is the pre number of an element, and the value is a vector containing the namespace declarations being declared on that element. Therefore, it does not reflect the namespaces being in scope for that element. For that, a walk along axis ancestor is necessary.

Definition at line 268 of file qacceltree_p.h.

Referenced by namespaceBindings(), printStats(), and sendNamespaces().

◆ sourcePositions

QHash<PreNumber, QPair<qint64, qint64> > QPatternist::AccelTree::sourcePositions

Definition at line 277 of file qacceltree_p.h.

Referenced by sourceLocation().


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