Qt 4.8
|
Provides casting functionality for classes, such as CastAs or NumberFN, which needs to perform casting. More...
#include <qcastingplatform_p.h>
Protected Functions | |
Item | cast (const Item &sourceValue, const ReportContext::Ptr &context) const |
CastingPlatform (const ReportContext::ErrorCode code=ReportContext::FORG0001) | |
void | checkTargetType (const ReportContext::Ptr &context) const |
bool | prepareCasting (const ReportContext::Ptr &context, const ItemType::Ptr &sourceType) |
Private Functions | |
Item | castWithCaster (const Item &sourceValue, const AtomicCaster::Ptr &caster, const ReportContext::Ptr &context) const |
Item | castWithCaster (const Item &sourceValue, const AtomicCaster::Ptr &caster, const DynamicContext::Ptr &context) const |
void | issueCastError (const Item &validationError, const Item &sourceValue, const ReportContext::Ptr &context) const |
ItemType::Ptr | targetType () const |
Static Private Functions | |
static AtomicCaster::Ptr | locateCaster (const ItemType::Ptr &sourceType, const ReportContext::Ptr &context, bool &castImpossible, const SourceLocationReflection *const location, const ItemType::Ptr &targetType) |
Properties | |
AtomicCaster::Ptr | m_caster |
const ReportContext::ErrorCode | m_errorCode |
Provides casting functionality for classes, such as CastAs or NumberFN, which needs to perform casting.
Classes which need to perform casting can simply from this class and gain access to casting functinality wrapped in a convenient way. At the center of this class is the cast() function, which is used at runtime to perform the actual cast.
The actual circumstances where casting is used, such as in the 'castable as' expression or the fn:number()
function, often have other things to handle as well, error handling and cardinality checks for example. This class handles only casting and leaves the other case-specific details to the sub-class such that this class only do one thing well.
This template class takes two parameters:
The class inheriting CastingPlatform must implement the following function:
that returns the type that should be cast to. The type must be an AtomicType. Typically, it is appropriate to declare this function inline
.
A sub-class calls prepareCasting() at compile time(such that CastingPlatform can attempt to lookup the proper AtomicCaster) and then it simply uses the cast() function at runtime. The function targetType() must be implemented such that CastingPlatform knows what type it shall cast to.
Definition at line 110 of file qcastingplatform_p.h.
|
inlineprotected |
Definition at line 116 of file qcastingplatform_p.h.
|
protected |
Attempts to cast sourceValue
to targetType(), and returns the created value. Remember that prepareCasting() should have been called at compile time, otherwise this function will be slow.
Error reporting is done in two ways. If a cast fails because of an error in lexical representation a ValidationError is returned. If the cause of failure is that the casting combination is invalid(such as when attempting to cast xs:date
to xs:integer
), a ValidationError is returned if false
was passed in the template instantiation, an error is issued via context
.
sourceValue | the value to cast. Must be non null . |
context | the usual ReportContext, used for error reporting. |
Definition at line 74 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform().
|
inlineprivate |
Definition at line 49 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform().
|
inlineprivate |
|
protected |
Checks that the targetType() is a valid target type for castable as
and cast as
. For example, that it is not abstract. If the type is invalid, an error is raised via the context
. Note that it is assumed the type is atomic.
Definition at line 166 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform().
|
private |
Definition at line 187 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::targetType().
|
staticprivate |
Locates the caster for casting values of type sourceType
to targetType(), if possible.
castImpossible
is not initialized. Initialize it to false
.
Definition at line 121 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform().
|
protected |
This function should be called at compiled time, it attempts to determine what AtomicCaster that should be used when casting from sourceType
to targetType(). If that is not possible, because the sourceType
is xs:anyAtomicType
for instance, the AtomicCaster lookup will done at runtime on a case-per-case basis.
true
if the requested casting combination is valid or might be valid. If it is guranteed to be invalid, false
is returned. Definition at line 101 of file qcastingplatform.cpp.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform().
|
inlineprivate |
Definition at line 183 of file qcastingplatform_p.h.
Referenced by QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform(), and QPatternist::CastingPlatform< UntypedAtomicConverter, true >::targetType().
|
private |
Definition at line 194 of file qcastingplatform_p.h.
|
private |
Definition at line 195 of file qcastingplatform_p.h.