| 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 | #include "qbasictypesfactory_p.h" |
| 41 | #include "qconstructorfunctionsfactory_p.h" |
| 42 | #include "qfunctioncall_p.h" |
| 43 | #include "qxpath10corefunctions_p.h" |
| 44 | #include "qxpath20corefunctions_p.h" |
| 45 | #include "qxslt20corefunctions_p.h" |
| 46 | |
| 47 | #include "qfunctionfactorycollection_p.h" |
| 48 | |
| 49 | QT_BEGIN_NAMESPACE |
| 50 | |
| 51 | using namespace QPatternist; |
| 52 | |
| 53 | Expression::Ptr FunctionFactoryCollection::createFunctionCall(const QXmlName name, |
| 54 | const Expression::List &arguments, |
| 55 | const StaticContext::Ptr &context, |
| 56 | const SourceLocationReflection *const r) |
| 57 | { |
| 58 | const_iterator it; |
| 59 | const_iterator e(constEnd()); |
| 60 | Expression::Ptr function; |
| 61 | |
| 62 | for(it = constBegin(); it != e; ++it) |
| 63 | { |
| 64 | function = (*it)->createFunctionCall(name, arguments, context, r); |
| 65 | |
| 66 | if(function) |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | return function; |
| 71 | } |
| 72 | |
| 73 | bool FunctionFactoryCollection::isAvailable(const NamePool::Ptr &np, const QXmlName name, const xsInteger arity) |
| 74 | { |
| 75 | const_iterator it; |
| 76 | const_iterator e(constEnd()); |
| 77 | |
| 78 | for(it = constBegin(); it != e; ++it) |
| 79 | if((*it)->isAvailable(np, name, arity)) |
| 80 | return true; |
| 81 | |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | FunctionSignature::Hash FunctionFactoryCollection::functionSignatures() const |
| 86 | { |
| 87 | /* We simply grab the function signatures for each library, and |
| 88 | * put them all in one list. */ |
| 89 | |
| 90 | const const_iterator e(constEnd()); |
| 91 | FunctionSignature::Hash result; |
| 92 | |
| 93 | for(const_iterator it(constBegin()); it != e; ++it) |
| 94 | { |
| 95 | const auto &signatures = (*it)->functionSignatures(); |
| 96 | const FunctionSignature::Hash::const_iterator e2(signatures.constEnd()); |
| 97 | FunctionSignature::Hash::const_iterator sit(signatures.constBegin()); |
| 98 | |
| 99 | for(; sit != e2; ++sit) |
| 100 | result.insert(akey: sit.key(), avalue: sit.value()); |
| 101 | } |
| 102 | |
| 103 | return result; |
| 104 | } |
| 105 | |
| 106 | FunctionSignature::Ptr FunctionFactoryCollection::retrieveFunctionSignature(const NamePool::Ptr &, const QXmlName name) |
| 107 | { |
| 108 | return functionSignatures().value(akey: name); |
| 109 | } |
| 110 | |
| 111 | FunctionFactory::Ptr FunctionFactoryCollection::xpath10Factory() |
| 112 | { |
| 113 | /* We don't use a global static for caching this, because AbstractFunctionFactory |
| 114 | * stores state specific to the NamePool, when being used. */ |
| 115 | return FunctionFactory::Ptr(new XPath10CoreFunctions()); |
| 116 | } |
| 117 | |
| 118 | FunctionFactory::Ptr FunctionFactoryCollection::xpath20Factory(const NamePool::Ptr &np) |
| 119 | { |
| 120 | /* We don't use a global static for caching this, because AbstractFunctionFactory |
| 121 | * stores state specific to the NamePool, when being used. */ |
| 122 | const FunctionFactoryCollection::Ptr fact(new FunctionFactoryCollection()); |
| 123 | fact->append(t: xpath10Factory()); |
| 124 | fact->append(t: FunctionFactory::Ptr(new XPath20CoreFunctions())); |
| 125 | fact->append(t: FunctionFactory::Ptr( |
| 126 | new ConstructorFunctionsFactory(np, BasicTypesFactory::self(np)))); |
| 127 | return fact; |
| 128 | } |
| 129 | |
| 130 | FunctionFactory::Ptr FunctionFactoryCollection::xslt20Factory(const NamePool::Ptr &np) |
| 131 | { |
| 132 | const FunctionFactory::Ptr retval(xpath20Factory(np)); |
| 133 | static_cast<FunctionFactoryCollection *>(retval.data())->append(t: FunctionFactory::Ptr(new XSLT20CoreFunctions())); |
| 134 | return retval; |
| 135 | } |
| 136 | |
| 137 | QT_END_NAMESPACE |
| 138 | |