fe9372d7dc044c3f4012d0f4e4e8c8d8dfe6e2c7
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / type / qatomicmathematicianlocators.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 "qabstractfloatmathematician_p.h"
43 #include "qatomicmathematicianlocators_p.h"
44 #include "qatomicmathematicians_p.h"
45
46 QT_BEGIN_NAMESPACE
47
48 using namespace QPatternist;
49
50 #define implMathVisit(ownerClass, visitor, mather, validOps)                            \
51 AtomicTypeVisitorResult::Ptr                                                            \
52 ownerClass##MathematicianLocator::visit(const visitor *, const qint16 op,               \
53                                         const SourceLocationReflection *const r) const  \
54 {                                                                                       \
55     Q_UNUSED(r)                                                                         \
56     /* Note the extra paranteses around validOps. */                                    \
57     if(((validOps) & AtomicMathematician::Operator(op)) == op)                                                         \
58         return AtomicTypeVisitorResult::Ptr(new mather());                              \
59     else                                                                                \
60         return AtomicTypeVisitorResult::Ptr();                                          \
61 }
62
63 #define implReportingMathVisit(ownerClass, visitor, mather, validOps)                   \
64 AtomicTypeVisitorResult::Ptr                                                            \
65 ownerClass##MathematicianLocator::visit(const visitor *, const qint16 op,               \
66                                         const SourceLocationReflection *const r) const  \
67 {                                                                                       \
68     /* Note the extra paranteses around validOps. */                                    \
69     if(((validOps) & AtomicMathematician::Operator(op)) == op)                                                         \
70         return AtomicTypeVisitorResult::Ptr(new mather(r));                             \
71     else                                                                                \
72         return AtomicTypeVisitorResult::Ptr();                                          \
73 }
74
75 #define implRevReportingMathVisit(ownerClass, visitor, mather, validOps)                \
76 AtomicTypeVisitorResult::Ptr                                                            \
77 ownerClass##MathematicianLocator::visit(const visitor *, const qint16 op,               \
78                                         const SourceLocationReflection *const r) const  \
79 {                                                                                       \
80     /* Note the extra paranteses around validOps. */                                    \
81     if(((validOps) & AtomicMathematician::Operator(op)) == op)                                                         \
82         return AtomicTypeVisitorResult::Ptr(new OperandSwitcherMathematician(           \
83                                             AtomicMathematician::Ptr(new mather(r))));  \
84     else                                                                                \
85         return AtomicTypeVisitorResult::Ptr();                                          \
86 }
87
88 static const AtomicMathematician::Operators AllMathOperators(AtomicMathematician::Add       |
89                                                              AtomicMathematician::Div       |
90                                                              AtomicMathematician::IDiv      |
91                                                              AtomicMathematician::Mod       |
92                                                              AtomicMathematician::Multiply  |
93                                                              AtomicMathematician::Substract);
94
95 static const AtomicMathematician::Operators DivMultiply(AtomicMathematician::Multiply       |
96                                                         AtomicMathematician::Div);
97
98 static const AtomicMathematician::Operators DurationOps(AtomicMathematician::Div            |
99                                                         AtomicMathematician::Substract      |
100                                                         AtomicMathematician::Add);
101
102 static const AtomicMathematician::Operators DTOps(AtomicMathematician::Substract            |
103                                                   AtomicMathematician::Add);
104
105 implReportingMathVisit(Double,           DecimalType,            DoubleMathematician,    AllMathOperators)
106 implReportingMathVisit(Double,           DoubleType,             DoubleMathematician,    AllMathOperators)
107 implReportingMathVisit(Double,           FloatType,              DoubleMathematician,    AllMathOperators)
108 implReportingMathVisit(Double,           IntegerType,            DoubleMathematician,    AllMathOperators)
109 implRevReportingMathVisit(Double,           YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
110 implRevReportingMathVisit(Double,           DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
111
112 implReportingMathVisit(Float,            DecimalType,            FloatMathematician,     AllMathOperators)
113 implReportingMathVisit(Float,            DoubleType,    DoubleMathematician,    AllMathOperators)
114 implReportingMathVisit(Float,            FloatType,              FloatMathematician,     AllMathOperators)
115 implReportingMathVisit(Float,            IntegerType,            FloatMathematician,     AllMathOperators)
116 implRevReportingMathVisit(Float,            YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
117 implRevReportingMathVisit(Float,            DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
118
119 implReportingMathVisit(Decimal, DecimalType,            DecimalMathematician,   AllMathOperators)
120 implReportingMathVisit(Decimal,          DoubleType,    DoubleMathematician,    AllMathOperators)
121 implReportingMathVisit(Decimal,          FloatType,              FloatMathematician,     AllMathOperators)
122 implReportingMathVisit(Decimal, IntegerType,            DecimalMathematician,   AllMathOperators)
123 implRevReportingMathVisit(Decimal,          YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
124 implRevReportingMathVisit(Decimal,          DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
125
126 implReportingMathVisit(Integer, DecimalType,            DecimalMathematician,   AllMathOperators)
127 implReportingMathVisit(Integer,          DoubleType,    DoubleMathematician,    AllMathOperators)
128 implReportingMathVisit(Integer,          FloatType,              FloatMathematician,     AllMathOperators)
129 implReportingMathVisit(Integer, IntegerType,            IntegerMathematician,   AllMathOperators)
130 implRevReportingMathVisit(Integer,          YearMonthDurationType,  DurationNumericMathematician,  AtomicMathematician::Multiply)
131 implRevReportingMathVisit(Integer,          DayTimeDurationType,    DurationNumericMathematician,  AtomicMathematician::Multiply)
132
133 implRevReportingMathVisit(DayTimeDuration,  DateTimeType,           DateTimeDurationMathematician,       AtomicMathematician::Add)
134 implRevReportingMathVisit(DayTimeDuration,  DateType,               DateTimeDurationMathematician,       AtomicMathematician::Add)
135 implMathVisit(DayTimeDuration,  DayTimeDurationType,    DurationDurationMathematician, DurationOps)
136 implReportingMathVisit(DayTimeDuration,  DecimalType,   DurationNumericMathematician,  DivMultiply)
137 implReportingMathVisit(DayTimeDuration,  DoubleType,    DurationNumericMathematician,  DivMultiply)
138 implReportingMathVisit(DayTimeDuration,  FloatType,     DurationNumericMathematician,  DivMultiply)
139 implReportingMathVisit(DayTimeDuration,  IntegerType,   DurationNumericMathematician,  DivMultiply)
140 implRevReportingMathVisit(DayTimeDuration,  SchemaTimeType,               DateTimeDurationMathematician,       AtomicMathematician::Add)
141
142 implRevReportingMathVisit(YearMonthDuration, DateTimeType,          DateTimeDurationMathematician,       AtomicMathematician::Add)
143 implRevReportingMathVisit(YearMonthDuration, DateType,              DateTimeDurationMathematician,       AtomicMathematician::Add)
144 implReportingMathVisit(YearMonthDuration, DecimalType,  DurationNumericMathematician,  DivMultiply)
145 implReportingMathVisit(YearMonthDuration, DoubleType,   DurationNumericMathematician,  DivMultiply)
146 implReportingMathVisit(YearMonthDuration, FloatType,    DurationNumericMathematician,  DivMultiply)
147 implReportingMathVisit(YearMonthDuration, IntegerType,  DurationNumericMathematician,  DivMultiply)
148 implMathVisit(YearMonthDuration, YearMonthDurationType, DurationDurationMathematician, DurationOps)
149
150 implMathVisit(Date,              DateType,              AbstractDateTimeMathematician,
151               AtomicMathematician::Substract)
152 implReportingMathVisit(Date,     YearMonthDurationType, DateTimeDurationMathematician,       DTOps)
153 implReportingMathVisit(Date,     DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
154
155 implMathVisit(SchemaTime,              SchemaTimeType,              AbstractDateTimeMathematician,
156               AtomicMathematician::Substract)
157 implReportingMathVisit(SchemaTime,     DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
158
159 implMathVisit(DateTime,          DateTimeType,          AbstractDateTimeMathematician,
160               AtomicMathematician::Substract)
161 implReportingMathVisit(DateTime, YearMonthDurationType, DateTimeDurationMathematician,       DTOps)
162 implReportingMathVisit(DateTime, DayTimeDurationType,   DateTimeDurationMathematician,       DTOps)
163
164 #undef implMathVisit
165 #undef implReportingMathVisit
166 #undef implRevReportingMathVisit
167
168 QT_END_NAMESPACE