Update copyright year in license headers.
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / expr / qoptimizerblocks_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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_OptimizerBlocks_H
53 #define Patternist_OptimizerBlocks_H
54
55 #include <private/qatomiccomparator_p.h>
56 #include <private/qexpression_p.h>
57 #include <private/qoptimizerframework_p.h>
58
59 QT_BEGIN_HEADER
60
61 QT_BEGIN_NAMESPACE
62
63 namespace QPatternist
64 {
65     /**
66      * @short Identifies Expression instances by their Expression::id().
67      *
68      * @author Frans englich <frans.englich@nokia.com>
69      * @ingroup Patternist_expressions
70      */
71     class ByIDIdentifier : public ExpressionIdentifier
72     {
73     public:
74         ByIDIdentifier(const Expression::ID id);
75         virtual bool matches(const Expression::Ptr &expr) const;
76     private:
77         const Expression::ID m_id;
78     };
79
80     /**
81      * @short Identifies Expression instances based on their static type.
82      *
83      * BySequenceTypeIdentifier identifies Expression instances
84      * if their Expression::staticType() matches the requested one,
85      * regardless of whether the Expression is a particular one, such
86      * as AndExpression.
87      *
88      * For example, constructing a BySequenceTypeIdentifier while
89      * passing CommonSequenceTypes::EBV in its constructor will create
90      * a ExpressionIdentifier that returns @c true for a static type with
91      * item type <tt>xs:string</tt>, but returns @c false for a static type involving
92      * <tt>xs:date</tt>.
93      *
94      * @author Frans englich <frans.englich@nokia.com>
95      * @ingroup Patternist_expressions
96      */
97     class BySequenceTypeIdentifier : public ExpressionIdentifier
98     {
99     public:
100         BySequenceTypeIdentifier(const SequenceType::Ptr &seqType);
101
102         /**
103          * @returns @c true, if the static type of @p expr is matches
104          * the SequenceType passed in the BySequenceTypeIdentifier()
105          * constructor, otherwise @c false.
106          */
107         virtual bool matches(const Expression::Ptr &expr) const;
108
109     private:
110         const SequenceType::Ptr m_seqType;
111     };
112
113     /**
114      * @short Determines whether an Expression is a value or general comparison or both,
115      * with a certain operator.
116      *
117      * @author Frans englich <frans.englich@nokia.com>
118      * @ingroup Patternist_expressions
119      */
120     class ComparisonIdentifier : public ExpressionIdentifier
121     {
122     public:
123
124         /**
125          * @param comparatorHosts the possible parent that may have
126          * the operator. This may be Expression::IDGeneralComparison or
127          * Expression::IDValueComparison. The two values may also be OR'd,
128          * meaning any of them will do.
129          *
130          * @param op the operator that the comparator host must have. For example,
131          * if @p op is AtomicComparator::OperatorGreatorOrEqual this ComparisonIdentifier
132          * will match operator >= in the case of IDGeneralComparison and 'ge' in the
133          * case of IDValueComparison.
134          */
135         ComparisonIdentifier(const QVector<Expression::ID> comparatorHosts,
136                              const AtomicComparator::Operator op);
137
138         /**
139          * @returns @c true, if @p expr is a ValueComparison with the operator
140          * passed in ComparisonIdentifier().
141          */
142         virtual bool matches(const Expression::Ptr &expr) const;
143
144     private:
145         const QVector<Expression::ID> m_hosts;
146         const AtomicComparator::Operator m_op;
147     };
148
149     /**
150      * @short Matches numeric literals that are of type xs:integer and
151      * has a specific value.
152      *
153      * For example IntegerIdentifier(4) would match the former but
154      * not the latter operand in this expression: "4 + 5".
155      *
156      * @author Frans englich <frans.englich@nokia.com>
157      * @ingroup Patternist_expressions
158      */
159     class IntegerIdentifier : public ExpressionIdentifier
160     {
161     public:
162         IntegerIdentifier(const xsInteger num);
163         virtual bool matches(const Expression::Ptr &expr) const;
164
165     private:
166         const xsInteger m_num;
167     };
168
169     /**
170      * @short Matches boolean literals.
171      *
172      * For example BooleanIdentifier(true) would match the former but
173      * not the latter operand in this expression: "true() + false()".
174      *
175      * @author Frans englich <frans.englich@nokia.com>
176      * @ingroup Patternist_expressions
177      */
178     class BooleanIdentifier : public ExpressionIdentifier
179     {
180     public:
181         BooleanIdentifier(const bool value);
182         virtual bool matches(const Expression::Ptr &expr) const;
183
184     private:
185         const bool m_value;
186     };
187
188     /**
189      * @short Creates a particular Expression instance identified by an Expression::ID.
190      *
191      * For example, if ByIDCreator() is passed Expression::IDCountFN, create()
192      * will return CountFN instances.
193      *
194      * @author Frans englich <frans.englich@nokia.com>
195      * @ingroup Patternist_expressions
196      */
197     class ByIDCreator : public ExpressionCreator
198     {
199     public:
200         /**
201          * Creates a ByIDCreator that creates expressions
202          * of the type that @p id identifies.
203          */
204         ByIDCreator(const Expression::ID id);
205         virtual Expression::Ptr create(const Expression::List &operands,
206                                        const StaticContext::Ptr &context,
207                                        const SourceLocationReflection *const r) const;
208
209         /**
210          * Creates an expression by id @p id with the arguments @p operands.
211          */
212         static Expression::Ptr create(const Expression::ID id,
213                                       const Expression::List &operands,
214                                       const StaticContext::Ptr &context,
215                                       const SourceLocationReflection *const r);
216
217     private:
218         const Expression::ID m_id;
219     };
220 }
221
222 QT_END_NAMESPACE
223
224 QT_END_HEADER
225
226 #endif