Qt 4.8
Public Types | Public Functions | Static Public Functions | Static Protected Functions | List of all members
QPatternist::Numeric Class Referenceabstract

Base class for all numeric values. More...

#include <qschemanumeric_p.h>

Inheritance diagram for QPatternist::Numeric:
QPatternist::AtomicValue QSharedData QPatternist::CppCastingHelper< AtomicValue > QPatternist::AbstractFloat< isDouble > QPatternist::Decimal QPatternist::DerivedInteger< DerivedType > QPatternist::Integer

Public Types

typedef QExplicitlySharedDataPointer< NumericPtr
 
- Public Types inherited from QPatternist::AtomicValue
typedef QList< AtomicValue::PtrList
 
typedef QExplicitlySharedDataPointer< AtomicValuePtr
 

Public Functions

virtual Numeric::Ptr abs () const =0
 
virtual Numeric::Ptr ceiling () const =0
 
virtual Numeric::Ptr floor () const =0
 
virtual bool isInf () const =0
 
virtual bool isNaN () const =0
 
virtual bool isSigned () const =0
 Returns true if this value is signed. If false is returned, the value is unsigned. More...
 
virtual Numeric::Ptr round () const =0
 
virtual Numeric::Ptr roundHalfToEven (const xsInteger scale) const =0
 
virtual xsFloat toDecimal () const =0
 
virtual xsDouble toDouble () const =0
 
virtual xsFloat toFloat () const =0
 
virtual xsInteger toInteger () const =0
 
virtual Item toNegated () const =0
 
virtual qulonglong toUnsignedInteger () const =0
 
