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 #include "qanyitemtype_p.h"
41 #include "qderivedinteger_p.h"
42 
43 #include "qbuiltinatomictypes_p.h"
44 #include "qbuiltinnodetype_p.h"
45 #include "qbuiltintypes_p.h"
46 #include "qxsltnodetest_p.h"
47 
48 /* Included here to avoid the static initialization failure. */
49 #include "qatomiccasterlocators.cpp"
50 #include "qatomiccomparatorlocators.cpp"
51 #include "qatomicmathematicianlocators.cpp"
52 
53 QT_BEGIN_NAMESPACE
54 
55 using namespace QPatternist;
56 
57 // STATIC DATA
58 /* Special cases. */
59 #define initType(var, cls) const cls::Ptr BuiltinTypes::var(new cls())
60 initType(item,                  AnyItemType);
61 initType(node,                  AnyNodeType);
62 #undef initType
63 
64 #define initSType(var, cls) const SchemaType::Ptr BuiltinTypes::var(new cls())
65 initSType(xsAnyType,            AnyType);
66 initSType(xsAnySimpleType,      AnySimpleType);
67 initSType(xsUntyped,            Untyped);
68 #undef initSType
69 
70 /* The primitive atomic types. */
71 #define at(className, varName) const AtomicType::Ptr BuiltinTypes::varName(new className());
72 at(AnyAtomicType,               xsAnyAtomicType)
73 at(UntypedAtomicType,           xsUntypedAtomic)
74 at(DateTimeType,                xsDateTime)
75 at(DateType,                    xsDate)
76 at(SchemaTimeType,                    xsTime)
77 at(DurationType,                xsDuration)
78 at(YearMonthDurationType,       xsYearMonthDuration)
79 at(DayTimeDurationType,         xsDayTimeDuration)
80 
81 at(NumericType,                 numeric)
82 at(DecimalType,                 xsDecimal)
83 at(GYearMonthType,              xsGYearMonth)
84 at(GYearType,                   xsGYear)
85 at(GMonthDayType,               xsGMonthDay)
86 at(GDayType,                    xsGDay)
87 at(GMonthType,                  xsGMonth)
88 
89 at(BooleanType,                 xsBoolean)
90 at(Base64BinaryType,            xsBase64Binary)
91 at(AnyURIType,                  xsAnyURI)
92 
93 #define it(className, varName) const ItemType::Ptr BuiltinTypes::varName(new className());
94 at(QNameType,                   xsQName)
95 at(HexBinaryType,               xsHexBinary)
96 at(FloatType,                   xsFloat)
97 at(DoubleType,                  xsDouble)
98 #undef it
99 
100 const AtomicType::Ptr BuiltinTypes::xsString(new StringType(BuiltinTypes::xsAnyAtomicType,
101                                                             AtomicCasterLocator::Ptr(new ToStringCasterLocator())));
102 
103 #define dsType(varName, parent)                                             \
104     const AtomicType::Ptr BuiltinTypes::xs ## varName                       \
105     (new DerivedStringType<Type ## varName>(BuiltinTypes::parent,           \
106                            AtomicCasterLocator::Ptr(new ToDerivedStringCasterLocator<Type ## varName>())))
107 
108 dsType(NormalizedString,    xsString);
109 dsType(Token,               xsNormalizedString);
110 dsType(Language,            xsToken);
111 dsType(NMTOKEN,             xsToken);
112 dsType(Name,                xsToken);
113 dsType(NCName,              xsName);
114 dsType(ID,                  xsNCName);
115 dsType(IDREF,               xsNCName);
116 dsType(ENTITY,              xsNCName);
117 #undef sType
118 
119 const AtomicType::Ptr BuiltinTypes::xsInteger(new IntegerType(BuiltinTypes::xsDecimal,
120                                                               AtomicCasterLocator::Ptr(new ToIntegerCasterLocator())));
121 
122 #define iType(varName, parent)                                              \
123     const AtomicType::Ptr BuiltinTypes::xs ## varName                       \
124     (new DerivedIntegerType<Type ## varName>(parent,                        \
125                                              AtomicCasterLocator::Ptr(new ToDerivedIntegerCasterLocator<Type ## varName>())))
126 
127 /* Initialize derived integers. The order of initialization is significant. */
128 iType(NonPositiveInteger,   xsInteger);
129 iType(NegativeInteger,      xsNonPositiveInteger);
130 iType(Long,                 xsInteger);
131 iType(Int,                  xsLong);
132 iType(Short,                xsInt);
133 iType(Byte,                 xsShort);
134 iType(NonNegativeInteger,   xsInteger);
135 iType(UnsignedLong,         xsNonNegativeInteger);
136 iType(UnsignedInt,          xsUnsignedLong);
137 iType(UnsignedShort,        xsUnsignedInt);
138 iType(UnsignedByte,         xsUnsignedShort);
139 iType(PositiveInteger,      xsNonNegativeInteger);
140 #undef iType
141 
142 at(NOTATIONType,            xsNOTATION)
143 #undef at
144 
145 /* QXmlNodeModelIndex types */
146 #define nt(var, enu) const ItemType::Ptr BuiltinTypes::var = \
147                            ItemType::Ptr(new BuiltinNodeType<QXmlNodeModelIndex::enu>())
148 
149 nt(comment,     Comment);
150 nt(attribute,   Attribute);
151 nt(document,    Document);
152 nt(element,     Element);
153 nt(text,        Text);
154 nt(pi,          ProcessingInstruction);
155 #undef nt
156 
157 const ItemType::Ptr BuiltinTypes::xsltNodeTest(new XSLTNodeTest());
158 
159 QT_END_NAMESPACE
160