8f23712b00124b2b012f00b488e6ec9a5eda45ab
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / functions / qdatetimefns_p.h
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 //
43 //  W A R N I N G
44 //  -------------
45 //
46 // This file is not part of the Qt API.  It exists purely as an
47 // implementation detail.  This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51
52 #ifndef Patternist_DateTimeFNs_H
53 #define Patternist_DateTimeFNs_H
54
55 #include <private/qatomiccomparator_p.h>
56 #include <private/qcommonvalues_p.h>
57 #include <private/qschemadatetime_p.h>
58 #include <private/qdaytimeduration_p.h>
59 #include <private/qdecimal_p.h>
60 #include <private/qinteger_p.h>
61 #include <private/qfunctioncall_p.h>
62
63 /**
64  * @file
65  * @short Contains classes implementing the functions found in
66  * <a href="http://www.w3.org/TR/xpath-functions/#component-exraction-functions">XQuery 1.0 and
67  * XPath 2.0 Functions and Operators, 10.5 Component Extraction Functions on Durations, Dates and Times</a>.
68  *
69  * @ingroup Patternist_functions
70  */
71
72 QT_BEGIN_HEADER
73
74 QT_BEGIN_NAMESPACE
75
76 namespace QPatternist
77 {
78     /**
79      * @short Helper class for implementing functions extracting components from durations.
80      *
81      * Each sub-class must implement this function:
82      *
83      * @code
84      * Item extract(const AbstractDuration *const duration) const;
85      * @endcode
86      *
87      * This function performs the actual component extraction from the argument, that
88      * is guaranteed to never be @c null.
89      *
90      * @ingroup Patternist_functions
91      * @author Frans Englich <frans.englich@nokia.com>
92      */
93     template<typename TSubClass>
94     class ExtractFromDurationFN : public FunctionCall
95     {
96     public:
97         /**
98          * Takes care of the argument handling, and, if applicable,
99          * calls extract() with the value of the operand.
100          */
101         virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
102     };
103
104     /**
105      * @short Implements the function <tt>fn:years-from-duration()</tt>.
106      *
107      * @ingroup Patternist_functions
108      * @author Frans Englich <frans.englich@nokia.com>
109      */
110     class YearsFromDurationFN : public ExtractFromDurationFN<YearsFromDurationFN>
111     {
112     public:
113         inline Item extract(const AbstractDuration *const duration) const;
114     };
115
116     /**
117      * @short Implements the function <tt>fn:months-from-duration()</tt>.
118      *
119      * @ingroup Patternist_functions
120      * @author Frans Englich <frans.englich@nokia.com>
121      */
122     class MonthsFromDurationFN : public ExtractFromDurationFN<MonthsFromDurationFN>
123     {
124     public:
125         inline Item extract(const AbstractDuration *const duration) const;
126     };
127
128     /**
129      * @short Implements the function <tt>fn:days-from-duration()</tt>.
130      *
131      * @ingroup Patternist_functions
132      * @author Frans Englich <frans.englich@nokia.com>
133      */
134     class DaysFromDurationFN : public ExtractFromDurationFN<DaysFromDurationFN>
135     {
136     public:
137         inline Item extract(const AbstractDuration *const duration) const;
138     };
139
140     /**
141      * @short Implements the function <tt>fn:hours-from-duration()</tt>.
142      *
143      * @ingroup Patternist_functions
144      * @author Frans Englich <frans.englich@nokia.com>
145      */
146     class HoursFromDurationFN : public ExtractFromDurationFN<HoursFromDurationFN>
147     {
148     public:
149         inline Item extract(const AbstractDuration *const duration) const;
150     };
151
152     /**
153      * @short Implements the function <tt>fn:minutes-from-duration()</tt>.
154      *
155      * @ingroup Patternist_functions
156      * @author Frans Englich <frans.englich@nokia.com>
157      */
158     class MinutesFromDurationFN : public ExtractFromDurationFN<MinutesFromDurationFN>
159     {
160     public:
161         inline Item extract(const AbstractDuration *const duration) const;
162     };
163
164     /**
165      * @short Implements the function <tt>fn:seconds-from-duration()</tt>.
166      *
167      * @ingroup Patternist_functions
168      * @author Frans Englich <frans.englich@nokia.com>
169      */
170     class SecondsFromDurationFN : public ExtractFromDurationFN<SecondsFromDurationFN>
171     {
172     public:
173         inline Item extract(const AbstractDuration *const duration) const;
174     };
175
176     /**
177      * @short Helper class for implementing functions extracting components
178      * from date/time values.
179      *
180      * Each sub-class must implement this function:
181      *
182      * @code
183      * Item extract(const AbstractDuration *const duration) const;
184      * @endcode
185      *
186      * This function performs the actual component extraction from the argument, that
187      * is guaranteed to never be @c null.
188      *
189      * @ingroup Patternist_functions
190      * @author Frans Englich <frans.englich@nokia.com>
191      */
192     template<typename TSubClass>
193     class ExtractFromDateTimeFN : public FunctionCall
194     {
195     public:
196         /**
197          * Takes care of the argument handling, and, if applicable,
198          * calls extract() with the value of the operand.
199          */
200         virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
201     };
202
203     /**
204      * @short Extracts the year property from a sub-class of AbstractDateTime such as DateTime or Date.
205      * This function implements <tt>fn:year-from-dateTime()</tt> and <tt>fn:year-from-date()</tt>.
206      *
207      * @ingroup Patternist_functions
208      * @author Frans Englich <frans.englich@nokia.com>
209      */
210     class YearFromAbstractDateTimeFN : public ExtractFromDateTimeFN<YearFromAbstractDateTimeFN>
211     {
212     public:
213         inline Item extract(const QDateTime &dt) const;
214     };
215
216     /**
217      * @short Extracts the day property from a sub-class of AbstractDateTime such as DateTime or Date.
218      * This function implements <tt>fn:day-from-dateTime()</tt> and <tt>fn:day-from-date()</tt>.
219      *
220      * @ingroup Patternist_functions
221      * @author Frans Englich <frans.englich@nokia.com>
222      */
223     class DayFromAbstractDateTimeFN : public ExtractFromDateTimeFN<DayFromAbstractDateTimeFN>
224     {
225     public:
226         inline Item extract(const QDateTime &dt) const;
227     };
228
229     /**
230      * @short Extracts the minute property from a sub-class of AbstractDateTime such as DateTime or SchemaTime.
231      * Implements the functions <tt>fn:hours-from-dateTime()</tt> and
232      * <tt>fn:hours-from-time()</tt>.
233      *
234      * @ingroup Patternist_functions
235      * @author Frans Englich <frans.englich@nokia.com>
236      */
237     class HoursFromAbstractDateTimeFN : public ExtractFromDateTimeFN<HoursFromAbstractDateTimeFN>
238     {
239     public:
240         inline Item extract(const QDateTime &dt) const;
241     };
242
243     /**
244      * @short Extracts the minutes property from a sub-class of AbstractDateTime such as DateTime or Date.
245      * Implements the functions <tt>fn:minutes-from-dateTime()</tt> and
246      * <tt>fn:minutes-from-time()</tt>.
247      *
248      * @ingroup Patternist_functions
249      * @author Frans Englich <frans.englich@nokia.com>
250      */
251     class MinutesFromAbstractDateTimeFN : public ExtractFromDateTimeFN<MinutesFromAbstractDateTimeFN>
252     {
253     public:
254         inline Item extract(const QDateTime &dt) const;
255     };
256
257     /**
258      * @short Extracts the seconds property from a sub-class of AbstractDateTime such as DateTime or Date.
259      * Implements the functions <tt>fn:seconds-from-dateTime()</tt> and
260      * <tt>fn:seconds-from-time()</tt>.
261      *
262      * @ingroup Patternist_functions
263      * @author Frans Englich <frans.englich@nokia.com>
264      */
265     class SecondsFromAbstractDateTimeFN : public ExtractFromDateTimeFN<SecondsFromAbstractDateTimeFN>
266     {
267     public:
268         inline Item extract(const QDateTime &dt) const;
269     };
270
271     /**
272      * @short Extracts the timezone property from a sub-class of AbstractDateTime such as DateTime or Date.
273      * Implements the functions <tt>fn:timezone-from-dateTime()</tt>,
274      * <tt>fn:timezone-from-time()</tt> and <tt>fn:timezone-from-date()</tt>.
275      *
276      * @ingroup Patternist_functions
277      * @author Frans Englich <frans.englich@nokia.com>
278      */
279     class TimezoneFromAbstractDateTimeFN : public ExtractFromDateTimeFN<TimezoneFromAbstractDateTimeFN>
280     {
281     public:
282         inline Item extract(const QDateTime &dt) const;
283     };
284
285     /**
286      * @short implements the functions <tt>fn:month-from-dateTime()</tt> and <tt>fn:month-from-date()</tt>.
287      *
288      * @ingroup Patternist_functions
289      * @author Frans Englich <frans.englich@nokia.com>
290      */
291     class MonthFromAbstractDateTimeFN : public ExtractFromDateTimeFN<MonthFromAbstractDateTimeFN>
292     {
293     public:
294         inline Item extract(const QDateTime &dt) const;
295     };
296
297 #include "qdatetimefns_tpl_p.h"
298
299 }
300
301 QT_END_NAMESPACE
302
303 QT_END_HEADER
304
305 #endif