Qt 4.8
Public Functions | Static Public Functions | List of all members
QPatternist::NumericToDecimalCaster< IsInteger > Class Template Reference

Casts a numeric value, such as xs:double or xs:decimal, to xs:integer or xs:decimal, depending on IsInteger. More...

#include <qatomiccasters_p.h>

Inheritance diagram for QPatternist::NumericToDecimalCaster< IsInteger >:
QPatternist::AtomicCaster QPatternist::AtomicTypeVisitorResult QSharedData

Public Functions

virtual Item castFrom (const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
- Public Functions inherited from QPatternist::AtomicCaster
 AtomicCaster ()
 
virtual ~AtomicCaster ()
 
- 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 Public Functions

static QString errorMessage ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::AtomicCaster
typedef QExplicitlySharedDataPointer< AtomicCasterPtr
 
- Public Types inherited from QPatternist::AtomicTypeVisitorResult
typedef QExplicitlySharedDataPointer< AtomicTypeVisitorResultPtr
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

template<const bool IsInteger>
class QPatternist::NumericToDecimalCaster< IsInteger >

Casts a numeric value, such as xs:double or xs:decimal, to xs:integer or xs:decimal, depending on IsInteger.

castFrom() uses Numeric::toInteger() for doing the actual casting.

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

Definition at line 215 of file qatomiccasters_p.h.

Functions

◆ castFrom()

template<const bool IsInteger>
virtual Item QPatternist::NumericToDecimalCaster< IsInteger >::castFrom ( const Item from,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
) const
inlinevirtual

Casts from to an atomic value of the type this class casts to, and returns that value. The context is used for reporting errors in case the casting fails, and to in general access information from the dynamic context.

Implements QPatternist::AtomicCaster.

Definition at line 226 of file qatomiccasters_p.h.

228  {
229  const ItemType::Ptr t(from.type());
230  const Numeric *const num = from.template as<Numeric>();
231 
232  if(BuiltinTypes::xsDouble->xdtTypeMatches(t) || BuiltinTypes::xsFloat->xdtTypeMatches(t))
233  {
234  if(num->isInf() || num->isNaN())
235  {
237  .arg(formatType(context->namePool(), IsInteger ? BuiltinTypes::xsInteger : BuiltinTypes::xsDecimal))
238  .arg(formatType(context->namePool(), t))
239  .arg(formatData(num->stringValue())),
241  }
242  }
243 
244  if(IsInteger)
245  return Integer::fromValue(num->toInteger());
246  else
247  return toItem(Decimal::fromValue(num->toDecimal()));
248  }
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
static AtomicValue::Ptr createError(const QString &description=QString(), const ReportContext::ErrorCode=ReportContext::FORG0001)
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
static Item fromValue(const xsInteger num)
Definition: qinteger.cpp:52
static const AtomicType::Ptr xsDouble
static Decimal::Ptr fromValue(const xsDecimal num)
Definition: qdecimal.cpp:59
static QString formatData(const QString &data)
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static const AtomicType::Ptr xsFloat
static const AtomicType::Ptr xsInteger
static const AtomicType::Ptr xsDecimal

◆ errorMessage()

template<const bool IsInteger>
static QString QPatternist::NumericToDecimalCaster< IsInteger >::errorMessage ( )
inlinestatic

Used by NumericToDerivedIntegerCaster in addition to this class.

Definition at line 221 of file qatomiccasters_p.h.

222  {
223  return QtXmlPatterns::tr("When casting to %1 from %2, the source value cannot be %3.");
224  }

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