c14d48eeceedeb9021ea53a22be3d8f27c834462
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / functions / qcomparingaggregator_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_ComparingAggregator_H
53 #define Patternist_ComparingAggregator_H
54
55 /**
56  * @file qcomparingaggregator_p.h
57  * @short Contains the implementations for the functions <tt>fn:max()</tt>, MaxFN,
58  * and <tt>fn:min()</tt>, MinFN, and the class ComparingAggregator.
59  */
60
61 #include <private/qabstractfloat_p.h>
62 #include <private/qdecimal_p.h>
63 #include <private/qcastingplatform_p.h>
64 #include <private/qcomparisonplatform_p.h>
65 #include <private/qliteral_p.h>
66 #include <private/qaggregator_p.h>
67 #include <private/quntypedatomicconverter_p.h>
68 #include <private/qpatternistlocale_p.h>
69
70 QT_BEGIN_HEADER
71
72 QT_BEGIN_NAMESPACE
73
74 namespace QPatternist
75 {
76     /**
77      * @short Base class for the implementations of the <tt>fn:min()</tt> and <tt>fn:max()</tt> function.
78      *
79      * What function that more specifically is
80      * followed, depends on how the constructor is called.
81      *
82      * @see MaxFN
83      * @see MinFN
84      * @ingroup Patternist_functions
85      * @author Frans Englich <frans.englich@nokia.com>
86      */
87     template <AtomicComparator::Operator oper, AtomicComparator::ComparisonResult result>
88     class ComparingAggregator : public Aggregator,
89                                 public ComparisonPlatform<ComparingAggregator<oper, result>,
90                                                           true, AtomicComparator::AsValueComparison,
91                                                           ReportContext::FORG0006>,
92                                 public CastingPlatform<ComparingAggregator<oper, result>, true>
93     {
94     public:
95         virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
96         virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
97                                           const SequenceType::Ptr &reqType);
98
99         inline AtomicComparator::Operator operatorID() const
100         {
101             return oper;
102         }
103
104         inline ItemType::Ptr targetType() const
105         {
106             return BuiltinTypes::xsDouble;
107         }
108
109     private:
110         inline Item applyNumericPromotion(const Item &old,
111                                                const Item &nev,
112                                                const Item &newVal) const;
113
114         using ComparisonPlatform<ComparingAggregator<oper, result>,
115                                  true,
116                                  AtomicComparator::AsValueComparison,
117                                  ReportContext::FORG0006>::comparator;
118         using ComparisonPlatform<ComparingAggregator<oper, result>,
119                                  true,
120                                  AtomicComparator::AsValueComparison,
121                                  ReportContext::FORG0006>::fetchComparator;
122         using CastingPlatform<ComparingAggregator<oper, result>, true>::cast;
123     };
124
125 #include "qcomparingaggregator_tpl_p.h"
126
127     /**
128      * @short An instantiation of ComparingAggregator suitable for <tt>fn:max()</tt>.
129      *
130      * @ingroup Patternist_functions
131      */
132     typedef ComparingAggregator<AtomicComparator::OperatorGreaterThan, AtomicComparator::GreaterThan> MaxFN;
133
134     /**
135      * @short An instantiation of ComparingAggregator suitable for <tt>fn:max()</tt>.
136      *
137      * @ingroup Patternist_functions
138      */
139     typedef ComparingAggregator<AtomicComparator::OperatorLessThan, AtomicComparator::LessThan> MinFN;
140 }
141
142 QT_END_NAMESPACE
143
144 QT_END_HEADER
145
146 #endif