Qt 4.8
Public Types | Public Functions | Static Public Functions | List of all members
QPatternist::AtomicComparator Class Referenceabstract

Base class for classes responsible of comparing two atomic values. More...

#include <qatomiccomparator_p.h>

Inheritance diagram for QPatternist::AtomicComparator:
QPatternist::AtomicTypeVisitorResult QSharedData QPatternist::AbstractDateTimeComparator QPatternist::AbstractDurationComparator QPatternist::AbstractFloatComparator QPatternist::BinaryDataComparator QPatternist::BooleanComparator QPatternist::CaseInsensitiveStringComparator QPatternist::DecimalComparator QPatternist::IntegerComparator QPatternist::QNameComparator QPatternist::StringComparator

Public Types

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
 

Public Functions

 AtomicComparator ()
 
virtual ComparisonResult compare (const Item &op1, const AtomicComparator::Operator op, const Item &op2) const
 
virtual bool equals (const Item &op1, const Item &op2) const =0
 
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...
 

Static Public Functions

static QString displayName (const AtomicComparator::Operator op, const ComparisonType type)
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Base class for classes responsible of comparing two atomic values.

This class is also known as the AtomicParrot.

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

Definition at line 77 of file qatomiccomparator_p.h.

Typedefs

◆ Operators

Definition at line 140 of file qatomiccomparator_p.h.

◆ Ptr

Definition at line 83 of file qatomiccomparator_p.h.

Enumerations

◆ ComparisonResult

Signifies the result of a value comparison. This is used for value comparisons, and in the future likely also for sorting.

See also
W3C XML Path Language (XPath) 2.0, 3.5.1 Value Comparisons
Enumerator
LessThan 
Equal 
GreaterThan 
Incomparable 

Definition at line 149 of file qatomiccomparator_p.h.

◆ ComparisonType

Identifies the kind of comparison.

Enumerator
AsGeneralComparison 

Identifies a general comparison; operator =, >, <=, and so on.

AsValueComparison 

Identifies a value comparison; operator eq, lt, le, and so on.

Definition at line 188 of file qatomiccomparator_p.h.

◆ Operator

Identifies operators used in value comparisons.

The enum values are bit-significant.

See also
W3C XML Path Language (XPath) 2.0, 3.5.1 Value Comparisons
Enumerator
OperatorEqual 

Operator eq and =.

OperatorNotEqual 

Operator ne and !=.

OperatorGreaterThan 

Operator gt and >.

OperatorLessThan 

Operator lt and <.

OperatorLessThanNaNLeast 

One of the operators we use for sorting. The only difference from OperatorLessThan is that it sees NaN as ordered and smaller than other numbers.

OperatorLessThanNaNGreatest 

One of the operators we use for sorting. The only difference from OperatorLessThanLeast is that it sees NaN as ordered and larger than other numbers.

OperatorGreaterOrEqual 

Operator ge and >=.

OperatorLessOrEqual 

Operator le and <=.

Definition at line 93 of file qatomiccomparator_p.h.

Constructors and Destructors

◆ AtomicComparator()

AtomicComparator::AtomicComparator ( )

Definition at line 50 of file qatomiccomparator.cpp.

51 {
52 }

◆ ~AtomicComparator()

AtomicComparator::~AtomicComparator ( )
virtual

Definition at line 54 of file qatomiccomparator.cpp.

55 {
56 }

Functions

◆ compare()

AtomicComparator::ComparisonResult AtomicComparator::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 in QPatternist::AbstractDurationComparator, QPatternist::AbstractDateTimeComparator, QPatternist::IntegerComparator, QPatternist::DecimalComparator, QPatternist::AbstractFloatSortComparator< t_op >, QPatternist::AbstractFloatComparator, QPatternist::BooleanComparator, QPatternist::CaseInsensitiveStringComparator, and QPatternist::StringComparator.

Definition at line 59 of file qatomiccomparator.cpp.

62 {
63  Q_ASSERT_X(false, Q_FUNC_INFO, "This function should never be called.");
64  return LessThan;
65 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ displayName()

QString AtomicComparator::displayName ( const AtomicComparator::Operator  op,
const ComparisonType  type 
)
static

Utility function for getting the lexical representation for the comparison operator op. Depending on the type argument, the string returned is either a general comparison or a value comparison operator.

Parameters
opthe operator which the display name should be determined for.
typesignifies whether the returned display name should be for a value comparison or a general comparison. For example, if op is OperatorEqual and type is AsValueComparision, "eq" is returned.

Definition at line 67 of file qatomiccomparator.cpp.

69 {
72  {
73  switch(op)
74  {
75  case OperatorEqual:
76  return QLatin1String("=");
78  return QLatin1String("<=");
80  return QLatin1String("<");
82  return QLatin1String(">=");
84  /* Fallthrough. */
86  /* Fallthrough. */
87  case OperatorLessThan:
88  return QLatin1String(">");
89  case OperatorNotEqual:
90  return QLatin1String("!=");
91  }
92  }
93 
94  switch(op)
95  {
96  case OperatorEqual:
97  return QLatin1String("eq");
99  return QLatin1String("ge");
100  case OperatorGreaterThan:
101  return QLatin1String("gt");
102  case OperatorLessOrEqual:
103  return QLatin1String("le");
105  /* Fallthrough. */
107  /* Fallthrough. */
108  case OperatorLessThan:
109  return QLatin1String("lt");
110  case OperatorNotEqual:
111  return QLatin1String("ne");
112  }
113 
114  Q_ASSERT(false);
115  return QString(); /* GCC unbarfer. */
116 }
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ equals()

virtual bool QPatternist::AtomicComparator::equals ( const Item op1,
const Item op2 
) const
pure 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

Implemented in QPatternist::AbstractDurationComparator, QPatternist::AbstractDateTimeComparator, QPatternist::QNameComparator, QPatternist::IntegerComparator, QPatternist::DecimalComparator, QPatternist::AbstractFloatComparator, QPatternist::BooleanComparator, QPatternist::BinaryDataComparator, QPatternist::CaseInsensitiveStringComparator, and QPatternist::StringComparator.


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