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

Compares sub-classes of AbstractDateTime. More...

#include <qatomiccomparators_p.h>

Inheritance diagram for QPatternist::AbstractDateTimeComparator:
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 sub-classes of AbstractDateTime.

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

Definition at line 264 of file qatomiccomparators_p.h.

Functions

◆ compare()

AtomicComparator::ComparisonResult AbstractDateTimeComparator::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.

Definition at line 298 of file qatomiccomparators.cpp.

301 {
302  const QDateTime &dt1 = operand1.as<AbstractDateTime>()->toDateTime();
303  const QDateTime &dt2 = operand2.as<AbstractDateTime>()->toDateTime();
304 
305  if(dt1 == dt2)
306  return Equal;
307  else if(dt1 < dt2)
308  return LessThan;
309  else
310  return GreaterThan;
311 }
Base class for classes implementing values related to time, date or both.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216

◆ equals()

bool AbstractDateTimeComparator::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 279 of file qatomiccomparators.cpp.

281 {
282  const QDateTime dt1(o1.as<AbstractDateTime>()->toDateTime());
283  const QDateTime dt2(o2.as<AbstractDateTime>()->toDateTime());
284 
285  /*
286  pDebug() << "COMPARING:"
287  << o1->as<AbstractDateTime>()->toDateTime().toString()
288  << o2->as<AbstractDateTime>()->toDateTime().toString();
289  pDebug() << "DATE ONLY:"
290  << o1->as<AbstractDateTime>()->toDateTime().isDateOnly()
291  << o2->as<AbstractDateTime>()->toDateTime().isDateOnly();
292  */
293  return dt1 == dt2 &&
294  dt1.timeSpec() == dt2.timeSpec();
295 }
Base class for classes implementing values related to time, date or both.
const QDateTime & toDateTime() const
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Qt::TimeSpec timeSpec() const
Returns the time specification of the datetime.
Definition: qdatetime.cpp:2379

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