Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Properties | List of all members
QPatternist::Decimal Class Reference

Implements the value instance of the xs:decimal type. More...

#include <qdecimal_p.h>

Inheritance diagram for QPatternist::Decimal:
QPatternist::Numeric QPatternist::AtomicValue QSharedData QPatternist::CppCastingHelper< AtomicValue >

Public Functions

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

Protected Functions

 Decimal (const xsDecimal num)
 
- Protected Functions inherited from QPatternist::AtomicValue
 AtomicValue ()
 
- Protected Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
 CppCastingHelper ()
 

Properties

const xsDecimal m_value
 

Additional Inherited Members

- Public Types inherited from QPatternist::Numeric
typedef QExplicitlySharedDataPointer< NumericPtr
 
- Public Types inherited from QPatternist::AtomicValue
typedef QList< AtomicValue::PtrList
 
typedef QExplicitlySharedDataPointer< AtomicValuePtr
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Static Protected Functions inherited from QPatternist::Numeric
static xsDouble roundFloat (const xsDouble val)
 Implements fn:round() for types implemented with floating point. More...
 

Detailed Description

Implements the value instance of the xs:decimal type.

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

Definition at line 76 of file qdecimal_p.h.

Constructors and Destructors

◆ Decimal()

Decimal::Decimal ( const xsDecimal  num)
protected

Definition at line 55 of file qdecimal.cpp.

Referenced by abs(), ceiling(), floor(), fromLexical(), fromValue(), and round().

55  : m_value(num)
56 {
57 }
const xsDecimal m_value
Definition: qdecimal_p.h:148

Functions

◆ abs()

Numeric::Ptr Decimal::abs ( ) const
virtual

Performs the algorithm specified for the function fn:abs on this Numeric, and whose result is returned.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.4.1 fn:abs

Implements QPatternist::Numeric.

Definition at line 204 of file qdecimal.cpp.

205 {
206  return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(fabs(m_value))));
207 }
const xsDecimal m_value
Definition: qdecimal_p.h:148
Decimal(const xsDecimal num)
Definition: qdecimal.cpp:55
QExplicitlySharedDataPointer< Numeric > Ptr

◆ ceiling()

Numeric::Ptr Decimal::ceiling ( ) const
virtual

Performs the algorithm specified for the function fn:ceiling on this Numeric, and whose result is returned.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.4.2 fn:ceiling

Implements QPatternist::Numeric.

Definition at line 199 of file qdecimal.cpp.

200 {
201  return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(ceil(m_value))));
202 }
#define ceil(x)
const xsDecimal m_value
Definition: qdecimal_p.h:148
Decimal(const xsDecimal num)
Definition: qdecimal.cpp:55
QExplicitlySharedDataPointer< Numeric > Ptr

◆ evaluateEBV()

bool Decimal::evaluateEBV ( const QExplicitlySharedDataPointer< DynamicContext > &  ) const
virtual

Gets the Effective Boolean Value of this number.

Returns
false if the number is 0 or NaN, otherwise true.

Reimplemented from QPatternist::AtomicValue.

Definition at line 89 of file qdecimal.cpp.

90 {
91  return !Double::isEqual(m_value, 0.0);
92 }
static bool isEqual(const xsDouble a, const xsDouble b)
const xsDecimal m_value
Definition: qdecimal_p.h:148

◆ floor()

Numeric::Ptr Decimal::floor ( ) const
virtual

Performs the algorithm specified for the function fn:floor on this Numeric, and whose result is returned.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.4.3 fn:floor

Implements QPatternist::Numeric.

Definition at line 194 of file qdecimal.cpp.

Referenced by toString().

195 {
196  return Numeric::Ptr(new Decimal(static_cast<xsDecimal>(::floor(m_value))));
197 }
virtual Numeric::Ptr floor() const
Definition: qdecimal.cpp:194
const xsDecimal m_value
Definition: qdecimal_p.h:148
Decimal(const xsDecimal num)
Definition: qdecimal.cpp:55
QExplicitlySharedDataPointer< Numeric > Ptr

◆ fromLexical()

AtomicValue::Ptr Decimal::fromLexical ( const QString strNumeric)
static

Creates a Decimal from the lexical representation of xs:decimal stored in strNumeric.

A possible optimization is to create an Integer if the string ends with ".0". But this is not conformant. For example, the user writes N.0 which according to the specification is an xs:decimal, but where the expression is, is an xs:integer is required. That would pass with such an optimization.

Definition at line 64 of file qdecimal.cpp.

