Qt 4.8
qdocumentprojector.cpp
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 #include "qdocumentprojector_p.h"
43 
45 
46 using namespace QPatternist;
47 
49  QAbstractXmlReceiver *const receiver) : m_paths(paths)
50  , m_pathCount(paths.count())
51  , m_action(ProjectedExpression::Move)
52  , m_nodesInProcess(0)
53  , m_receiver(receiver)
54 {
55  Q_ASSERT_X(paths.count() > 0, Q_FUNC_INFO,
56  "Using DocumentProjector with no paths is an "
57  "overhead and has also undefined behavior.");
59 }
60 
62 {
63  Q_UNUSED(name);
64 
65  switch(m_action)
66  {
68  {
69  m_receiver->startElement(name);
70  /* Fallthrough. */
71  }
73  {
75  return;
76  }
77  default:
78  {
80  "We're not supposed to receive Keep here, because "
81  "endElement() should always end that state.");
82 
83  for(int i = 0; i < m_pathCount; ++i)
84  {
85  m_action = m_paths.at(i)->actionForElement(name, m_paths[i]);
86 
87  switch(m_action)
88  {
90  {
92  continue;
93  }
95  {
96  /* Ok, at least one path wanted this node. Pass it on,
97  * and exit. */
98  m_receiver->startElement(name);
100  return;
101  }
103  {
104  /* This particular path doesn't need it, but
105  * some other path might, so continue looping. */
106  continue;
107  }
109  Q_ASSERT_X(false, Q_FUNC_INFO, "The action functions can never return Move.");
110  }
111  }
112 
114 
116  m_receiver->startElement(name);
117  else
118  {
120  }
121  }
122  }
123 }
124 
126 {
128  {
130 
132 
133  /* We have now kept the single node, and now wants to skip
134  * all its children. */
136  m_nodesInProcess = 0;
137  }
139  {
142 
143  if(m_nodesInProcess == 0)
144  {
145  /* We have now skipped all the children, let's do
146  * a new path analysis. */
148  }
149  }
150  else
151  {
153  "We're not supposed to be in a Move action here.");
154  /* We skip calling m_receiver's endElement() here since we're
155  * skipping. */
158 
159  if(m_nodesInProcess == 0)
160  {
161  /* Ok, we've skipped them all, let's do something
162  * new -- let's Move on to the next path! */
164  }
165  }
166 }
167 
169  const QString &value)
170 {
171  Q_UNUSED(name);
172  Q_UNUSED(value);
173 }
174 
176 {
177  Q_UNUSED(nb);
178 }
179 
181 {
183  "Invalid input; it's the caller's responsibility to ensure the input is correct.");
184  Q_UNUSED(value);
185 }
186 
188 {
189  Q_UNUSED(value);
190 }
191 
193  const QString &value)
194 {
196  "Invalid input; it's the caller's responsibility to ensure the input is correct.");
197  Q_UNUSED(name);
198  Q_UNUSED(value);
199 }
200 
201 void DocumentProjector::item(const Item &outputItem)
202 {
203  Q_UNUSED(outputItem);
204 }
205 
207 {
208 }
209 
211 {
212 }
213 
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
virtual void namespaceBinding(const QXmlName nb)
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
virtual void characters(const QString &value)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
virtual void attribute(const QXmlName name, const QString &value)
Signals the presence of an attribute node.
virtual void endElement()
Signals the end of the current element.
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
virtual void processingInstruction(const QXmlName name, const QString &value)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
QAbstractXmlReceiver *const m_receiver
The namespace for the internal API of QtXmlPatterns.
ProjectedExpression::Vector m_paths
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual Action actionForElement(const QXmlName name, ProjectedExpression::Ptr &next) const
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
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual void item(const Item &item)
Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue...
virtual void comment(const QString &value)
virtual void startElement(const QXmlName name)
Signals the start of an element by name name.
ProjectedExpression::Action m_action
DocumentProjector(const ProjectedExpression::Vector &paths, QAbstractXmlReceiver *const receiver)
#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