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

Performs arithmetics between Integer values. More...

#include <qatomicmathematicians_p.h>

Inheritance diagram for QPatternist::IntegerMathematician:
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
 
 IntegerMathematician (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 arithmetics between Integer values.

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

Definition at line 95 of file qatomicmathematicians_p.h.

Constructors and Destructors

◆ IntegerMathematician()

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

Definition at line 99 of file qatomicmathematicians_p.h.

100  {
101  }
DelegatingSourceLocationReflection(const SourceLocationReflection *const r)

Functions

◆ calculate()

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

Implements QPatternist::AtomicMathematician.

Definition at line 134 of file qatomicmathematicians.cpp.

138 {
139  switch(op)
140  {
141  case Div:
142  if(o2.as<Numeric>()->toInteger() == 0)
143  {
144  context->error(divZeroInvalid(), ReportContext::FOAR0001, this);
145  return Item(); /* Silences source code analyzer warning. */
146  }
147  else /* C++ automatically performs truncation of long integer(xsInteger). */
148  return toItem(Decimal::fromValue(o1.as<Numeric>()->toDecimal() / o2.as<Numeric>()->toDecimal()));
149  case IDiv:
150  {
151  if(o2.as<Numeric>()->toInteger() == 0)
152  {
153  context->error(idivZeroInvalid(), ReportContext::FOAR0001, this);
154  return Item(); /* Silences source code analyzer warning. */
155  }
156  else /* C++ automatically performs truncation of long integer(xsInteger). */
157  return Integer::fromValue(o1.as<Numeric>()->toInteger() / o2.as<Numeric>()->toInteger());
158  }
159  case Substract:
160  return Integer::fromValue(o1.as<Numeric>()->toInteger() - o2.as<Numeric>()->toInteger());
161  case Mod:
162  {
163  const xsInteger divisor = o2.as<Numeric>()->toInteger();
164 
165  if(divisor == 0)
166  {
167  context->error(modZeroInvalid(), ReportContext::FOAR0001, this);
168  return Item(); /* Silences source code analyzer warning. */
169  }
170  else
171  return Integer::fromValue(o1.as<Numeric>()->toInteger() % divisor);
172  }
173  case Multiply:
174  return Integer::fromValue(o1.as<Numeric>()->toInteger() * o2.as<Numeric>()->toInteger());
175  case Add:
176  return Integer::fromValue(o1.as<Numeric>()->toInteger() + o2.as<Numeric>()->toInteger());
177  }
178 
179  Q_ASSERT(false);
180  return Item(); /* GCC unbarfer. */
181 }
virtual xsFloat toDecimal() const =0
qint64 xsInteger
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: