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
51#ifndef Patternist_FunctionFactory_H
52#define Patternist_FunctionFactory_H
53
54#include <QHash>
55#include <QSharedData>
56
57#include <private/qexpression_p.h>
58#include <private/qfunctionsignature_p.h>
59#include <private/qprimitives_p.h>
60#include <QXmlName>
61
62QT_BEGIN_NAMESPACE
63
64namespace QPatternist
65{
66
67 /**
68 * @short An entry point for looking up and creating FunctionCall instances.
69 *
70 * @ingroup Patternist_functions
71 * @see <a href ="http://www.w3.org/TR/xpath-functions/">XQuery 1.0
72 * and XPath 2.0 Functions and Operators</a>
73 * @see <a href="http://www.w3.org/TR/xpath20/#dt-function-signature">XML Path
74 * Language (XPath) 2.0, Definition: Function signatures</a>
75 * @author Frans Englich <frans.englich@nokia.com>
76 */
77 class Q_AUTOTEST_EXPORT FunctionFactory : public QSharedData
78 {
79 public:
80
81 typedef QExplicitlySharedDataPointer<FunctionFactory> Ptr;
82 typedef QList<FunctionFactory::Ptr> List;
83
84 virtual ~FunctionFactory();
85
86 /**
87 * Creates a function call implementation.
88 *
89 * A FunctionFactory represents a set of functions, which it
90 * is able to instantiate and to serve FunctionSignatures for. Conventionally,
91 * a FunctionFactory per namespace exists.
92 *
93 * @note This function should not issue any error unless it is absolutely
94 * confident that the error cannot be fixed in another way. For example, in
95 * some cases it might be that a function is available in another FunctionFactory
96 * and it would therefore be wrong to issue an error signalling that no function
97 * by that @p name exists, but leave that to the callee.
98 * @param name the name of the function to create. In Clark syntax, this could
99 * for example be {http://www.w3.org/2005/04/xpath-functions}lower-case
100 * @param arguments the function's operands
101 * @param context the usual StaticContext which supplies compile time data
102 * and reporting functionality.
103 * @param r the SourceLocationReflection that identifies the callsite.
104 * @returns an instance of Expression which is the function implementation
105 * for @p name. Or, a static error was raised.
106 */
107 virtual Expression::Ptr createFunctionCall(const QXmlName name,
108 const Expression::List &arguments,
109 const StaticContext::Ptr &context,
110 const SourceLocationReflection *const r) = 0;
111
112 /**
113 * Determines whether a function with the name @p name and arity @p arity
114 * is available. The implementation operates on the result of
115 * retrieveFunctionSignature() to determine the result.
116 *
117 * @param np the NamePool.
118 * @param name the name of the function. For example fn:string-join.
119 * @param arity the number of arguments the function must have.
120 */
121 virtual bool isAvailable(const NamePool::Ptr &np,
122 const QXmlName name,
123 const xsInteger arity);
124
125 virtual FunctionSignature::Hash functionSignatures() const = 0;
126
127 /**
128 * Determines whether this FunctionFactory contains the function signature
129 * @p signature.
130 *
131 * The implementation uses functionSignatures().
132 */
133 bool hasSignature(const FunctionSignature::Ptr &signature) const;
134
135 protected:
136 /**
137 * @short This constructor cannot be removed, because it can't be synthesized, for
138 * some reason.
139 */
140 inline FunctionFactory()
141 {
142 }
143
144 /**
145 * This is a convenience function for sub-classes. It retrieves the
146 * function signature for function with name @p name.
147 *
148 * According to the specifications are function signatures identified by their
149 * name and arity, but currently is the arity not part of the signature.
150 *
151 * If no function could be found for the given name, @c null is returned.
152 */
153 virtual FunctionSignature::Ptr retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name) = 0;
154
155 private:
156 Q_DISABLE_COPY(FunctionFactory)
157 };
158}
159
160QT_END_NAMESPACE
161
162#endif
163

source code of qtxmlpatterns/src/xmlpatterns/functions/qfunctionfactory_p.h