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

Performs division or multiplication between either DayTimeDuration or YearMonthDuration and Double values. More...

#include <qatomicmathematicians_p.h>

Inheritance diagram for QPatternist::DurationNumericMathematician:
QPatternist::AtomicMathematician QPatternist::DelegatingSourceLocationReflection QPatternist::AtomicTypeVisitorResult QPatternist::SourceLocationReflection QSharedData

Public Functions

virtual Item calculate (const Item &o1, const Operator op, const Item &o2, const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
 DurationNumericMathematician (const SourceLocationReflection *const r)
 
- Public Functions inherited from QPatternist::AtomicMathematician
virtual ~AtomicMathematician ()
 
- 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...
 
- Public Functions inherited from QPatternist::DelegatingSourceLocationReflection
virtual const SourceLocationReflectionactualReflection () const
 
 DelegatingSourceLocationReflection (const SourceLocationReflection *const r)
 
virtual QString description () const
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::AtomicMathematician
enum  Operator {
  Div = 1, IDiv = 2, Substract = 4, Mod = 8,
  Multiply = 16, Add = 32
}
 
typedef QFlags< OperatorOperators
 
typedef QExplicitlySharedDataPointer< AtomicMathematicianPtr
 
- Public Types inherited from QPatternist::AtomicTypeVisitorResult
typedef QExplicitlySharedDataPointer< AtomicTypeVisitorResultPtr
 
- Static Public Functions inherited from QPatternist::AtomicMathematician
static QString displayName (const AtomicMathematician::Operator op)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Performs division or multiplication between either DayTimeDuration or YearMonthDuration and Double values.

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

Definition at line 116 of file qatomicmathematicians_p.h.

Constructors and Destructors

◆ DurationNumericMathematician()

QPatternist::DurationNumericMathematician::DurationNumericMathematician ( const SourceLocationReflection *const  r)
inline

Definition at line 120 of file qatomicmathematicians_p.h.

121  {
122  }
DelegatingSourceLocationReflection(const SourceLocationReflection *const r)

Functions

◆ calculate()

Item DurationNumericMathematician::calculate ( const Item o1,
const Operator  op,
const Item o2,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
) const
virtual

Implements QPatternist::AtomicMathematician.

Definition at line 183 of file qatomicmathematicians.cpp.

187 {
188  Q_ASSERT(op == Div || op == Multiply);
189 
190  const AbstractDuration::Ptr duration(o1.as<AbstractDuration>());
191  const xsDouble dbl = o2.as<Numeric>()->toDouble();
192 
193  switch(op)
194  {
195  case Div:
196  {
197  if(qIsInf(dbl))
198  return duration->fromValue(0);
199  else if(qIsNaN(dbl))
200  {
201  context->error(QtXmlPatterns::tr(
202  "Dividing a value of type %1 by %2 (not-a-number) "
203  "is not allowed.")
204  .arg(formatType(context->namePool(),
205  duration->type()))
206  .arg(formatData("NaN")),
208  this);
209  return Item();
210  }
211  else if(Double::isEqual(dbl, 0))
212  {
213  context->error(QtXmlPatterns::tr(
214  "Dividing a value of type %1 by %2 or %3 (plus or "
215  "minus zero) is not allowed.")
216  .arg(formatType(context->namePool(),
217  duration->type()))
218  .arg(formatData("-0"))
219  .arg(formatData("0")),
221  this);
222  return Item();
223  }
224 
225  return duration->fromValue(static_cast<AbstractDuration::Value>(duration->value() / dbl));
226  }
227  case Multiply:
228  {
229  if(Double::isEqual(dbl, 0))
230  return duration->fromValue(0);
231  else if(qIsNaN(dbl))
232  {
233  context->error(QtXmlPatterns::tr(
234  "Dividing a value of type %1 by %2 (not-a-number) "
235  "is not allowed.")
236  .arg(formatType(context->namePool(),
237  duration->type()))
238  .arg(formatData("NaN")),
240  this);
241  return Item();
242  }
243  else if(qIsInf(dbl))
244  {
245  context->error(QtXmlPatterns::tr(
246  "Multiplication of a value of type %1 by %2 or %3 "
247  "(plus or minus infinity) is not allowed.")
248  .arg(formatType(context->namePool(),
249  duration->type()))
250  .arg(formatData("-INF"))
251  .arg(formatData("INF")),
253  this);
254  return Item();
255  }
256 
257  return duration->fromValue(static_cast<AbstractDuration::Value>(duration->value() * dbl));
258  }
259  default:
260  {
261  Q_ASSERT(false);
262  return Item(); /* Silence warning. */
263  }
264  }
265 }
virtual NamePool::Ptr namePool() const =0
Base class for classes implementing durations.
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
static QString formatData(const QString &data)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static bool isEqual(const xsDouble a, const xsDouble b)
Base class for all numeric values.
static qreal toDouble(const QChar *&str)
TCastTarget * as() const
Definition: qitem_p.h:278
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

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