| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
| 7 | ** |
| 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 The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | /** |
| 52 | * @file |
| 53 | * @short This file is included by BuiltintNodeType.h. |
| 54 | * If you need includes in this file, put them in BuiltintNodeType.h, outside of the namespace. |
| 55 | */ |
| 56 | |
| 57 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 58 | BuiltinNodeType<kind>::BuiltinNodeType() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 63 | bool BuiltinNodeType<kind>::xdtTypeMatches(const ItemType::Ptr &other) const |
| 64 | { |
| 65 | if(!other->isNodeType()) |
| 66 | return false; |
| 67 | |
| 68 | return *static_cast<const BuiltinNodeType *>(other.data()) == *this |
| 69 | ? true |
| 70 | : xdtTypeMatches(other: other->xdtSuperType()); |
| 71 | } |
| 72 | |
| 73 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 74 | bool BuiltinNodeType<kind>::itemMatches(const Item &item) const |
| 75 | { |
| 76 | Q_ASSERT(item); |
| 77 | |
| 78 | return item.isNode() && |
| 79 | item.asNode().kind() == kind; |
| 80 | } |
| 81 | |
| 82 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 83 | ItemType::Ptr BuiltinNodeType<kind>::atomizedType() const |
| 84 | { |
| 85 | switch(kind) |
| 86 | { |
| 87 | /* Fallthrough all these. */ |
| 88 | case QXmlNodeModelIndex::Attribute: |
| 89 | case QXmlNodeModelIndex::Document: |
| 90 | case QXmlNodeModelIndex::Element: |
| 91 | case QXmlNodeModelIndex::Text: |
| 92 | return BuiltinTypes::xsUntypedAtomic; |
| 93 | case QXmlNodeModelIndex::ProcessingInstruction: |
| 94 | /* Fallthrough. */ |
| 95 | case QXmlNodeModelIndex::Comment: |
| 96 | return BuiltinTypes::xsString; |
| 97 | default: |
| 98 | { |
| 99 | Q_ASSERT_X(false, Q_FUNC_INFO, |
| 100 | "Encountered invalid XPath Data Model node type." ); |
| 101 | return BuiltinTypes::xsUntypedAtomic; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 107 | QString BuiltinNodeType<kind>::displayName(const NamePool::Ptr &) const |
| 108 | { |
| 109 | switch(kind) |
| 110 | { |
| 111 | case QXmlNodeModelIndex::Element: |
| 112 | return QLatin1String("element()" ); |
| 113 | case QXmlNodeModelIndex::Document: |
| 114 | return QLatin1String("document()" ); |
| 115 | case QXmlNodeModelIndex::Attribute: |
| 116 | return QLatin1String("attribute()" ); |
| 117 | case QXmlNodeModelIndex::Text: |
| 118 | return QLatin1String("text()" ); |
| 119 | case QXmlNodeModelIndex::ProcessingInstruction: |
| 120 | return QLatin1String("processing-instruction()" ); |
| 121 | case QXmlNodeModelIndex::Comment: |
| 122 | return QLatin1String("comment()" ); |
| 123 | default: |
| 124 | { |
| 125 | Q_ASSERT_X(false, Q_FUNC_INFO, |
| 126 | "Encountered invalid XPath Data Model node type." ); |
| 127 | return QString(); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 133 | ItemType::Ptr BuiltinNodeType<kind>::xdtSuperType() const |
| 134 | { |
| 135 | return BuiltinTypes::node; |
| 136 | } |
| 137 | |
| 138 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 139 | QXmlNodeModelIndex::NodeKind BuiltinNodeType<kind>::nodeKind() const |
| 140 | { |
| 141 | return kind; |
| 142 | } |
| 143 | |
| 144 | template <const QXmlNodeModelIndex::NodeKind kind> |
| 145 | PatternPriority BuiltinNodeType<kind>::patternPriority() const |
| 146 | { |
| 147 | /* See XSL Transformations (XSLT) Version 2.0, 6.4 Conflict Resolution for |
| 148 | * Template Rules */ |
| 149 | switch(kind) |
| 150 | { |
| 151 | case QXmlNodeModelIndex::Text: |
| 152 | /* Fallthrough. */ |
| 153 | case QXmlNodeModelIndex::ProcessingInstruction: |
| 154 | /* Fallthrough. */ |
| 155 | case QXmlNodeModelIndex::Comment: |
| 156 | /* "If the pattern is any other NodeTest, optionally preceded by a |
| 157 | * PatternAxis, then the priority is 0.5." |
| 158 | * Fallthrough. */ |
| 159 | case QXmlNodeModelIndex::Attribute: |
| 160 | /* Fallthrough. */ |
| 161 | case QXmlNodeModelIndex::Element: |
| 162 | /* Fallthrough. */ |
| 163 | case QXmlNodeModelIndex::Document: |
| 164 | /* "If the pattern has the form /, then the priority is -0.5.". */ |
| 165 | return -0.5; |
| 166 | default: |
| 167 | { |
| 168 | Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown node type" ); |
| 169 | return 0; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | |