Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / type / qatomicmathematicianlocators.cpp
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 #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