Qt 4.8
Public Functions | List of all members
QPatternist::AbstractFloatMathematician< isDouble > Class Template Reference

Performs arithmetics between AbstractFloat values (Float and Double classes). More...

#include <qabstractfloatmathematician_p.h>

Inheritance diagram for QPatternist::AbstractFloatMathematician< isDouble >:
QPatternist::AtomicMathematician QPatternist::DelegatingSourceLocationReflection QPatternist::AtomicTypeVisitorResult QPatternist::SourceLocationReflection QSharedData

Public Functions

 AbstractFloatMathematician (const SourceLocationReflection *const r)
 
virtual Item calculate (const Item &o1, const Operator op, const Item &o2, const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
- 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

template<const bool isDouble>
class QPatternist::AbstractFloatMathematician< isDouble >

Performs arithmetics between AbstractFloat values (Float and Double classes).

Author
Vincent Ricard magic.nosp@m.@mag.nosp@m.icnin.nosp@m.ja.o.nosp@m.rg

Definition at line 74 of file qabstractfloatmathematician_p.h.

Constructors and Destructors

◆ AbstractFloatMathematician()

template<const bool isDouble>
QPatternist::AbstractFloatMathematician< isDouble >::AbstractFloatMathematician ( const SourceLocationReflection *const  r)
inline

Definition at line 78 of file qabstractfloatmathematician_p.h.

79  {
80  }
DelegatingSourceLocationReflection(const SourceLocationReflection *const r)

Functions

◆ calculate()

template<const bool isDouble>
Item QPatternist::AbstractFloatMathematician< isDouble >::calculate ( const Item o1,
const Operator  op,
const Item o2,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
) const
virtual

Implements QPatternist::AtomicMathematician.

Definition at line 49 of file qabstractfloatmathematician.cpp.

Referenced by QPatternist::AbstractFloatMathematician< isDouble >::AbstractFloatMathematician().

53 {
54  const Numeric *const num1 = o1.template as<Numeric>();
55  const Numeric *const num2 = o2.template as<Numeric>();
56  switch(op)
57  {
58  case Div:
59  return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() / num2->toDouble()));
60  case IDiv:
61  {
62  if(num1->isNaN() || num2->isNaN())
63  {
64  context->error(QtXmlPatterns::tr("No operand in an integer division, %1, can be %2.")
65  .arg(formatKeyword("idiv"))
66  .arg(formatData("NaN")),
68  }
69  else if(num1->isInf())
70  {
71  context->error(QtXmlPatterns::tr("The first operand in an integer division, %1, cannot be infinity (%2).")
72  .arg(formatKeyword("idiv"))
73  .arg(formatData("INF")),
75  }
76  else if(num2->toInteger() == 0)
77  context->error(QtXmlPatterns::tr("The second operand in a division, %1, cannot be zero (%2).")
78  .arg(formatKeyword("idiv"))
79  .arg(formatData("0")),
81 
82  return Integer::fromValue(static_cast<xsInteger>(num1->toDouble() / num2->toDouble()));
83  }
84  case Substract:
85  return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() - num2->toDouble()));
86  case Mod:
87  return toItem(AbstractFloat<isDouble>::fromValue(::fmod(num1->toDouble(), num2->toDouble())));
88  case Multiply:
89  return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() * num2->toDouble()));
90  case Add:
91  return toItem(AbstractFloat<isDouble>::fromValue(num1->toDouble() + num2->toDouble()));
92  }
93 
94  Q_ASSERT(false);
95  return Item(); /* GCC unbarfer. */
96 }
QString formatKeyword(const QString &keyword)
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static Item fromValue(const xsInteger num)
Definition: qinteger.cpp:52
The Item is the most basic of all visual items in QML.
static QString formatData(const QString &data)
static Numeric::Ptr fromValue(const xsDouble num)

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