Qt 4.8
Public Functions | Static Private Functions | List of all members
QPatternist::AbstractDurationComparator Class Reference

Compares sub-classes of AbstractDuration. More...

#include <qatomiccomparators_p.h>

Inheritance diagram for QPatternist::AbstractDurationComparator:
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...
 

Static Private Functions

static QDateTime addDurationToDateTime (const QDateTime &dateTime, const AbstractDuration *const duration)
 

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 AbstractDuration.

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

Definition at line 279 of file qatomiccomparators_p.h.

Functions

◆ addDurationToDateTime()

QDateTime AbstractDurationComparator::addDurationToDateTime ( const QDateTime dateTime,
const AbstractDuration *const  duration 
)
inlinestaticprivate

Definition at line 323 of file qatomiccomparators.cpp.

325 {
326  QDateTime result(dateTime);
327  qint64 seconds = 0;
328 
329  const qint8 signMultiplier = (duration->isPositive() ? 1 : -1);
330 
331  result = result.addYears(signMultiplier * duration->years());
332  result = result.addMonths(signMultiplier * duration->months());
333  result = result.addDays(signMultiplier * duration->days());
334 
335  seconds = 60 * 60 * duration->hours();
336  seconds += 60 * duration->minutes();
337  seconds += duration->seconds();
338 
339  result = result.addSecs(signMultiplier * seconds);
340  result = result.addMSecs(signMultiplier * duration->mseconds());
341 
342  return result;
343 }
virtual SecondProperty seconds() const =0
virtual MinuteProperty minutes() const =0
virtual MonthProperty months() const =0
signed char qint8
Definition: qglobal.h:933
virtual DayCountProperty days() const =0
virtual HourProperty hours() const =0
__int64 qint64
Definition: qglobal.h:942
virtual YearProperty years() const =0
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
virtual MSecondProperty mseconds() const =0

◆ compare()

AtomicComparator::ComparisonResult AbstractDurationComparator::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 346 of file qatomiccomparators.cpp.

349 {
350  const AbstractDuration *const duration = o1.as<AbstractDuration>();
351  const AbstractDuration *const otherDuration = o2.as<AbstractDuration>();
352 
353  const QDateTime dateTime1(QDate(1696, 9, 1), QTime(0, 0, 0), Qt::UTC);
354  const QDateTime dateTime2(QDate(1697, 2, 1), QTime(0, 0, 0), Qt::UTC);
355  const QDateTime dateTime3(QDate(1903, 3, 1), QTime(0, 0, 0), Qt::UTC);
356  const QDateTime dateTime4(QDate(1903, 7, 1), QTime(0, 0, 0), Qt::UTC);
357 
358  const QDateTime durationDateTime1 = addDurationToDateTime(dateTime1, duration);
359  const QDateTime durationDateTime2 = addDurationToDateTime(dateTime2, duration);
360  const QDateTime durationDateTime3 = addDurationToDateTime(dateTime3, duration);
361  const QDateTime durationDateTime4 = addDurationToDateTime(dateTime4, duration);
362 
363  const QDateTime otherDurationDateTime1 = addDurationToDateTime(dateTime1, otherDuration);
364  const QDateTime otherDurationDateTime2 = addDurationToDateTime(dateTime2, otherDuration);
365  const QDateTime otherDurationDateTime3 = addDurationToDateTime(dateTime3, otherDuration);
366  const QDateTime otherDurationDateTime4 = addDurationToDateTime(dateTime4, otherDuration);
367 
368  if (durationDateTime1 > otherDurationDateTime1 &&
369  durationDateTime2 > otherDurationDateTime2 &&
370  durationDateTime3 > otherDurationDateTime3 &&
371  durationDateTime4 > otherDurationDateTime4) {
372  return GreaterThan;
373  } else if (durationDateTime1 < otherDurationDateTime1 &&
374  durationDateTime2 < otherDurationDateTime2 &&
375  durationDateTime3 < otherDurationDateTime3 &&
376  durationDateTime4 < otherDurationDateTime4) {
377  return LessThan;
378  } else if (*duration == *otherDuration) {
379  return Equal;
380  } else {
381  return Incomparable;
382  }
383 }
Base class for classes implementing durations.
The QDate class provides date functions.
Definition: qdatetime.h:55
The QTime class provides clock time functions.
Definition: qdatetime.h:148
const TCastTarget * as() const
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static QDateTime addDurationToDateTime(const QDateTime &dateTime, const AbstractDuration *const duration)

◆ equals()

bool AbstractDurationComparator::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 315 of file qatomiccomparators.cpp.

317 {
318  /* We use AbstractDuration::operator==() */
319  return *o1.as<AbstractDuration>() ==
320  *o2.as<AbstractDuration>();
321 }
Base class for classes implementing durations.
const TCastTarget * as() const

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