Qt 4.8
Public Types | Public Functions | Related Functions | List of all members
QPatternist::ItemType Class Referenceabstract

Base class for the XPath Data Model's type hierarchy. More...

#include <qitemtype_p.h>

Inheritance diagram for QPatternist::ItemType:
QSharedData QPatternist::AnyItemType QPatternist::AnyNodeType QPatternist::AtomicType QPatternist::EBVType QPatternist::EmptySequenceType QPatternist::MultiItemType QPatternist::NoneType QPatternist::AbstractNodeTest QPatternist::BuiltinNodeType< kind > QPatternist::XSLTNodeTest QPatternist::BuiltinAtomicType QPatternist::NumericType QPatternist::LocalNameTest QPatternist::NamespaceNameTest QPatternist::QNameTest QPatternist::AnyAtomicType QPatternist::AnyURIType QPatternist::Base64BinaryType QPatternist::BooleanType QPatternist::DateTimeType QPatternist::DateType QPatternist::DayTimeDurationType QPatternist::DecimalType QPatternist::DoubleType QPatternist::DurationType QPatternist::FloatType QPatternist::GDayType QPatternist::GMonthDayType QPatternist::GMonthType QPatternist::GYearMonthType QPatternist::GYearType QPatternist::HexBinaryType QPatternist::IntegerType QPatternist::NOTATIONType QPatternist::QNameType QPatternist::SchemaTimeType QPatternist::StringType QPatternist::UntypedAtomicType QPatternist::YearMonthDurationType

Public Types

enum  Category { NodeNameTest = 1, Other = 2 }
 
enum  InstanceOf { ClassLocalNameTest, ClassNamespaceNameTest, ClassQNameTest, ClassOther }
 
typedef QList< ItemType::PtrList
 
typedef QExplicitlySharedDataPointer< ItemTypePtr
 

Public Functions

virtual ItemType::Ptr atomizedType () const =0
 
virtual QString displayName (const NamePool::Ptr &np) const =0
 
virtual InstanceOf instanceOf () const
 
virtual bool isAtomicType () const =0
 
virtual bool isNodeType () const =0
 
virtual bool itemMatches (const Item &item) const =0
 
 ItemType ()
 
virtual Category itemTypeCategory () const
 
bool operator!= (const ItemType &other) const
 
virtual bool operator== (const ItemType &other) const
 
virtual const ItemTypeoperator| (const ItemType &other) const
 
virtual ItemType::Ptr xdtSuperType () const =0
 
virtual bool xdtTypeMatches (const ItemType::Ptr &other) const =0
 Returns true if other matches this type. That is, if other is equal to this type or a subtype of this type. More...
 
virtual ~ItemType ()
 
- 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...
 

Related Functions

(Note that these are not member functions.)

ItemType::Ptr operator| (const ItemType::Ptr &op1, const ItemType::Ptr &op2)
 
void operator|= (ItemType::Ptr &op1, const ItemType::Ptr &op2)
 Computes the union type of op1 and op2, and assigns it to op1. More...
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Base class for the XPath Data Model's type hierarchy.

It can not be instantiated, but it's possible via ItemType's two subtypes: Nodes, represented by QXmlNodeModelIndex, and atom types, represented by AtomicType.

ItemType tries to by its design stay close to the notation used in Formal Semantics. The operator|() is a good example, it allow typing code to be written similar to how inference rules in the specification are written.

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

Definition at line 82 of file qitemtype_p.h.

Typedefs

◆ List

A list of ItemType instances, each wrapped in a smart pointer.

Definition at line 92 of file qitemtype_p.h.

◆ Ptr

A smart pointer wrapping ItemType instances.

Definition at line 88 of file qitemtype_p.h.

Enumerations

◆ Category

Enumerator
NodeNameTest 
Other 

Definition at line 96 of file qitemtype_p.h.

◆ InstanceOf

Enumerator
ClassLocalNameTest 
ClassNamespaceNameTest 
ClassQNameTest 
ClassOther 

Definition at line 217 of file qitemtype_p.h.

Constructors and Destructors

◆ ~ItemType()

ItemType::~ItemType ( )
virtual

Definition at line 52 of file qitemtype.cpp.

53 {
54 }

◆ ItemType()

QPatternist::ItemType::ItemType ( )
inline

Definition at line 232 of file qitemtype_p.h.

233  {
234  }

Functions

◆ atomizedType()

virtual ItemType::Ptr QPatternist::ItemType::atomizedType ( ) const
pure virtual

Determines the atomic type that the resulting sequence after atomization of this node would be an instance of. For example, for document node, xs:untypedAtomic is returned. Phrased differently, the returned type is the type of the result of the typed-value accessor.

If the type cannot be atomized, it returns null.

This function is also defined on SchemaType, because some schema types can also be atomized.

