Qt 4.8
qatomiccasters_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_AtomicCasters_H
53 #define Patternist_AtomicCasters_H
54 
55 #include "qatomiccaster_p.h"
56 #include "qdecimal_p.h"
57 #include "qderivedinteger_p.h"
58 #include "qderivedstring_p.h"
59 #include "qinteger_p.h"
60 #include "qvalidationerror_p.h"
61 
69 
71 
72 namespace QPatternist
73 {
74 
85  template<TypeOfDerivedString DerivedType>
87  {
88  public:
89  virtual Item castFrom(const Item &from,
91  {
92  Q_ASSERT(from);
93  return DerivedString<DerivedType>::fromLexical(context->namePool(), from.stringValue());
94  }
95  };
96 
108  {
109  public:
110  virtual Item castFrom(const Item &from,
111  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
112  };
113 
121  {
122  public:
123  virtual Item castFrom(const Item &from,
124  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
125  };
126 
134  {
135  public:
136  virtual Item castFrom(const Item &from,
137  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
138  };
139 
147  {
148  public:
149  virtual Item castFrom(const Item &from,
150  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
151  };
152 
160  {
161  public:
162  virtual Item castFrom(const Item &from,
163  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
164  };
165 
173  {
174  public:
175  virtual Item castFrom(const Item &from,
176  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
177  };
178 
186  {
187  public:
188  virtual Item castFrom(const Item &from,
189  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
190  };
191 
199  {
200  public:
201  virtual Item castFrom(const Item &from,
202  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
203  };
204 
214  template <const bool IsInteger>
216  {
217  public:
221  static inline QString errorMessage()
222  {
223  return QtXmlPatterns::tr("When casting to %1 from %2, the source value cannot be %3.");
224  }
225 
226  virtual Item castFrom(const Item &from,
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  {
236  return ValidationError::createError(errorMessage()
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  }
249  };
250 
258  {
259  public:
260  virtual Item castFrom(const Item &from,
261  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
262  };
263 
271  {
272  public:
273  virtual Item castFrom(const Item &from,
274  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
275  };
276 
284  {
285  public:
286  virtual Item castFrom(const Item &from,
287  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
288  };
289 
297  {
298  public:
299  virtual Item castFrom(const Item &from,
300  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
301  };
302 
316  {
317  public:
318 
322  virtual Item castFrom(const Item &from,
323  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
324  };
325 
333  {
334  public:
335  virtual Item castFrom(const Item &from,
336  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
337  };
338 
346  {
347  public:
348  virtual Item castFrom(const Item &from,
349  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
350  };
351 
359  {
360  public:
361  virtual Item castFrom(const Item &from,
362  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
363  };
364 
372  {
373  public:
374  virtual Item castFrom(const Item &from,
375  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
376  };
377 
385  {
386  public:
387  virtual Item castFrom(const Item &from,
388  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
389  };
390 
398  {
399  public:
400  virtual Item castFrom(const Item &from,
401  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
402  };
403 
411  {
412  public:
413  virtual Item castFrom(const Item &from,
414  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
415  };
416 
424  {
425  public:
426  virtual Item castFrom(const Item &from,
427  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
428  };
429 
437  {
438  public:
439  virtual Item castFrom(const Item &from,
440  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
441  };
442 
450  {
451  public:
452  virtual Item castFrom(const Item &from,
453  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
454  };
455 
463  {
464  public:
465  virtual Item castFrom(const Item &from,
466  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
467  };
468 
469 
477  {
478  public:
479  virtual Item castFrom(const Item &from,
480  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
481  };
482 
490  {
491  public:
492  virtual Item castFrom(const Item &from,
493  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
494  };
495 
503  {
504  public:
505  virtual Item castFrom(const Item &from,
506  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
507  };
508 
516  {
517  public:
518  virtual Item castFrom(const Item &from,
519  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
520  };
521 
529  {
530  public:
531  virtual Item castFrom(const Item &from,
532  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
533  };
534 
542  {
543  public:
544  virtual Item castFrom(const Item &from,
545  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
546  };
547 
555  {
556  public:
557  virtual Item castFrom(const Item &from,
558  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
559  };
560 
568  {
569  public:
570  virtual Item castFrom(const Item &from,
571  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
572  };
573 
581  {
582  public:
583  virtual Item castFrom(const Item &from,
584  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
585  };
586 
594  {
595  public:
596  virtual Item castFrom(const Item &from,
597  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
598  };
599 
607  {
608  public:
609  virtual Item castFrom(const Item &from,
610  const QExplicitlySharedDataPointer<DynamicContext> &context) const;
611  };
612 
619  template<TypeOfDerivedInteger type>
621  {
622  public:
623  virtual Item
624  castFrom(const Item &from,
626  {
627  return DerivedInteger<type>::fromLexical(context->namePool(), from.stringValue());
628  }
629  };
630 
637  template<TypeOfDerivedInteger type>
639  {
640  public:
641  virtual Item
642  castFrom(const Item &from,
644  {
645  return DerivedInteger<type>::fromValue(context->namePool(), from.template as<AtomicValue>()->evaluateEBV(context) ? 1 : 0);
646  }
647  };
648 
655  template<TypeOfDerivedString type>
657  {
658  public:
659  virtual Item
660  castFrom(const Item &from,
662  {
663  return DerivedString<type>::fromLexical(context->namePool(), from.stringValue());
664  }
665  };
666 
673  template<TypeOfDerivedInteger type>
675  {
676  public:
677  virtual Item
678  castFrom(const Item &from,
680  {
681  const ItemType::Ptr t(from.type());
682  const Numeric *const num = from.template as<Numeric>();
683 
684  if(BuiltinTypes::xsDouble->xdtTypeMatches(t) || BuiltinTypes::xsFloat->xdtTypeMatches(t))
685  {
686  if(num->isInf() || num->isNaN())
687  {
689  .arg(formatType(context->namePool(), DerivedInteger<type>::itemType()))
690  .arg(formatType(context->namePool(), t))
691  .arg(formatData(num->stringValue())),
693  }
694  }
695 
696  return toItem(DerivedInteger<type>::fromValue(context->namePool(), from.template as<Numeric>()->toInteger()));
697  }
698  };
699 }
700 
702 
704 
705 #endif
Casts an xs:string instance to a derived type of xs:integer.
Casts an AbstractDuration instance to Duration.
Casts a value of type xs:boolean to xs:decimal.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Casts a numeric value, such as xs:double or xs:decimal, to xs:integer or xs:decimal, depending on IsInteger.
static AtomicValue::Ptr fromValue(const NamePool::Ptr &np, const TemporaryStorageType num)
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Casts any numeric instance to a derived type of xs:integer.
Casts a xs:date or xs:dateTime atomic value to xs:gDay.
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &strNumeric)
static AtomicValue::Ptr createError(const QString &description=QString(), const ReportContext::ErrorCode=ReportContext::FORG0001)
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
Casts an AbstractDateTime instance to SchemaTime.
Casts a xs:string or xs:untypedAtomic atomic value to xs:base64Binary.
Casts an xs:boolean instance to a derived type of xs:integer.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Casts an AbstractDateTime instance to DateTime.
Casts a xs:date or xs:dateTime atomic value to xs:gMonth.
static Item fromValue(const xsInteger num)
Definition: qinteger.cpp:52
Casts a xs:date or xs:dateTime atomic value to xs:gYear.
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Casts any atomic value to xs:untypedAtomic.
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Casts an AbstractDateTime instance to SchemaTime.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Casts an xs:boolean instance to a derived type of xs:integer.
Casts a value of type xs:boolean to xs:integer.
The namespace for the internal API of QtXmlPatterns.
static const AtomicType::Ptr xsDouble
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
Casts any atomic value to xs:string.
Casts a xs:string or xs:untypedAtomic atomic value to xs:dateTime.
QExplicitlySharedDataPointer< ItemType > type() const
Returns the ItemType this Item is of.
Definition: qitem_p.h:365
static Decimal::Ptr fromValue(const xsDecimal num)
Definition: qdecimal.cpp:59
static QString formatData(const QString &data)
Casts a xs:string or xs:untypedAtomic atomic value to xs:hexBinary.
Casts a value to itself. Essentially, this AtomicCaster does nothing.
AtomicCaster is an abstract base class for classes that performs casting between two atomic values of...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Casts a xs:date or xs:dateTime atomic value to xs:gYearMonth.
Casts a xs:string or xs:untypedAtomic atomic value to xs:gYear.
Base class for all numeric values.
Casts a xs:string or xs:untypedAtomic atomic value to xs:dayTimeDuration.
Casts a xs:string or xs:untypedAtomic atomic value to xs:duration.
Casts any numeric value to xs:boolean.
Casts a xs:string or xs:untypedAtomic atomic value to xs:gYearMonth.
Casts any string value, xs:string or xs:untypedAtomic, to xs:boolean.
Casts a xs:string or xs:untypedAtomic atomic value to xs:gDay.
Casts an AbstractDuration instance to DayTimeDuration.
static const AtomicType::Ptr xsFloat
Casts an AbstractDuration instance to YearMonthDuration.
Casts a xs:string or xs:untypedAtomic atomic value to xs:date.
Casts a xs:date or xs:dateTime atomic value to xs:gMonthDay.
Casts a string value, xs:string or xs:untypedAtomic, to xs:integer.
Casts a xs:string or xs:untypedAtomic atomic value to xs:gYearMonth.
Casts a xs:string or xs:untypedAtomic atomic value to xs:gMonth.
static const AtomicType::Ptr xsInteger
virtual Item castFrom(const Item &from, const QExplicitlySharedDataPointer< DynamicContext > &context) const
Casts a xs:string or xs:untypedAtomic atomic value to xs:time.
Casts a xs:string or xs:untypedAtomic atomic value to xs:yearMonthDuration.
static const AtomicType::Ptr xsDecimal
Casts a xs:hexBinary atomic value to xs:base64Binary.
Casts a xs:base64Binary atomic value to xs:hexBinary.
Represents instances of derived xs:integer types, such as xs:byte.
Casts a string value, xs:string or xs:untypedAtomic, to xs:decimal.
#define QT_END_HEADER
Definition: qglobal.h:137
Casts a string value to xs:anyURI.
static ItemType::Ptr itemType()
static AtomicValue::Ptr fromLexical(const NamePool::Ptr &np, const QString &lexical)