Qt 4.8
qcombinenodes.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 "qcommonsequencetypes_p.h"
43 #include "qexceptiterator_p.h"
44 #include "qgenericsequencetype_p.h"
45 #include "qintersectiterator_p.h"
46 #include "qitemmappingiterator_p.h"
47 #include "qnodesort_p.h"
48 #include "qunioniterator_p.h"
49 
50 #include "qcombinenodes_p.h"
51 
53 
54 using namespace QPatternist;
55 
57  const Operator op,
58  const Expression::Ptr &operand2) : PairContainer(operand1, operand2),
59  m_operator(op)
60 {
61  Q_ASSERT(op == Union ||
62  op == Except ||
63  op == Intersect);
64 }
65 
67 {
68  const Item::Iterator::Ptr op1(m_operand1->evaluateSequence(context));
69  const Item::Iterator::Ptr op2(m_operand2->evaluateSequence(context));
70 
71  switch(m_operator)
72  {
73  case Intersect:
74  return Item::Iterator::Ptr(new IntersectIterator(op1, op2));
75  case Except:
76  return Item::Iterator::Ptr(new ExceptIterator(op1, op2));
77  default:
78  {
80  return Item::Iterator::Ptr(new UnionIterator(op1, op2));
81  }
82  }
83 }
84 
86 {
87  return evaluateSequence(context)->next();
88 }
89 
91  const SequenceType::Ptr &reqType)
92 {
93 
94  const Expression::Ptr me(PairContainer::typeCheck(context, reqType));
95 
98 
99  return me;
100 }
101 
103 {
104  /* If it's the union operator, we can possibly avoid
105  * evaluating the second operand. */
106 
107  if(m_operator == Union)
108  {
109  return m_operand1->evaluateEBV(context) ||
110  m_operand2->evaluateEBV(context);
111  }
112  else
113  return PairContainer::evaluateEBV(context);
114 }
115 
117 {
118  switch(op)
119  {
120  case Intersect:
121  return QLatin1String("intersect");
122  case Except:
123  return QLatin1String("except");
124  default:
125  {
126  Q_ASSERT(op == Union);
127  return QLatin1String("union");
128  }
129  }
130 }
131 
133 {
136 
137  Cardinality card;
138 
139  /* Optimization: the cardinality can be better inferred for
140  * Intersect and Except, although it's not trivial code. */
141  if(m_operator == Union)
142  card = t1->cardinality() | t2->cardinality();
143  else /* Except. */
144  card = Cardinality::zeroOrMore();
145 
146  return makeGenericSequenceType(t1->itemType() | t2->itemType(), card);
147 }
148 
150 {
151  SequenceType::List result;
154  return result;
155 }
156 
158 {
159  return m_operator;
160 }
161 
163 {
164  return visitor->visit(this);
165 }
166 
168 {
169  return IDCombineNodes;
170 }
171 
static Cardinality zeroOrMore()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
Implements the except operator. That is, the computation of the sequence of nodes from one sequence...
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static const SequenceType::Ptr ZeroOrMoreNodes
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
CombineNodes(const Expression::Ptr &operand1, const Operator op, const Expression::Ptr &operand2)
virtual SequenceType::Ptr staticType() const
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual SequenceType::List expectedOperandTypes() const
The namespace for the internal API of QtXmlPatterns.
virtual SequenceType::Ptr staticType() const =0
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static QString displayName(const Operator op)
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Represents a cardinality, a possible , often represented by occurrence indicators.
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
Operator operatorID() const
static Expression::Ptr wrapAround(const Expression::Ptr &operand, const StaticContext::Ptr &context)
Definition: qnodesort.cpp:92
Implements the except operator. That is, the computation of the sequence of nodes from one sequence...
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const
Base class for expressions that has exactly two operands.
Implements the intersect operator. That is, the computation of the intersection between two sequences...