Qt 4.8
Public Functions | List of all members
QPatternist::RemoveFN Class Reference

Implements the function fn:remove(). More...

#include <qsequencefns_p.h>

Inheritance diagram for QPatternist::RemoveFN:
QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual SequenceType::Ptr staticType () const
 
- Public Functions inherited from QPatternist::FunctionCall
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
virtual Expression::Properties properties () const
 
virtual void setSignature (const FunctionSignature::Ptr &sign)
 
virtual FunctionSignature::Ptr signature () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- Public Functions inherited from QPatternist::Expression
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::FunctionCall
typedef QExplicitlySharedDataPointer< FunctionCallPtr
 
- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Implements the function fn:remove().

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 254 of file qsequencefns_p.h.

Functions

◆ evaluateSequence()

Item::Iterator::Ptr RemoveFN::evaluateSequence ( const DynamicContext::Ptr context) const
virtual

Evaluate this Expression by iterating over it. This is a central function for evaluating expressions.

Expressions must always always return a valid QAbstractXmlForwardIterator and may never return 0. If an empty result is of interest to be returned, the EmptyIterator should be returned.

The default implementation returns a SingletonIterator over the item returned from evaluateSingleton().

Note
This function may raise an exception when calling, not only when QAbstractXmlForwardIterator::next() is called on the return value. This is because in some cases evaluateSingleton() is called directly.

Reimplemented from QPatternist::Expression.

Definition at line 162 of file qsequencefns.cpp.

163 {
164  const xsInteger pos = m_operands.last()->evaluateSingleton(context).as<Numeric>()->toInteger();
166 
167  if(pos < 1)
168  return it;
169 
170  return Item::Iterator::Ptr(new RemovalIterator(it, pos));
171 }
#define it(className, varName)
qint64 xsInteger
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
Base class for all numeric values.
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
TCastTarget * as() const
Definition: qitem_p.h:278
Removes one items at a specified position from an input QAbstractXmlForwardIterator.
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

Item RemoveFN::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented from QPatternist::Expression.

Definition at line 173 of file qsequencefns.cpp.

174 {
175  const xsInteger pos = m_operands.last()->evaluateSingleton(context).as<Numeric>()->toInteger();
176  if(pos <= 1)
177  return Item();
178 
179  return m_operands.first()->evaluateSingleton(context);
180 }
qint64 xsInteger
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Base class for all numeric values.
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
TCastTarget * as() const
Definition: qitem_p.h:278
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ staticType()

SequenceType::Ptr RemoveFN::staticType ( ) const
virtual

Implements the static enferences rules, "Since one item may be removed from the sequence, the resulting type is made optional:"

statEnv |- (FN-URI,"remove")(Type, Type1) : prime(Type) * quantifier(Type)?

However, because Patternist's type system is more fine grained than Formal Semantics, the sequence isn't made optional. Instead its minimum length is reduced with one.

See also
XQuery 1.0 and XPath 2.0 Formal Semantics, 7.2.11 The fn:remove function

Reimplemented from QPatternist::FunctionCall.

Definition at line 182 of file qsequencefns.cpp.

183 {
184  const SequenceType::Ptr opType(m_operands.first()->staticType());
185  const Cardinality c(opType->cardinality());
186 
187  if(c.minimum() == 0)
188  return makeGenericSequenceType(opType->itemType(), c);
189  else
190  {
191  return makeGenericSequenceType(opType->itemType(),
192  Cardinality::fromRange(c.minimum() - 1,
193  c.maximum()));
194  }
195 }
unsigned char c[8]
Definition: qnumeric_p.h:62
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual SequenceType::Ptr staticType() const =0
Represents a cardinality, a possible , often represented by occurrence indicators.
static Cardinality fromRange(const Count minimum, const Count maximum)

The documentation for this class was generated from the following files: