Qt 4.8
Public Types | Public Functions | List of all members
QPatternist::ExternalVariableLoader Class Reference

Responsible for loading and declaring available external variables. More...

#include <qexternalvariableloader_p.h>

Inheritance diagram for QPatternist::ExternalVariableLoader:
QSharedData QPatternist::VariableLoader

Public Types

typedef QExplicitlySharedDataPointer< ExternalVariableLoaderPtr
 

Public Functions

virtual SequenceType::Ptr announceExternalVariable (const QXmlName name, const SequenceType::Ptr &declaredType)
 
virtual bool evaluateEBV (const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
 
virtual Item::Iterator::Ptr evaluateSequence (const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
 
virtual Item evaluateSingleton (const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
 
 ExternalVariableLoader ()
 
virtual ~ExternalVariableLoader ()
 
- 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...
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Responsible for loading and declaring available external variables.

An external variable in XQuery is a global variable that has been declared to receive its value from the XQuery implementation, as opposed to an initializing expression. Here is an example of a query with an external variable declaration, followed by a ordinary global variable:

declare variable $theName external; declare variable $theName := "the value"; "And here's the query body(a string literal)"

An external variable declaration can also specify a sequence type:

declare variable $theName as xs:integer external;

This class allows the user to supply the values to external variables. When an external variable declaration occur in the query, announceExternalVariable() is called.

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

Definition at line 90 of file qexternalvariableloader_p.h.

Typedefs

◆ Ptr

Definition at line 93 of file qexternalvariableloader_p.h.

Constructors and Destructors

◆ ExternalVariableLoader()

QPatternist::ExternalVariableLoader::ExternalVariableLoader ( )
inline

Definition at line 94 of file qexternalvariableloader_p.h.

94 {}

◆ ~ExternalVariableLoader()

ExternalVariableLoader::~ExternalVariableLoader ( )
virtual

Definition at line 52 of file qexternalvariableloader.cpp.

53 {
54 }

Functions

◆ announceExternalVariable()

SequenceType::Ptr ExternalVariableLoader::announceExternalVariable ( const QXmlName  name,
const SequenceType::Ptr declaredType 
)
virtual

Called when Patternist encounters an external variable in the query. It is guaranteed to be called once for each external variable appearing in a query module.

Parameters
namethe name of the variable. Quaranteed to never be null.
declaredTypethe type that the user declared the variable to be of. Whether this type matches the actual value of the variable or not is irrelevant. Patternist will do the necessary error handling based on the sequence type that is returned from this function. If the user didn't declare a type, the type is item()*(zero or more items). Quaranteed to never be null.
Returns
the sequence type of the value this ExternalVariableLoader actually supplies. However, if the ExternalVariableLoader knows it cannot supply a variable by this name, null should be returned.

Reimplemented in QPatternist::VariableLoader.

Definition at line 57 of file qexternalvariableloader.cpp.

59 {
60  Q_ASSERT(!name.isNull());
61  Q_ASSERT(declaredType);
62  Q_UNUSED(name); /* Needed when compiling in release mode. */
63  Q_UNUSED(declaredType); /* Needed when compiling in release mode. */
64 
65  return SequenceType::Ptr();
66 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QExplicitlySharedDataPointer< const SequenceType > Ptr
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ evaluateEBV()

bool ExternalVariableLoader::evaluateEBV ( const QXmlName  name,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
)
virtual

Definition at line 87 of file qexternalvariableloader.cpp.

Referenced by QPatternist::ExternalVariableReference::evaluateEBV(), and evaluateSingleton().

89 {
90  Q_ASSERT(!name.isNull());
91  return Boolean::evaluateEBV(evaluateSequence(name, context), context);
92 }
static bool evaluateEBV(const Item::Iterator::Ptr &e, const QExplicitlySharedDataPointer< DynamicContext > &)
Definition: qboolean.cpp:55
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Item::Iterator::Ptr evaluateSequence(const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ evaluateSequence()

Item::Iterator::Ptr ExternalVariableLoader::evaluateSequence ( const QXmlName  name,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
)
virtual

This function is called at runtime when the external variable by name name needs to be evaluated. It is not defined how many times this function will be called. It depends on aspects such as how the query was optimized.

Parameters
namethe name of the variable. Quaranteed to never be null.
contextthe DynamicContext.
Returns
the value of the variable. Remember that this value must match the sequence type returned from announceExternalVariable() for the same name.

Definition at line 68 of file qexternalvariableloader.cpp.

Referenced by evaluateEBV(), and QPatternist::ExternalVariableReference::evaluateSequence().

70 {
71  Q_ASSERT(!name.isNull());
72  const Item item(evaluateSingleton(name, context));
73 
74  if(item)
75  return makeSingletonIterator(item);
76  else
78 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const EmptyIterator< Item >::Ptr emptyIterator
virtual Item evaluateSingleton(const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ evaluateSingleton()

Item ExternalVariableLoader::evaluateSingleton ( const QXmlName  name,
const QExplicitlySharedDataPointer< DynamicContext > &  context 
)
virtual

Definition at line 80 of file qexternalvariableloader.cpp.

Referenced by evaluateSequence(), and QPatternist::ExternalVariableReference::evaluateSingleton().

82 {
83  Q_ASSERT(!name.isNull());
84  return Boolean::fromValue(evaluateEBV(name, context));
85 }
virtual bool evaluateEBV(const QXmlName name, const QExplicitlySharedDataPointer< DynamicContext > &context)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static Boolean::Ptr fromValue(const bool value)
Definition: qboolean.cpp:115
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

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