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

#include <qatomicmathematicians_p.h>

Inheritance diagram for QPatternist::DecimalMathematician:
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
 
 DecimalMathematician (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

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

Definition at line 75 of file qatomicmathematicians_p.h.

Constructors and Destructors

◆ DecimalMathematician()

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

Definition at line 79 of file qatomicmathematicians_p.h.

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

Functions

◆ calculate()

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

Implements QPatternist::AtomicMathematician.

Definition at line 84 of file qatomicmathematicians.cpp.

Referenced by QPatternist::DateTimeDurationMathematician::DateTimeDurationMathematician(), DecimalMathematician(), QPatternist::DurationNumericMathematician::DurationNumericMathematician(), and QPatternist::IntegerMathematician::IntegerMathematician().

88 {
89  switch(op)
90  {
91  case Div:
92  {
93  if(o2.as<Numeric>()->toInteger() == 0)
94  {
95  context->error(divZeroInvalid(), ReportContext::FOAR0001, this);
96  return Item(); /* Silences source code analyzer warning. */
97  }
98  else
99  return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() / o2.as<Numeric>()->toDecimal()));
100  }
101  case IDiv:
102  {
103  if(o2.as<Numeric>()->toInteger() == 0)
104  {
105  context->error(idivZeroInvalid(), ReportContext::FOAR0001, this);
106  return Item(); /* Silences source code analyzer warning. */
107  }
108  else
109  return Integer::fromValue(static_cast<xsInteger>(o1.as<Numeric>()->toDecimal() /
110  o2.as<Numeric>()->toDecimal()));
111  }
112  case Substract:
113  return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() - o2.as<Numeric>()->toDecimal()));
114  case Mod:
115  {
116  if(o2.as<Numeric>()->toInteger() == 0)
117  {
118  context->error(modZeroInvalid(), ReportContext::FOAR0001, this);
119  return Item(); /* Silences source code analyzer warning. */
120  }
121  else
122  return toItem(Decimal::fromValue(::fmod(o1.as<Numeric>()->toDecimal(), o2.as<Numeric>()->toDecimal())));
123  }
124  case Multiply:
125  return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() * o2.as<Numeric>()->toDecimal()));
126  case Add:
127  return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() + o2.as<Numeric>()->toDecimal()));
128  }
129 
130  Q_ASSERT(false);
131  return Item(); /* GCC unbarfer. */
132 }
virtual xsFloat toDecimal() const =0
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
static QString idivZeroInvalid()
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
static QString modZeroInvalid()
static Decimal::Ptr fromValue(const xsDecimal num)
Definition: qdecimal.cpp:59
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Base class for all numeric values.
virtual xsInteger toInteger() const =0
static QString divZeroInvalid()
TCastTarget * as() const
Definition: qitem_p.h:278

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