Qt 4.8
qsequencefns_p.h
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 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_SequenceFNs_H
53 #define Patternist_SequenceFNs_H
54 
55 #include "qatomiccomparator_p.h"
56 #include "qcomparisonplatform_p.h"
57 #include "qliteral_p.h"
58 #include "qfunctioncall_p.h"
59 
72 
74 
75 namespace QPatternist
76 {
84  class BooleanFN : public FunctionCall
85  {
86  public:
87  virtual bool evaluateEBV(const DynamicContext::Ptr &context) const;
88 
94  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
95  const SequenceType::Ptr &reqType);
96  };
97 
104  class IndexOfFN : public FunctionCall,
105  public ComparisonPlatform<IndexOfFN, false>
106  {
107  public:
109  {
110  }
111 
112  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
113  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
114  const SequenceType::Ptr &reqType);
115 
117  {
119  }
120  };
121 
131  template<const Expression::ID Id>
132  class Existence : public FunctionCall
133  {
134  public:
135  virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
136  {
137  if(Id == IDExistsFN)
138  return !m_operands.first()->evaluateSequence(context)->isEmpty();
139  else
140  return m_operands.first()->evaluateSequence(context)->isEmpty();
141  }
142 
148  {
149  // RVCT doesn't like using template parameter in trinary operator when the trinary operator result is
150  // passed directly into another constructor.
151  Q_ASSERT(Id == IDExistsFN || Id == IDEmptyFN);
152 
153  const Expression::Ptr me(FunctionCall::compress(context));
154 
155  if(me != this)
156  return me;
157 
158  // RVCT doesn't like using template parameter in trinary operator when the trinary operator result is
159  // passed directly into another constructor.
160  Expression::ID tempId = Id;
161  const Cardinality myCard((tempId == IDExistsFN) ? Cardinality::oneOrMore() : Cardinality::empty());
162 
163  const Cardinality card(m_operands.first()->staticType()->cardinality());
164  if(myCard.isMatch(card))
165  { /* Since the dynamic type always is narrower than the static type or equal, and that the
166  static type is in scope, it means we will always be true. */
167  return wrapLiteral(CommonValues::BooleanTrue, context, this);
168  }
169  else
170  {
171  /* Is it even possible to hit? */
172  if(myCard.canMatch(card))
173  {
174  return me;
175  }
176  else
177  { /* We can never hit. */
178  return wrapLiteral(CommonValues::BooleanFalse, context, this);
179  }
180  }
181  }
182  };
183 
191  public ComparisonPlatform<IndexOfFN, false>
192  {
193  public:
195  {
196  }
197 
198  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
204  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
205  const SequenceType::Ptr &reqType);
213  virtual SequenceType::Ptr staticType() const;
214 
215  protected:
217  {
219  }
220  };
221 
231  {
232  public:
233  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
234  virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
235 
245  virtual SequenceType::Ptr staticType() const;
246  };
247 
254  class RemoveFN : public FunctionCall
255  {
256  public:
257  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
258  virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
259 
272  virtual SequenceType::Ptr staticType() const;
273  };
274 
281  class ReverseFN : public FunctionCall
282  {
283  public:
284 
285  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
286  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
287  const SequenceType::Ptr &reqType);
288 
300  virtual SequenceType::Ptr staticType() const;
301  };
302 
311  {
312  public:
313  SubsequenceFN();
314  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
315  virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
316 
317  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
318  const SequenceType::Ptr &reqType);
319 
325  virtual Expression::Ptr compress(const StaticContext::Ptr &context);
326 
333  virtual SequenceType::Ptr staticType() const;
334 
335  private:
337  };
338 }
339 
341 
343 
344 #endif
Base class for implementations of builtin functions.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static const AtomicValue::Ptr BooleanTrue
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
AtomicComparator::Operator operatorID() const
Implements the function fn:remove().
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual SequenceType::Ptr staticType() const
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
Implements the function fn:index-of().
static Cardinality empty()
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static Cardinality oneOrMore()
The namespace for the internal API of QtXmlPatterns.
Implements the function fn:distinct-values().
AtomicComparator::Operator operatorID() const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
bool canMatch(const Cardinality &other) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Implements the function fn:subsequence().
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Provides comparison functionality for classes that compare Items, such as ValueComparison or MaxFN...
Represents a cardinality, a possible , often represented by occurrence indicators.
bool isMatch(const Cardinality &other) const
static const AtomicValue::Ptr BooleanFalse
Implements the function fn:reverse().
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
Implements the function fn:boolean().
#define QT_END_HEADER
Definition: qglobal.h:137
Implements the functions fn:exists() and fn:empty().
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
Implements the function fn:insert-before().
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const