Referenced by QPatternist::StringToDecimalCaster::castFrom(), QPatternist::Numeric::fromLexical(), QPatternist::XSLTTokenizer::handleXSLTVersion(), and QPatternist::yyparse().

65 {
66  /* QString::toDouble() handles the whitespace facet. */
67  const QString strNumericTrimmed(strNumeric.trimmed());
68 
69  /* Block these out, as QString::toDouble() supports them. */
70  if(strNumericTrimmed.compare(QLatin1String("-INF"), Qt::CaseInsensitive) == 0
71  || strNumericTrimmed.compare(QLatin1String("INF"), Qt::CaseInsensitive) == 0
72  || strNumericTrimmed.compare(QLatin1String("+INF"), Qt::CaseInsensitive) == 0
73  || strNumericTrimmed.compare(QLatin1String("nan"), Qt::CaseInsensitive) == 0
74  || strNumericTrimmed.contains(QLatin1Char('e'))
75  || strNumericTrimmed.contains(QLatin1Char('E')))
76  {
78  }
79 
80  bool conversionOk = false;
81  const xsDecimal num = strNumericTrimmed.toDouble(&conversionOk);
82 
83  if(conversionOk)
84  return AtomicValue::Ptr(new Decimal(num));
85  else
87 }
QExplicitlySharedDataPointer< AtomicValue > Ptr
Definition: qitem_p.h:127
static AtomicValue::Ptr createError(const QString &description=QString(), const ReportContext::ErrorCode=ReportContext::FORG0001)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
xsDouble xsDecimal
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Decimal(const xsDecimal num)
Definition: qdecimal.cpp:55
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ fromValue()

Decimal::Ptr Decimal::fromValue ( const xsDecimal  num)
static

◆ isInf()

bool Decimal::isInf ( ) const
virtual
Returns
always false, xs:decimal doesn't have infinity in its value space.

Implements QPatternist::Numeric.

Definition at line 214 of file qdecimal.cpp.

215 {
216  return false;
217 }

◆ isNaN()

bool Decimal::isNaN ( ) const
virtual
Returns
always false, xs:decimal doesn't have not-a-number in its value space.

Implements QPatternist::Numeric.

Definition at line 209 of file qdecimal.cpp.

210 {
211  return false;
212 }

◆ isSigned()

bool Decimal::isSigned ( ) const
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.

Implements QPatternist::Numeric.

Definition at line 227 of file qdecimal.cpp.

