1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
44 * @short This file is included by BuiltintNodeType.h.
45 * If you need includes in this file, put them in BuiltintNodeType.h, outside of the namespace.
48 template <const QXmlNodeModelIndex::NodeKind kind>
49 BuiltinNodeType<kind>::BuiltinNodeType()
53 template <const QXmlNodeModelIndex::NodeKind kind>
54 bool BuiltinNodeType<kind>::xdtTypeMatches(const ItemType::Ptr &other) const
56 if(!other->isNodeType())
59 return *static_cast<const BuiltinNodeType *>(other.data()) == *this
61 : xdtTypeMatches(other->xdtSuperType());
64 template <const QXmlNodeModelIndex::NodeKind kind>
65 bool BuiltinNodeType<kind>::itemMatches(const Item &item) const
69 return item.isNode() &&
70 item.asNode().kind() == kind;
73 template <const QXmlNodeModelIndex::NodeKind kind>
74 ItemType::Ptr BuiltinNodeType<kind>::atomizedType() const
78 /* Fallthrough all these. */
79 case QXmlNodeModelIndex::Attribute:
80 case QXmlNodeModelIndex::Document:
81 case QXmlNodeModelIndex::Element:
82 case QXmlNodeModelIndex::Text:
83 return BuiltinTypes::xsUntypedAtomic;
84 case QXmlNodeModelIndex::ProcessingInstruction:
86 case QXmlNodeModelIndex::Comment:
87 return BuiltinTypes::xsString;
90 Q_ASSERT_X(false, Q_FUNC_INFO,
91 "Encountered invalid XPath Data Model node type.");
92 return BuiltinTypes::xsUntypedAtomic;
97 template <const QXmlNodeModelIndex::NodeKind kind>
98 QString BuiltinNodeType<kind>::displayName(const NamePool::Ptr &) const
102 case QXmlNodeModelIndex::Element:
103 return QLatin1String("element()");
104 case QXmlNodeModelIndex::Document:
105 return QLatin1String("document()");
106 case QXmlNodeModelIndex::Attribute:
107 return QLatin1String("attribute()");
108 case QXmlNodeModelIndex::Text:
109 return QLatin1String("text()");
110 case QXmlNodeModelIndex::ProcessingInstruction:
111 return QLatin1String("processing-instruction()");
112 case QXmlNodeModelIndex::Comment:
113 return QLatin1String("comment()");
116 Q_ASSERT_X(false, Q_FUNC_INFO,
117 "Encountered invalid XPath Data Model node type.");
123 template <const QXmlNodeModelIndex::NodeKind kind>
124 ItemType::Ptr BuiltinNodeType<kind>::xdtSuperType() const
126 return BuiltinTypes::node;
129 template <const QXmlNodeModelIndex::NodeKind kind>
130 QXmlNodeModelIndex::NodeKind BuiltinNodeType<kind>::nodeKind() const
135 template <const QXmlNodeModelIndex::NodeKind kind>
136 PatternPriority BuiltinNodeType<kind>::patternPriority() const
138 /* See XSL Transformations (XSLT) Version 2.0, 6.4 Conflict Resolution for
142 case QXmlNodeModelIndex::Text:
144 case QXmlNodeModelIndex::ProcessingInstruction:
146 case QXmlNodeModelIndex::Comment:
147 /* "If the pattern is any other NodeTest, optionally preceded by a
148 * PatternAxis, then the priority is 0.5."
150 case QXmlNodeModelIndex::Attribute:
152 case QXmlNodeModelIndex::Element:
154 case QXmlNodeModelIndex::Document:
155 /* "If the pattern has the form /, then the priority is -0.5.". */
159 Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown node type");