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//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_AtomicMathematicians_H
51#define Patternist_AtomicMathematicians_H
52
53#include <private/qatomicmathematician_p.h>
54#include <private/qsourcelocationreflection_p.h>
55
56/**
57 * @file
58 * @short Contains classes performing arithemetic operations between atomic values, such as
59 * subtracting two dates.
60 */
61
62QT_BEGIN_NAMESPACE
63
64namespace QPatternist
65{
66 /**
67 *
68 * @ingroup Patternist_xdm
69 * @author Frans Englich <frans.englich@nokia.com>
70 */
71 class DecimalMathematician : public AtomicMathematician
72 , public DelegatingSourceLocationReflection
73 {
74 public:
75 inline DecimalMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
76 {
77 }
78
79 virtual Item calculate(const Item &o1,
80 const Operator op,
81 const Item &o2,
82 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
83 };
84
85 /**
86 * @short Performs arithmetics between Integer values.
87 *
88 * @ingroup Patternist_xdm
89 * @author Frans Englich <frans.englich@nokia.com>
90 */
91 class IntegerMathematician : public AtomicMathematician
92 , public DelegatingSourceLocationReflection
93 {
94 public:
95 inline IntegerMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
96 {
97 }
98
99 virtual Item calculate(const Item &o1,
100 const Operator op,
101 const Item &o2,
102 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
103 };
104
105 /**
106 * @short Performs division or multiplication between either DayTimeDuration or YearMonthDuration
107 * and Double values.
108 *
109 * @ingroup Patternist_xdm
110 * @author Frans Englich <frans.englich@nokia.com>
111 */
112 class DurationNumericMathematician : public AtomicMathematician
113 , public DelegatingSourceLocationReflection
114 {
115 public:
116 inline DurationNumericMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
117 {
118 }
119
120 virtual Item calculate(const Item &o1,
121 const Operator op,
122 const Item &o2,
123 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
124 };
125
126 /**
127 * @short Performs division between DayTimeDuration and DayTimeDuration, or
128 * YearMonthDuration and YearMonthDuration.
129 *
130 * @ingroup Patternist_xdm
131 * @author Frans Englich <frans.englich@nokia.com>
132 */
133 class DurationDurationDivisor : public AtomicMathematician
134 {
135 public:
136 virtual Item calculate(const Item &o1,
137 const Operator op,
138 const Item &o2,
139 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
140 };
141
142 /**
143 * @short Performs arithmetics between DayTimeDuration and DayTimeDuration, or
144 * YearMonthDuration and YearMonthDuration.
145 *
146 * @ingroup Patternist_xdm
147 * @author Frans Englich <frans.englich@nokia.com>
148 */
149 class DurationDurationMathematician : public AtomicMathematician
150 {
151 public:
152 virtual Item calculate(const Item &o1,
153 const Operator op,
154 const Item &o2,
155 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
156 };
157
158 /**
159 * @short Delegates an AtomicMathematician and switches its operands.
160 *
161 * Switches the operands of the call to a call to the calculate()
162 * on an AtomicMathematician such that the left operand becomes the right, and
163 * vice versa.
164 *
165 * Its constructor takes an AtomicMathematician instance which this OperandSwitcherMathematician
166 * should act as as a middle-man for, having the role of switching the two operands. Thus,
167 * OperandSwitcherMathematician can be described as a proxy or delegator class.
168 *
169 * This class is used for implementing operator combinations such as
170 * <tt>numeric * xs:yearMonthDuration</tt> and
171 * <tt>xs:yearMonthDuration * numeric</tt>.
172 *
173 * @ingroup Patternist_xdm
174 * @author Frans Englich <frans.englich@nokia.com>
175 */
176 class OperandSwitcherMathematician : public AtomicMathematician
177 {
178 public:
179 /**
180 * Creates an OperandSwitcherMathematician.
181 *
182 * @param mathematician the AtomicMathematician this OperandSwitcherMathematician
183 * should switch the operands for. Must be a non @c null, valid pointer.
184 */
185 OperandSwitcherMathematician(const AtomicMathematician::Ptr &mathematician);
186
187 /**
188 * Switch @p o1 and @p o2, and returns the value from the AtomicMathematician
189 * this OperandSwitcherMathematician represents.
190 */
191 virtual Item calculate(const Item &o1,
192 const Operator op,
193 const Item &o2,
194 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
195 private:
196 const AtomicMathematician::Ptr m_mather;
197 };
198
199 /**
200 * @short Performs arithmetics between an AbstractDateTime value and
201 * an AbstractDuration value.
202 *
203 * @ingroup Patternist_xdm
204 * @author Frans Englich <frans.englich@nokia.com>
205 */
206 class DateTimeDurationMathematician : public AtomicMathematician
207 , public DelegatingSourceLocationReflection
208 {
209 public:
210
211 inline DateTimeDurationMathematician(const SourceLocationReflection *const r) : DelegatingSourceLocationReflection(r)
212 {
213 }
214
215 /**
216 * @p o1 is an AbstractDateTime and @p o2 is an AbstractDuration.
217 *
218 */
219 virtual Item calculate(const Item &o1,
220 const Operator op,
221 const Item &o2,
222 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
223 };
224
225 /**
226 * @short Performs arithmetics between two AbstractDateTime values.
227 *
228 * @ingroup Patternist_xdm
229 * @author Frans Englich <frans.englich@nokia.com>
230 */
231 class AbstractDateTimeMathematician : public AtomicMathematician
232 {
233 public:
234 virtual Item calculate(const Item &o1,
235 const Operator op,
236 const Item &o2,
237 const QExplicitlySharedDataPointer<DynamicContext> &context) const;
238 };
239}
240
241QT_END_NAMESPACE
242
243#endif
244

source code of qtxmlpatterns/src/xmlpatterns/data/qatomicmathematicians_p.h