- Public Functions inherited from QPatternist::AtomicValue
virtual bool evaluateEBV (const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
virtual bool hasError () const
 
virtual QString stringValue () const =0
 
virtual ItemType::Ptr type () const =0
 
virtual ~AtomicValue ()
 
- 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::CppCastingHelper< AtomicValue >
const TCastTarget * as () const
 
TCastTarget * as ()
 

Static Public Functions

static AtomicValue::Ptr fromLexical (const QString &number)
 
- Static Public Functions inherited from QPatternist::AtomicValue
static ItemType::Ptr qtToXDMType (const QXmlItem &item)
 
static QVariant toQt (const AtomicValue *const value)
 
static QVariant toQt (const AtomicValue::Ptr &value)
 
static Item toXDM (const QVariant &value)
 

Static Protected Functions

static xsDouble roundFloat (const xsDouble val)
 Implements fn:round() for types implemented with floating point. More...
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::AtomicValue
 AtomicValue ()
 
- Protected Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
 CppCastingHelper ()
 

Detailed Description

Base class for all numeric values.

Creating Instances

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6 Functions and Operators on Numerics
XQuery 1.0 and XPath 2.0 Functions and Operators, 1.2 Function Overloading
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 90 of file qschemanumeric_p.h.

Typedefs

◆ Ptr

Definition at line 94 of file qschemanumeric_p.h.

Functions

◆ abs()

virtual Numeric::Ptr QPatternist::Numeric::abs ( ) const
pure virtual

◆ ceiling()

virtual Numeric::Ptr QPatternist::Numeric::ceiling ( ) const
pure virtual

◆ floor()

virtual Numeric::Ptr QPatternist::Numeric::floor ( ) const
pure virtual

◆ fromLexical()

AtomicValue::Ptr Numeric::fromLexical ( const QString number)
static

Creates a Numeric sub-class that is appropriate for number.

Note
usages of e/E is not handled; Double::fromLexical should be used in that case. There is no function similar to fromLexical that also takes double values into account(because that distinction is done in the scanner).

Currently used in the parser to create appropriate expressions.

Definition at line 62 of file qschemanumeric.cpp.

63 {
64  Q_ASSERT(!number.isEmpty());
65  Q_ASSERT_X(!number.contains(QLatin1Char('e')) &&
66  !number.contains(QLatin1Char('E')),
67  Q_FUNC_INFO, "Should not contain any e/E");
68 
69  if(number.contains(QLatin1Char('.'))) /* an xs:decimal. */
70  return Decimal::fromLexical(number);
71  else /* It's an integer, of some sort. E.g, -3, -2, -1, 0, 1, 2, 3 */
72  return Integer::fromLexical(number);
73 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
static AtomicValue::Ptr fromLexical(const QString &strNumeric)
Definition: qdecimal.cpp:64
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static AtomicValue::Ptr fromLexical(const QString &strNumeric)
Definition: qinteger.cpp:57
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ isInf()

virtual bool QPatternist::Numeric::isInf ( ) const
pure virtual

Determines whether this Numeric is an infinite number. Signedness is irrelevant, -INF as well as INF is considered infinity.

For numeric types that cannot represent infinity, such as xs:integer , this function should return false.

Returns
true if this Numeric is an infinite number

Implemented in QPatternist::DerivedInteger< DerivedType >, QPatternist::Decimal, QPatternist::AbstractFloat< isDouble >, and QPatternist::Integer.

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

◆ isNaN()

virtual bool QPatternist::Numeric::isNaN ( ) const
pure virtual

Determines whether this Numeric is not-a-number, NaN. For numeric types that cannot represent NaN, this function should return false.

Returns
true if this Numeric is NaN

Implemented in QPatternist::DerivedInteger< DerivedType >, QPatternist::AbstractFloat< isDouble >, QPatternist::Decimal, and QPatternist::Integer.

Referenced by QPatternist::AbstractFloatMathematician< isDouble >::calculate(), and qLess< Item::List >::isNaN().

◆ isSigned()

virtual bool QPatternist::Numeric::isSigned ( ) const
pure virtual

Returns true if this value is signed. If false is returned, the value is unsigned.

For float and decimal values, xs:double, xs:float and xs:decimal, the code asserts and behavior is undefined.

Implemented in QPatternist::DerivedInteger< DerivedType >, QPatternist::Decimal, QPatternist::AbstractFloat< isDouble >, and QPatternist::Integer.

Referenced by QPatternist::IntegerComparator::compare().

◆ round()

virtual Numeric::Ptr QPatternist::Numeric::round ( ) const
pure virtual

◆ roundFloat()

xsDouble Numeric::roundFloat ( const xsDouble  val)
staticprotected

Implements fn:round() for types implemented with floating point.

MS Windows and at least IRIX does not have C99's nearbyint() function(see the man page), so we reinvent it.

Definition at line 75 of file qschemanumeric.cpp.

Referenced by QPatternist::Decimal::round(), and QPatternist::AbstractFloat< isDouble >::round().

76 {
77  if(qIsInf(val) || AbstractFloat<true>::isEqual(val, 0.0))
78  return val;
79  else if(qIsNaN(val))
80  return val;
81  else
82  {
83  if(val >= -0.5 && val < 0)
84  return -0.0;
85  else
86  return ::floor(val + 0.5);
87 
88  }
89 }
Base template class for Float and Double classes.
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
Q_CORE_EXPORT bool qIsInf(double d)
Returns true if the double {d} is equivalent to infinity.
Definition: qnumeric.cpp:50

◆ roundHalfToEven()

virtual Numeric::Ptr QPatternist::Numeric::roundHalfToEven ( const xsInteger  scale) const
pure virtual

◆ toDecimal()

virtual xsFloat QPatternist::Numeric::toDecimal ( ) const
pure virtual

◆ toDouble()

virtual xsDouble QPatternist::Numeric::toDouble ( ) const
pure virtual

◆ toFloat()

virtual xsFloat QPatternist::Numeric::toFloat ( ) const
pure virtual
Returns
the particular number's value as a native representation of the type xs:float. This can be considered that the value is cast to xs:float.

Implemented in QPatternist::DerivedInteger< DerivedType >, QPatternist::AbstractFloat< isDouble >, QPatternist::Decimal, and QPatternist::Integer.

◆ toInteger()

virtual xsInteger QPatternist::Numeric::toInteger ( ) const
pure virtual

◆ toNegated()

virtual Item QPatternist::Numeric::toNegated ( ) const
pure virtual

◆ toUnsignedInteger()

virtual qulonglong QPatternist::Numeric::toUnsignedInteger ( ) const
pure virtual
Returns
the number as an unsigned integer. If the value is not unsigned, the code asserts and behavior is undefined.

Implemented in QPatternist::DerivedInteger< DerivedType >, QPatternist::AbstractFloat< isDouble >, QPatternist::Decimal, and QPatternist::Integer.

Referenced by QPatternist::XsdTypeChecker::checkConstrainingFacets().


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