Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / type / qbuiltinnodetype_tpl_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 /**
43  * @file
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.
46  */
47
48 template <const QXmlNodeModelIndex::NodeKind kind>
49 BuiltinNodeType<kind>::BuiltinNodeType()
50 {
51 }
52
53 template <const QXmlNodeModelIndex::NodeKind kind>
54 bool BuiltinNodeType<kind>::xdtTypeMatches(const ItemType::Ptr &other) const
55 {
56     if(!other->isNodeType())
57         return false;
58
59     return *static_cast<const BuiltinNodeType *>(other.data()) == *this
60             ? true
61             : xdtTypeMatches(other->xdtSuperType());
62 }
63
64 template <const QXmlNodeModelIndex::NodeKind kind>
65 bool BuiltinNodeType<kind>::itemMatches(const Item &item) const
66 {
67     Q_ASSERT(item);
68
69     return item.isNode() &&
70            item.asNode().kind() == kind;
71 }
72
73 template <const QXmlNodeModelIndex::NodeKind kind>
74 ItemType::Ptr BuiltinNodeType<kind>::atomizedType() const
75 {
76     switch(kind)
77     {
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:
85         /* Fallthrough. */
86         case QXmlNodeModelIndex::Comment:
87             return BuiltinTypes::xsString;
88         default:
89         {
90             Q_ASSERT_X(false, Q_FUNC_INFO,
91                        "Encountered invalid XPath Data Model node type.");
92             return BuiltinTypes::xsUntypedAtomic;
93         }
94     }
95 }
96
97 template <const QXmlNodeModelIndex::NodeKind kind>
98 QString BuiltinNodeType<kind>::displayName(const NamePool::Ptr &) const
99 {
100     switch(kind)
101     {
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()");
114         default:
115         {
116             Q_ASSERT_X(false, Q_FUNC_INFO,
117                        "Encountered invalid XPath Data Model node type.");
118             return QString();
119         }
120     }
121 }
122
123 template <const QXmlNodeModelIndex::NodeKind kind>
124 ItemType::Ptr BuiltinNodeType<kind>::xdtSuperType() const
125 {
126     return BuiltinTypes::node;
127 }
128
129 template <const QXmlNodeModelIndex::NodeKind kind>
130 QXmlNodeModelIndex::NodeKind BuiltinNodeType<kind>::nodeKind() const
131 {
132     return kind;
133 }
134
135 template <const QXmlNodeModelIndex::NodeKind kind>
136 PatternPriority BuiltinNodeType<kind>::patternPriority() const
137 {
138     /* See XSL Transformations (XSLT) Version 2.0, 6.4 Conflict Resolution for
139      * Template Rules */
140     switch(kind)
141     {
142         case QXmlNodeModelIndex::Text:
143         /* Fallthrough. */
144         case QXmlNodeModelIndex::ProcessingInstruction:
145         /* Fallthrough. */
146         case QXmlNodeModelIndex::Comment:
147             /* "If the pattern is any other NodeTest, optionally preceded by a
148              * PatternAxis, then the priority is 0.5."
149              * Fallthrough. */
150         case QXmlNodeModelIndex::Attribute:
151         /* Fallthrough. */
152         case QXmlNodeModelIndex::Element:
153         /* Fallthrough. */
154         case QXmlNodeModelIndex::Document:
155             /* "If the pattern has the form /, then the priority is -0.5.". */
156             return -0.5;
157         default:
158         {
159             Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown node type");
160             return 0;
161         }
162     }
163
164 }
165