be9c28f18c0f50c3f4e716ccda41b18bf4864468
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / type / qbuiltintypes.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qanyitemtype_p.h"
43 #include "qderivedinteger_p.h"
44
45 #include "qbuiltinatomictypes_p.h"
46 #include "qbuiltinnodetype_p.h"
47 #include "qbuiltintypes_p.h"
48 #include "qxsltnodetest_p.h"
49
50 /* Included here to avoid the static initialization failure. */
51 #include "qatomiccasterlocators.cpp"
52 #include "qatomiccomparatorlocators.cpp"
53 #include "qatomicmathematicianlocators.cpp"
54
55 QT_BEGIN_NAMESPACE
56
57 using namespace QPatternist;
58
59 // STATIC DATA
60 /* Special cases. */
61 #define initType(var, cls) const cls::Ptr BuiltinTypes::var(new cls())
62 initType(item,                  AnyItemType);
63 initType(node,                  AnyNodeType);
64 #undef initType
65
66 #define initSType(var, cls) const SchemaType::Ptr BuiltinTypes::var(new cls())
67 initSType(xsAnyType,            AnyType);
68 initSType(xsAnySimpleType,      AnySimpleType);
69 initSType(xsUntyped,            Untyped);
70 #undef initSType
71
72 /* The primitive atomic types. */
73 #define at(className, varName) const AtomicType::Ptr BuiltinTypes::varName(new className());
74 at(AnyAtomicType,               xsAnyAtomicType)
75 at(UntypedAtomicType,           xsUntypedAtomic)
76 at(DateTimeType,                xsDateTime)
77 at(DateType,                    xsDate)
78 at(SchemaTimeType,                    xsTime)
79 at(DurationType,                xsDuration)
80 at(YearMonthDurationType,       xsYearMonthDuration)
81 at(DayTimeDurationType,         xsDayTimeDuration)
82
83 at(NumericType,                 numeric)
84 at(DecimalType,                 xsDecimal)
85 at(GYearMonthType,              xsGYearMonth)
86 at(GYearType,                   xsGYear)
87 at(GMonthDayType,               xsGMonthDay)
88 at(GDayType,                    xsGDay)
89 at(GMonthType,                  xsGMonth)
90
91 at(BooleanType,                 xsBoolean)
92 at(Base64BinaryType,            xsBase64Binary)
93 at(AnyURIType,                  xsAnyURI)
94
95 #define it(className, varName) const ItemType::Ptr BuiltinTypes::varName(new className());
96 at(QNameType,                   xsQName)
97 at(HexBinaryType,               xsHexBinary)
98 at(FloatType,                   xsFloat)
99 at(DoubleType,                  xsDouble)
100 #undef it
101
102 const AtomicType::Ptr BuiltinTypes::xsString(new StringType(BuiltinTypes::xsAnyAtomicType,
103                                                             AtomicCasterLocator::Ptr(new ToStringCasterLocator())));
104
105 #define dsType(varName, parent)                                             \
106     const AtomicType::Ptr BuiltinTypes::xs ## varName                       \
107     (new DerivedStringType<Type ## varName>(BuiltinTypes::parent,           \
108                            AtomicCasterLocator::Ptr(new ToDerivedStringCasterLocator<Type ## varName>())))
109
110 dsType(NormalizedString,    xsString);
111 dsType(Token,               xsNormalizedString);
112 dsType(Language,            xsToken);
113 dsType(NMTOKEN,             xsToken);
114 dsType(Name,                xsToken);
115 dsType(NCName,              xsName);
116 dsType(ID,                  xsNCName);
117 dsType(IDREF,               xsNCName);
118 dsType(ENTITY,              xsNCName);
119 #undef sType
120
121 const AtomicType::Ptr BuiltinTypes::xsInteger(new IntegerType(BuiltinTypes::xsDecimal,
122                                                               AtomicCasterLocator::Ptr(new ToIntegerCasterLocator())));
123
124 #define iType(varName, parent)                                              \
125     const AtomicType::Ptr BuiltinTypes::xs ## varName                       \
126     (new DerivedIntegerType<Type ## varName>(parent,                        \
127                                              AtomicCasterLocator::Ptr(new ToDerivedIntegerCasterLocator<Type ## varName>())))
128
129 /* Initialize derived integers. The order of initialization is significant. */
130 iType(NonPositiveInteger,   xsInteger);
131 iType(NegativeInteger,      xsNonPositiveInteger);
132 iType(Long,                 xsInteger);
133 iType(Int,                  xsLong);
134 iType(Short,                xsInt);
135 iType(Byte,                 xsShort);
136 iType(NonNegativeInteger,   xsInteger);
137 iType(UnsignedLong,         xsNonNegativeInteger);
138 iType(UnsignedInt,          xsUnsignedLong);
139 iType(UnsignedShort,        xsUnsignedInt);
140 iType(UnsignedByte,         xsUnsignedShort);
141 iType(PositiveInteger,      xsNonNegativeInteger);
142 #undef iType
143
144 at(NOTATIONType,            xsNOTATION)
145 #undef at
146
147 /* QXmlNodeModelIndex types */
148 #define nt(var, enu) const ItemType::Ptr BuiltinTypes::var = \
149                            ItemType::Ptr(new BuiltinNodeType<QXmlNodeModelIndex::enu>())
150
151 nt(comment,     Comment);
152 nt(attribute,   Attribute);
153 nt(document,    Document);
154 nt(element,     Element);
155 nt(text,        Text);
156 nt(pi,          ProcessingInstruction);
157 #undef nt
158
159 const ItemType::Ptr BuiltinTypes::xsltNodeTest(new XSLTNodeTest());
160
161 QT_END_NAMESPACE