Qt 4.8
qnodecomparison.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 "qcommonvalues_p.h"
44 #include "qemptysequence_p.h"
45 #include "qinteger_p.h"
46 #include "qschemanumeric_p.h"
47 #include "qrangeiterator_p.h"
48 
49 #include "qnodecomparison_p.h"
50 
52 
53 using namespace QPatternist;
54 
57  const Expression::Ptr &operand2)
58  : PairContainer(operand1, operand2)
59  , m_op(op)
60 {
64 }
65 
67 {
68  switch(evaluate(context))
69  {
70  case True:
72  case False:
74  default:
75  return Item();
76  }
77 }
78 
80 {
81  switch(evaluate(context))
82  {
83  case True:
84  return true;
85  default:
86  /* We include the empty sequence here. */
87  return false;
88  }
89 }
90 
92 {
93  const Item op1(m_operand1->evaluateSingleton(context));
94  if(!op1)
95  return Empty;
96 
97  const Item op2(m_operand2->evaluateSingleton(context));
98  if(!op2)
99  return Empty;
100 
101  /* We just returns an arbitrary value, since there's no order defined for nodes from different
102  * models, except for that the return value must be stable. */
103  if(op1.asNode().model() != op2.asNode().model())
104  return False;
105 
106  switch(m_op)
107  {
109  return op1.asNode().is(op2.asNode()) ? True : False;
111  return op1.asNode().compareOrder(op2.asNode()) == QXmlNodeModelIndex::Precedes ? True : False;
112  default:
113  {
115  return op1.asNode().compareOrder(op2.asNode()) == QXmlNodeModelIndex::Follows ? True : False;
116  }
117  }
118 }
119 
120 
122 {
123  SequenceType::List result;
126  return result;
127 }
128 
130 {
131  const Expression::Ptr me(PairContainer::compress(context));
132 
133  if(me != this)
134  /* We're already rewritten. */
135  return me;
136 
139  {
140  // TODO issue a warning in the @p context saying that one of the operands
141  // were empty, and that the expression always result in the empty sequence
142  // (which never is the intent, right?).
143  return EmptySequence::create(this, context);
144  }
145 
146  return Expression::Ptr(this);
147 }
148 
150 {
151  switch(op)
152  {
154  return QLatin1String("is");
156  return QLatin1String("<<");
157  default:
158  {
160  return QLatin1String(">>");
161  }
162  }
163 }
164 
166 {
170  else
172 }
173 
175 {
176  return m_op;
177 }
178 
180 {
181  return visitor->visit(this);
182 }
183 
static const SequenceType::Ptr ZeroOrOneNode
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const AtomicValue::Ptr BooleanTrue
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
NodeComparison(const Expression::Ptr &operand1, const QXmlNodeModelIndex::DocumentOrder op, const Expression::Ptr &operand2)
static QString displayName(const QXmlNodeModelIndex::DocumentOrder op)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
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
virtual QXmlNodeModelIndex::DocumentOrder operatorID() const
DocumentOrder
Identifies the specific node comparison operator that should be used.
The namespace for the internal API of QtXmlPatterns.
virtual SequenceType::Ptr staticType() const
virtual Cardinality cardinality() const =0
static const SequenceType::Ptr ZeroOrOneBoolean
Result evaluate(const DynamicContext::Ptr &context) const
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
static const SequenceType::Ptr ExactlyOneBoolean
virtual SequenceType::Ptr staticType() const =0
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Contains class Numeric. This file was originally called qnumeric_p.h, but various build systems canno...
virtual Item evaluateSingleton(const DynamicContext::Ptr &) const
virtual bool evaluateEBV(const DynamicContext::Ptr &) const
static const AtomicValue::Ptr BooleanFalse
const QXmlNodeModelIndex::DocumentOrder m_op
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Base class for expressions that has exactly two operands.