5c482f7d21c742b73b28e12dbe9e39f0b9d3e0e4
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / type / qbuiltinatomictypes.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 "qatomicmathematicianlocators_p.h"
43 #include "qbuiltintypes_p.h"
44
45 #include "qbuiltinatomictypes_p.h"
46
47 QT_BEGIN_NAMESPACE
48
49 using namespace QPatternist;
50
51 /* -------------------------------------------------------------- */
52 #define implAccept(className)                                                                       \
53 AtomicTypeVisitorResult::Ptr className##Type::accept(const AtomicTypeVisitor::Ptr &v,               \
54                                                      const SourceLocationReflection *const r) const \
55 {                                                                                                   \
56     return v->visit(this, r);                                                                       \
57 }                                                                                                   \
58                                                                                                     \
59 AtomicTypeVisitorResult::Ptr                                                                        \
60 className##Type::accept(const ParameterizedAtomicTypeVisitor::Ptr &v,                               \
61                         const qint16 op,                                                            \
62                         const SourceLocationReflection *const r) const                              \
63 {                                                                                                   \
64     return v->visit(this, op, r);                                                                   \
65 }
66
67 #define deployComp(className, qname, parent, comp, mather, caster)                          \
68 className##Type::className##Type() : BuiltinAtomicType(BuiltinTypes::parent,                \
69                                                        comp,                                \
70                                                        mather,                              \
71                                                        caster)                              \
72 {                                                                                           \
73 }                                                                                           \
74 implAccept(className)
75
76 #define deployBase(className, qname, parent) deployComp(className, qname, parent,           \
77                                                         AtomicComparatorLocator::Ptr(),     \
78                                                         AtomicMathematicianLocator::Ptr(),  \
79                                                         AtomicCasterLocator::Ptr())
80
81 #define deployFull(className, qname, parent)                                                \
82 deployComp(className, qname, parent,                                                        \
83            AtomicComparatorLocator::Ptr(new className##ComparatorLocator()),                \
84            AtomicMathematicianLocator::Ptr(),                                               \
85            AtomicCasterLocator::Ptr(new To##className##CasterLocator()))
86
87 #define deployMathComp(className, qname, parent)                                            \
88 deployComp(className, qname, parent,                                                        \
89            AtomicComparatorLocator::Ptr(new className##ComparatorLocator()),                \
90            AtomicMathematicianLocator::Ptr(new className##MathematicianLocator()),          \
91            AtomicCasterLocator::Ptr(new To##className##CasterLocator()))
92 /* -------------------------------------------------------------- */
93
94 /* -------------------------------------------------------------- */
95 /* xs:anyURI & xs:untypedAtomic are much treated like strings. This ensures
96  * they get the correct operators and automatically takes care of type promotion. */
97 deployComp(UntypedAtomic,       xsUntypedAtomic,       xsAnyAtomicType,
98            AtomicComparatorLocator::Ptr(new StringComparatorLocator()),
99            AtomicMathematicianLocator::Ptr(),
100            AtomicCasterLocator::Ptr(new ToUntypedAtomicCasterLocator()))
101 deployComp(AnyURI,              xsAnyURI,            xsAnyAtomicType,
102            AtomicComparatorLocator::Ptr(new StringComparatorLocator()),
103            AtomicMathematicianLocator::Ptr(),
104            AtomicCasterLocator::Ptr(new ToAnyURICasterLocator()))
105
106 deployBase(NOTATION,            xsNOTATION,                 xsAnyAtomicType)
107
108 deployMathComp(Float,               xsFloat,                numeric)
109 deployMathComp(Double,              xsDouble,               numeric)
110 deployMathComp(Decimal,             xsDecimal,              numeric)
111 deployMathComp(DayTimeDuration,     xsDayTimeDuration,      xsDuration)
112 deployMathComp(YearMonthDuration,   xsYearMonthDuration,    xsDuration)
113 deployMathComp(Date,                xsDate,                 xsAnyAtomicType)
114 deployMathComp(DateTime,            xsDateTime,             xsAnyAtomicType)
115 deployMathComp(SchemaTime,          xsTime,                 xsAnyAtomicType)
116
117 deployFull(Base64Binary,        xsBase64Binary,             xsAnyAtomicType)
118 deployFull(Boolean,             xsBoolean,                  xsAnyAtomicType)
119 deployFull(Duration,            xsDuration,                 xsAnyAtomicType)
120 deployFull(GDay,                xsGDay,                     xsAnyAtomicType)
121 deployFull(GMonth,              xsGMonth,                   xsAnyAtomicType)
122 deployFull(GMonthDay,           xsGMonthDay,                xsAnyAtomicType)
123 deployFull(GYear,               xsGYear,                    xsAnyAtomicType)
124 deployFull(GYearMonth,          xsGYearMonth,               xsAnyAtomicType)
125 deployFull(HexBinary,           xsHexBinary,                xsAnyAtomicType)
126 deployFull(QName,               xsQName,                    xsAnyAtomicType)
127 /* --------------------------------------------------------------- */
128
129 /* --------------------------------------------------------------- */
130 StringType::StringType(const AtomicType::Ptr &pType,
131                        const AtomicCasterLocator::Ptr &casterLoc)
132 : BuiltinAtomicType(pType,
133                     AtomicComparatorLocator::Ptr(new StringComparatorLocator()),
134                     AtomicMathematicianLocator::Ptr(),
135                     casterLoc)
136 {
137 }
138 implAccept(String)
139 /* --------------------------------------------------------------- */
140
141 /* --------------------------------------------------------------- */
142 IntegerType::IntegerType(const AtomicType::Ptr &pType,
143                          const AtomicCasterLocator::Ptr &casterLoc)
144 : BuiltinAtomicType(pType,
145                     AtomicComparatorLocator::Ptr(new IntegerComparatorLocator()),
146                     AtomicMathematicianLocator::Ptr(new IntegerMathematicianLocator()),
147                     casterLoc)
148 {
149 }
150 implAccept(Integer)
151 /* --------------------------------------------------------------- */
152
153 /* ---------------------- Special Overrides ---------------------- */
154 AnyAtomicType::AnyAtomicType() : BuiltinAtomicType(AtomicType::Ptr(),
155                                                    AtomicComparatorLocator::Ptr(),
156                                                    AtomicMathematicianLocator::Ptr(),
157                                                    AtomicCasterLocator::Ptr())
158 {
159 }
160 implAccept(AnyAtomic)
161
162 ItemType::Ptr AnyAtomicType::xdtSuperType() const
163 {
164     return BuiltinTypes::item;
165 }
166
167 SchemaType::Ptr AnyAtomicType::wxsSuperType() const
168 {
169     return BuiltinTypes::xsAnySimpleType;
170 }
171
172 bool AnyAtomicType::isAbstract() const
173 {
174     return true;
175 }
176
177 bool NOTATIONType::isAbstract() const
178 {
179     return true;
180 }
181
182 #define implementName(className, typeName)                          \
183 QXmlName className##Type::name(const NamePool::Ptr &np) const          \
184 {                                                                   \
185     return np->allocateQName(StandardNamespaces::xs, typeName);     \
186 }                                                                   \
187                                                                     \
188 QString className##Type::displayName(const NamePool::Ptr &np) const \
189 {                                                                   \
190     return np->displayName(name(np));                               \
191 }
192
193 implementName(AnyAtomic,            QLatin1String("anyAtomicType"))
194 implementName(AnyURI,               QLatin1String("anyURI"))
195 implementName(Base64Binary,         QLatin1String("base64Binary"))
196 implementName(Boolean,              QLatin1String("boolean"))
197 implementName(Date,                 QLatin1String("date"))
198 implementName(DateTime,             QLatin1String("dateTime"))
199 implementName(DayTimeDuration,      QLatin1String("dayTimeDuration"))
200 implementName(Decimal,              QLatin1String("decimal"))
201 implementName(Double,               QLatin1String("double"))
202 implementName(Duration,             QLatin1String("duration"))
203 implementName(Float,                QLatin1String("float"))
204 implementName(GDay,                 QLatin1String("gDay"))
205 implementName(GMonthDay,            QLatin1String("gMonthDay"))
206 implementName(GMonth,               QLatin1String("gMonth"))
207 implementName(GYearMonth,           QLatin1String("gYearMonth"))
208 implementName(GYear,                QLatin1String("gYear"))
209 implementName(HexBinary,            QLatin1String("hexBinary"))
210 implementName(Integer,              QLatin1String("integer"))
211 implementName(NOTATION,             QLatin1String("NOTATION"))
212 implementName(QName,                QLatin1String("QName"))
213 implementName(String,               QLatin1String("string"))
214 implementName(SchemaTime,                 QLatin1String("time"))
215 implementName(UntypedAtomic,        QLatin1String("untypedAtomic"))
216 implementName(YearMonthDuration,    QLatin1String("yearMonthDuration"))
217 /* --------------------------------------------------------------- */
218
219 #undef implAccept
220 #undef implementName
221 #undef deployComp
222 #undef deployBase
223 #undef deployFull
224 #undef deployMathComp
225
226 QT_END_NAMESPACE