See also
SchemaType::atomizedType()
XQuery 1.0 and XPath 2.0 Data Model, 5.15 typed-value Accessor
XQuery 1.0 and XPath 2.0 Formal Semantics, data on auxiliary judgment
Returns
the atomic type that the resulting sequence when performing atomization is an instance of.

Implemented in QPatternist::MultiItemType, QPatternist::AtomicType, QPatternist::NoneType, QPatternist::EBVType, QPatternist::EmptySequenceType, QPatternist::NumericType, QPatternist::AnyItemType, QPatternist::AnyNodeType, QPatternist::BuiltinNodeType< kind >, and QPatternist::AbstractNodeTest.

Referenced by QPatternist::AbstractNodeTest::atomizedType().

◆ displayName()

virtual QString QPatternist::ItemType::displayName ( const NamePool::Ptr np) const
pure virtual
Returns
a string representing the type. Used for diagnostic purposes. For a type whose name is a QName, a lexical representation should be returned with the prefix being a conventional one. Examples of a display names are "item()" and "xs:nonPositiveInteger".

Implemented in QPatternist::NOTATIONType, QPatternist::DerivedStringType< derivedType >, QPatternist::StringType, QPatternist::QNameType, QPatternist::AnyURIType, QPatternist::HexBinaryType, QPatternist::Base64BinaryType, QPatternist::BooleanType, QPatternist::GMonthType, QPatternist::GDayType, QPatternist::GMonthDayType, QPatternist::GYearType, QPatternist::GYearMonthType, QPatternist::DerivedIntegerType< derivedType >, QPatternist::IntegerType, QPatternist::DecimalType, QPatternist::FloatType, QPatternist::DoubleType, QPatternist::DayTimeDurationType, QPatternist::YearMonthDurationType, QPatternist::DurationType, QPatternist::SchemaTimeType, QPatternist::DateType, QPatternist::DateTimeType, QPatternist::UntypedAtomicType, QPatternist::AtomicType, QPatternist::MultiItemType, QPatternist::EmptySequenceType, QPatternist::EBVType, QPatternist::NoneType, QPatternist::AnyAtomicType, QPatternist::BuiltinNodeType< kind >, QPatternist::LocalNameTest, QPatternist::NamespaceNameTest, QPatternist::QNameTest, QPatternist::NumericType, QPatternist::AnyNodeType, and QPatternist::AnyItemType.

Referenced by QPatternist::GenericSequenceType::displayName(), QPatternist::QNameTest::displayName(), and QPatternist::LocalNameTest::displayName().

◆ instanceOf()

ItemType::InstanceOf ItemType::instanceOf ( ) const
virtual

Determines what class this ItemType is an instance of. This is in needed in some implementations of operator operator==(). By default, Other is returned.

Reimplemented in QPatternist::QNameTest, QPatternist::LocalNameTest, and QPatternist::NamespaceNameTest.

Definition at line 98 of file qitemtype.cpp.

Referenced by QPatternist::LocalNameTest::operator==(), QPatternist::QNameTest::operator==(), and QPatternist::NamespaceNameTest::operator==().

99 {
100  return ClassOther;
101 }

◆ isAtomicType()

virtual bool QPatternist::ItemType::isAtomicType ( ) const
pure virtual

◆ isNodeType()

virtual bool QPatternist::ItemType::isNodeType ( ) const
pure virtual

◆ itemMatches()

virtual bool QPatternist::ItemType::itemMatches ( const Item item) const
pure virtual

◆ itemTypeCategory()

ItemType::Category ItemType::itemTypeCategory ( ) const
virtual
Returns
always Other

Definition at line 88 of file qitemtype.cpp.

89 {
90  return Other;
91 }

◆ operator!=()

bool QPatternist::ItemType::operator!= ( const ItemType other) const
inline
Returns
the result of operator==() negated.

Definition at line 256 of file qitemtype_p.h.

257  {
258  return this != &other;
259  }

◆ operator==()

bool ItemType::operator== ( const ItemType other) const
virtual

Determines whether this ItemType is equal to other.

Many types are represented by singleton instances. For example, there exists only one instance of IntegerType. This operator==() takes advantage of that and uses equalness of object addresses for determining semantic equalness. This function is as a result fast.

However, it's overridden in some cases, such as for name tests, where it's not guaranteed that there exists two types.

Returns
true if this ItemType is equal to other, otherwise false.

Reimplemented in QPatternist::LocalNameTest, QPatternist::NamespaceNameTest, and QPatternist::QNameTest.

Definition at line 93 of file qitemtype.cpp.

94 {
95  return this == &other;
96 }

◆ operator|()

const ItemType & ItemType::operator| ( const ItemType other) const
virtual

Determines the super type that is closest to this ItemType and other. That is, the parent type of them both. For example, for the type xs:integer and xs:string the parent type is xs:anyAtomicType. For xs:NOTATION and processing-instruction(), it is item(), to name another example.

