source: trunk/src/xmlpatterns/projection/qdocumentprojector.cpp@ 1023

Last change on this file since 1023 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qdocumentprojector_p.h"
43
44QT_BEGIN_NAMESPACE
45
46using namespace QPatternist;
47
48DocumentProjector::DocumentProjector(const ProjectedExpression::Vector &paths,
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.");
58 Q_ASSERT(m_receiver);
59}
60
61void DocumentProjector::startElement(const QXmlName name)
62{
63 Q_UNUSED(name);
64
65 switch(m_action)
66 {
67 case ProjectedExpression::KeepSubtree:
68 {
69 m_receiver->startElement(name);
70 /* Fallthrough. */
71 }
72 case ProjectedExpression::Skip:
73 {
74 ++m_nodesInProcess;
75 return;
76 }
77 default:
78 {
79 Q_ASSERT_X(m_action == ProjectedExpression::Move, Q_FUNC_INFO,
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 {
89 case ProjectedExpression::Keep:
90 {
91 m_action = ProjectedExpression::Keep;
92 continue;
93 }
94 case ProjectedExpression::KeepSubtree:
95 {
96 /* Ok, at least one path wanted this node. Pass it on,
97 * and exit. */
98 m_receiver->startElement(name);
99 ++m_nodesInProcess;
100 return;
101 }
102 case ProjectedExpression::Skip:
103 {
104 /* This particular path doesn't need it, but
105 * some other path might, so continue looping. */
106 continue;
107 }
108 case ProjectedExpression::Move:
109 Q_ASSERT_X(false, Q_FUNC_INFO, "The action functions can never return Move.");
110 }
111 }
112
113 ++m_nodesInProcess;
114