228 {
229  Q_ASSERT_X(false, Q_FUNC_INFO,
230  "It makes no sense to call this function, see Numeric::isSigned().");
231  return false;
232 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ round()

Numeric::Ptr Decimal::round ( ) const
virtual

Performs the algorithm specified for the function fn:round on this Numeric, and whose result is returned.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.4.4 fn:round

Implements QPatternist::Numeric.

Definition at line 184 of file qdecimal.cpp.

185 {
186  return Numeric::Ptr(new Decimal(roundFloat(m_value)));
187 }
const xsDecimal m_value
Definition: qdecimal_p.h:148
Decimal(const xsDecimal num)
Definition: qdecimal.cpp:55
static xsDouble roundFloat(const xsDouble val)
Implements fn:round() for types implemented with floating point.
QExplicitlySharedDataPointer< Numeric > Ptr

◆ roundHalfToEven()

Numeric::Ptr Decimal::roundHalfToEven ( const xsInteger  scale) const
virtual

Performs rounding as defined for the fn:round-half-to-even on this Numeric, and whose result is returned.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 6.4.5 fn:round-half-to-even

Implements QPatternist::Numeric.

Definition at line 189 of file qdecimal.cpp.

190 {
191  return Numeric::Ptr();
192 }
QExplicitlySharedDataPointer< Numeric > Ptr

◆ stringValue()

QString Decimal::stringValue ( ) const
virtual

Implements QPatternist::AtomicValue.

Definition at line 94 of file qdecimal.cpp.

95 {
96  return toString(m_value);
97 }
const xsDecimal m_value
Definition: qdecimal_p.h:148
static QString toString(const xsDecimal value)
Definition: qdecimal.cpp:99

◆ toDecimal()

xsDecimal Decimal::toDecimal ( ) const
virtual
Returns
the particular number's value as a native representation of the type xs:decimal. This can be considered that the value is cast to xs:decimal.

Implements QPatternist::Numeric.

Definition at line 172 of file qdecimal.cpp.

173 {
174  return m_value;
175 }
const xsDecimal m_value
Definition: qdecimal_p.h:148

◆ toDouble()

xsDouble Decimal::toDouble ( ) const
virtual
Returns
the particular number's value as a native representation of the type xs:double. This can be considered that the value is cast to xs:double.

Implements QPatternist::Numeric.

Definition at line 157 of file qdecimal.cpp.

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

158 {
159  return static_cast<xsDouble>(m_value);
160 }
const xsDecimal m_value
Definition: qdecimal_p.h:148

◆ toFloat()

xsFloat Decimal::toFloat ( ) const
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.

Implements QPatternist::Numeric.

Definition at line 167 of file qdecimal.cpp.

168 {
169  return static_cast<xsFloat>(m_value);
170 }
const xsDecimal m_value
Definition: qdecimal_p.h:148
xsDouble xsFloat

◆ toInteger()

xsInteger Decimal::toInteger ( ) const
virtual
Returns
the particular number's value as a native representation of the type xs:integer. This can be considered that the value is cast to xs:integer.

Implements QPatternist::Numeric.

Definition at line 162 of file qdecimal.cpp.

163 {
164  return static_cast<xsInteger>(m_value);
165 }
qint64 xsInteger
const xsDecimal m_value
Definition: qdecimal_p.h:148

◆ toNegated()

Item Decimal::toNegated ( ) const
virtual

Unary minus.

Implements QPatternist::Numeric.

Definition at line 219 of file qdecimal.cpp.

220 {
222  return fromValue(0).data();
223  else
224  return fromValue(-m_value).data();
225 }
Base template class for Float and Double classes.
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static Decimal::Ptr fromValue(const xsDecimal num)
Definition: qdecimal.cpp:59
const xsDecimal m_value
Definition: qdecimal_p.h:148

◆ toString()

QString Decimal::toString ( const xsDecimal  value)
static

Converts value into a canonical string representation for xs:decimal. This function is used internally by various classes. Users probably wants to call stringValue() which in turn calls this function.

Definition at line 99 of file qdecimal.cpp.

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

100 {
101  /*
102  * If SV is in the value space of xs:integer, that is, if there are no
103  * significant digits after the decimal point, then the value is converted
104  * from an xs:decimal to an xs:integer and the resulting xs:integer is
105  * converted to an xs:string using the rule above.
106  */
107  if(Double::isEqual(::floor(value), value))
108  {
109  /* The static_cast is identical to Integer::toInteger(). */
110  return QString::number(static_cast<xsInteger>(value));
111  }
112  else
113  {
114  int sign;
115  int decimalPoint;
116  char *result = 0;
117  static_cast<void>(qdtoa(value, 0, 0, &decimalPoint, &sign, 0, &result));
118  /* If the copy constructor is used instead of QString::operator=(),
119  * it doesn't compile. I have no idea why. */
120  const QString qret(QString::fromLatin1(result));
121  free(result);
122 
123  QString valueAsString;
124 
125  if(sign)
126  valueAsString += QLatin1Char('-');
127 
128  if(0 < decimalPoint)
129  {
130  valueAsString += qret.left(decimalPoint);
131  valueAsString += QLatin1Char('.');
132  if (qret.size() <= decimalPoint)
133  valueAsString += QLatin1Char('0');
134  else
135  valueAsString += qret.mid(decimalPoint);
136  }
137  else
138  {
139  valueAsString += QLatin1Char('0');
140  valueAsString += QLatin1Char('.');
141 
142  for(int d = decimalPoint; d < 0; d++)
143  valueAsString += QLatin1Char('0');
144 
145  valueAsString += qret;
146  }
147 
148  return valueAsString;
149  }
150 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double d
Definition: qnumeric_p.h:62
virtual Numeric::Ptr floor() const
Definition: qdecimal.cpp:194
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int sign(int x)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static bool isEqual(const xsDouble a, const xsDouble b)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Q_CORE_EXPORT char * qdtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **resultp)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ toUnsignedInteger()

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

Implements QPatternist::Numeric.

Definition at line 177 of file qdecimal.cpp.

178 {
179  Q_ASSERT_X(false, Q_FUNC_INFO,
180  "It makes no sense to call this function, see Numeric::toUnsignedInteger().");
181  return 0;
182 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ type()

ItemType::Ptr Decimal::type ( ) const
virtual
Returns
always BuiltinTypes::xsDecimal

Implements QPatternist::AtomicValue.

Definition at line 152 of file qdecimal.cpp.

153 {
155 }
static const AtomicType::Ptr xsDecimal

Properties

◆ m_value

const xsDecimal QPatternist::Decimal::m_value
private

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