This function can be seen as the type function prime(Type), defined in Formal Semantics.

This walks the XPath Data Model type hierarchy, not the W3C XML Schema hierarchy.

Parameters
otherthe item type 'this' object, should be compared with. Invoking xdtSuperType on 'this' object with other as argument yields the same result as invoking the function on other with 'this' as argument.
Returns
the parent type of 'this' and other
See also
XQuery 1.0 and XPath 2.0 Formal Semantics, Prime Types, type function prime(Type)

Reimplemented in QPatternist::NoneType.

Definition at line 56 of file qitemtype.cpp.

57 {
58  const ItemType *ca = this;
59 
60  if(other == *CommonSequenceTypes::None)
61  return *ca;
62 
63  if(*ca == *CommonSequenceTypes::Empty)
64  return other;
65  else if(other == *CommonSequenceTypes::Empty)
66  return *ca;
67 
68  do
69  {
70  const ItemType *cb = &other;
71  do
72  {
73  if(*ca == *cb)
74  return *ca;
75 
76  cb = cb->xdtSuperType().data();
77  }
78  while(cb);
79 
80  ca = ca->xdtSuperType().data();
81  }
82  while(ca);
83 
84  Q_ASSERT_X(false, Q_FUNC_INFO, "We should never reach this line.");
85  return *this;
86 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
virtual ItemType::Ptr xdtSuperType() const =0
static const EmptySequenceType::Ptr Empty
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Base class for the XPath Data Model&#39;s type hierarchy.
Definition: qitemtype_p.h:82
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ xdtSuperType()

virtual ItemType::Ptr QPatternist::ItemType::xdtSuperType ( ) const
pure virtual

Determines the type's parent type in the XPath Data Model hierarchy. For example, for the type xs:anyAtomicType, the super type in the XPath Data Model is item(), not xs:anySimpleType. SchemaType::xdtSuperType navigates the schema hierarchy.

See also
SchemaType::wxsSuperType()
Returns
the type's super type.

Implemented in QPatternist::NoneType, QPatternist::MultiItemType, QPatternist::EBVType, QPatternist::NumericType, QPatternist::BuiltinAtomicType, QPatternist::EmptySequenceType, QPatternist::AnyAtomicType, QPatternist::AnyItemType, QPatternist::BuiltinNodeType< kind >, QPatternist::AnyNodeType, QPatternist::XSLTNodeTest, and QPatternist::AbstractNodeTest.

Referenced by operator|(), QPatternist::AbstractNodeTest::xdtTypeMatches(), QPatternist::XSLTNodeTest::xdtTypeMatches(), and QPatternist::AtomicType::xdtTypeMatches().

◆ xdtTypeMatches()

virtual bool QPatternist::ItemType::xdtTypeMatches ( const ItemType::Ptr other) const
pure virtual

Returns true if other matches this type. That is, if other is equal to this type or a subtype of this type.

For instance this statements evaluates to true:

but this evaluates to false:

Parameters
otherthe other ItemType that is to be matched. This is guaranteed by the caller to never be null.

Implemented in QPatternist::AtomicType, QPatternist::MultiItemType, QPatternist::AnyItemType, QPatternist::EBVType, QPatternist::EmptySequenceType, QPatternist::NoneType, QPatternist::XSLTNodeTest, QPatternist::AnyNodeType, QPatternist::BuiltinNodeType< kind >, QPatternist::NumericType, and QPatternist::AbstractNodeTest.

Referenced by QPatternist::BySequenceTypeIdentifier::matches(), QPatternist::SequenceType::matches(), and QPatternist::CastAs::typeCheck().

Friends and Related Functions

◆ operator|()

ItemType::Ptr operator| ( const ItemType::Ptr op1,
const ItemType::Ptr op2 
)
related

This operator exists for making it easier to use the ItemType class, which always are wrapped in ItemType::Ptr, by taking care of the dereferencing of ItemType::Ptr instances. Semantically, it performs the same as ItemType's operator of the same name.

See also
ItemType::operator|()
operator|=(ItemType::Ptr &, const ItemType::Ptr &)

Definition at line 250 of file qitemtype_p.h.

252  {
253  return ItemType::Ptr(const_cast<ItemType *>(&(*op1 | *op2)));
254  }
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88

◆ operator|=()

void operator|= ( ItemType::Ptr op1,
const ItemType::Ptr op2 
)
related

Computes the union type of op1 and op2, and assigns it to op1.

This operator exists for making it easier to use the ItemType class, which always are wrapped in ItemType::Ptr, by taking care of the dereferencing of the ItemType::Ptr instances.

See also
operator|(const ItemType::Ptr &, const ItemType::Ptr &)
Parameters
op1if null, op2 is returned unchanged
op2the other operand

Definition at line 273 of file qitemtype_p.h.

Referenced by QRect::QRect().

274  {
275  op1 = op1 | op2;
276  }

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