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

Compares xs:integer values. More...

#include <qatomiccomparators_p.h>

Inheritance diagram for QPatternist::IntegerComparator:
QPatternist::AtomicComparator QPatternist::AtomicTypeVisitorResult QSharedData

Public Functions

virtual ComparisonResult compare (const Item &op1, const AtomicComparator::Operator op, const Item &op2) const
 
virtual bool equals (const Item &op1, const Item &op2) const
 
- Public Functions inherited from QPatternist::AtomicComparator
 AtomicComparator ()
 
virtual ~AtomicComparator ()
 
- Public Functions inherited from QPatternist::AtomicTypeVisitorResult
 AtomicTypeVisitorResult ()
 
virtual ~AtomicTypeVisitorResult ()
 
- 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...
 

Additional Inherited Members

- Public Types inherited from QPatternist::AtomicComparator
enum  ComparisonResult { LessThan = 1, Equal = 2, GreaterThan = 4, Incomparable = 8 }
 
enum  ComparisonType { AsGeneralComparison = 1, AsValueComparison }
 
enum  Operator {
  OperatorEqual = 1, OperatorNotEqual = 1 << 1, OperatorGreaterThan = 1 << 2, OperatorLessThan = 1 << 3,
  OperatorLessThanNaNLeast = 1 << 4, OperatorLessThanNaNGreatest = 1 << 5, OperatorGreaterOrEqual = OperatorEqual | OperatorGreaterThan, OperatorLessOrEqual = OperatorEqual | OperatorLessThan
}
 
typedef QFlags< OperatorOperators
 
typedef QExplicitlySharedDataPointer< AtomicComparatorPtr
 
- Public Types inherited from QPatternist::AtomicTypeVisitorResult
typedef QExplicitlySharedDataPointer< AtomicTypeVisitorResultPtr
 
- Static Public Functions inherited from QPatternist::AtomicComparator
static QString displayName (const AtomicComparator::Operator op, const ComparisonType type)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Compares xs:integer values.

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

Definition at line 236 of file qatomiccomparators_p.h.

Functions

◆ compare()

AtomicComparator::ComparisonResult IntegerComparator::compare ( const Item op1,
const AtomicComparator::Operator  op,
const Item op2 
) const
virtual

Compares op1 and op2 and determines the relationship between the two. This is used for sorting and comparisons. The implementation performs an assert crash, and must therefore be re-implemented if comparing the relevant values should be possible.

Parameters
op1the first operand
opthe operator. How a comparison is carried out shouldn't depend on what the operator is, but in some cases it is of interest.
op2the second operand

Consider: xs:unsignedLong("100") > xs:unsignedLong("18446744073709551615")

If we perform math on the values as if they were xsInteger, the right operand overflows, wraps around, and the expression evaluates to false. Hence we have this code to deal with it.

This is runtime code, it would have been better if we had separate AtomicComparator classes for signed and unsigned values, but the changes required to the lookup code are extensive.

Reimplemented from QPatternist::AtomicComparator.

Definition at line 216 of file qatomiccomparators.cpp.

219 {
220  const Numeric *const num1 = o1.as<Numeric>();
221  const Numeric *const num2 = o1.as<Numeric>();
222 
235  if(num1->isSigned() || num2->isSigned())
236  {
237  const xsInteger v1 = o1.as<Numeric>()->toInteger();
238  const xsInteger v2 = o2.as<Numeric>()->toInteger();
239 
240  if(v1 == v2)
241  return Equal;
242  else if(v1 < v2)
243  return LessThan;
244  else
245  return GreaterThan;
246  }
247  else
248  {
249  const qulonglong v1 = o1.as<Numeric>()->toUnsignedInteger();
250  const qulonglong v2 = o2.as<Numeric>()->toUnsignedInteger();
251 
252  if(v1 == v2)
253  return Equal;
254  else if(v1 < v2)
255  return LessThan;
256  else
257  return GreaterThan;
258  }
259 }
qint64 xsInteger
virtual bool isSigned() const =0
Returns true if this value is signed. If false is returned, the value is unsigned.
const TCastTarget * as() const
Base class for all numeric values.
quint64 qulonglong
Definition: qglobal.h:952

◆ equals()

bool IntegerComparator::equals ( const Item op1,
const Item op2 
) const
virtual

Determines whether op1 and op2 are equal. It is the same as calling compare() and checking whether the return value is Equal, but since comparison testing is such a common operation, this specialized function exists.

Returns
true if op1 and op2 are equal.
Parameters
op1the first operand
op2the second operand

Implements QPatternist::AtomicComparator.

Definition at line 261 of file qatomiccomparators.cpp.

263 {
264  return o1.as<Numeric>()->toInteger() == o2.as<Numeric>()->toInteger();
265 }
const TCastTarget * as() const
Base class for all numeric values.

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