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

Compares xs:double values. More...

#include <qatomiccomparators_p.h>

Inheritance diagram for QPatternist::AbstractFloatComparator:
QPatternist::AtomicComparator QPatternist::AtomicTypeVisitorResult QSharedData QPatternist::AbstractFloatSortComparator< t_op >

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:double values.

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

Definition at line 166 of file qatomiccomparators_p.h.

Functions

◆ compare()

AtomicComparator::ComparisonResult AbstractFloatComparator::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

Reimplemented from QPatternist::AtomicComparator.

Reimplemented in QPatternist::AbstractFloatSortComparator< t_op >.

Definition at line 156 of file qatomiccomparators.cpp.

159 {
160  const xsDouble v1 = o1.as<Numeric>()->toDouble();
161  const xsDouble v2 = o2.as<Numeric>()->toDouble();
162 
163  if(Double::isEqual(v1, v2))
164  return Equal;
165  else if(v1 < v2)
166  return LessThan;
167  else if(v1 > v2)
168  return GreaterThan;
169  else
170  {
171  /* We have NaN values. Make sure we don't return a result which would
172  * signify success for the operator in question. */
173  if((op & OperatorGreaterThan) == OperatorGreaterThan)
174  return LessThan;
175  else
176  {
177  Q_ASSERT((op & OperatorLessThan) == OperatorLessThan);
178  return GreaterThan;
179  }
180  }
181 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static bool isEqual(const xsDouble a, const xsDouble b)
Base class for all numeric values.
static qreal toDouble(const QChar *&str)

◆ equals()

bool AbstractFloatComparator::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 183 of file qatomiccomparators.cpp.

185 {
186  return Double::isEqual(o1.as<Numeric>()->toDouble(), o2.as<Numeric>()->toDouble());
187 }
static bool isEqual(const xsDouble a, const xsDouble b)
Base class for all numeric values.
virtual xsDouble toDouble() const =0
static qreal toDouble(const QChar *&str)

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