48 template <
typename TSubClass, const
bool issueError>
57 const Item retval(caster->castFrom(sourceValue, context));
61 if(retval.template as<AtomicValue>()->hasError())
63 issueCastError(retval, sourceValue, context);
73 template <
typename TSubClass, const
bool issueError>
82 return castWithCaster(sourceValue, m_caster, context);
85 bool castImpossible =
false;
86 const AtomicCaster::Ptr caster(locateCaster(sourceValue.
type(), context, castImpossible,
static_cast<const TSubClass *
>(
this), targetType()));
88 if(!issueError && castImpossible)
93 return ValidationError::createError();
96 return castWithCaster(sourceValue, caster, context);
100 template <
typename TSubClass, const
bool issueError>
108 *sourceType == *BuiltinTypes::item ||
109 *sourceType == *CommonSequenceTypes::Empty ||
110 *sourceType == *BuiltinTypes::numeric)
114 bool castImpossible =
false;
115 m_caster = locateCaster(sourceType, context, castImpossible, static_cast<const TSubClass *>(
this), targetType());
117 return !castImpossible;
120 template <
typename TSubClass, const
bool issueError>
123 bool &castImpossible,
131 targetType.
data())->casterLocator());
136 context->error(QtXmlPatterns::tr(
"No casting is possible with %1 as the target type.")
137 .arg(
formatType(context->namePool(), targetType)),
141 castImpossible =
true;
146 const AtomicCaster::Ptr caster(static_cast<const AtomicType *>(sourceType.
data())->accept(locator, location));
151 context->error(QtXmlPatterns::tr(
"It is not possible to cast from %1 to %2.")
152 .arg(
formatType(context->namePool(), sourceType))
153 .arg(
formatType(context->namePool(), targetType)),
157 castImpossible =
true;
165 template <
typename TSubClass, const
bool issueError>
176 if(asAtomic->isAbstract())
178 context->error(QtXmlPatterns::tr(
"Casting to %1 is not possible because it " 179 "is an abstract type, and can therefore never be instantiated.")
181 ReportContext::XPST0080,
182 static_cast<const TSubClass*
>(
this));
186 template <
typename TSubClass, const
bool issueError>
188 const Item &sourceValue,
194 Q_ASSERT(validationError.template as<AtomicValue>()->hasError());
201 msg = QtXmlPatterns::tr(
"It's not possible to cast the value %1 of type %2 to %3")
209 msg = QtXmlPatterns::tr(
"Failure when casting from %1 to %2: %3")
211 .arg(
formatType(context->namePool(), targetType()))
218 context->error(msg, m_errorCode == ReportContext::FORG0001 ? err->errorCode() : m_errorCode,
219 static_cast<const TSubClass*
>(
this));
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
The QString class provides a Unicode character string.
T * data() const
Returns a pointer to the shared data object.
QString stringValue() const
Returns the string value of this Item.
QExplicitlySharedDataPointer< ItemType > type() const
Returns the ItemType this Item is of.
bool isAtomicValue() const
Determines whether this item is an atomic value, or a node.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Represents an item in the XPath 2.0 Data Model.
static QTestResult::TestLocation location
Base class for all instances that represents something at a certain location.
static QString formatData(const QXmlNodeModelIndex node)