/src/xmlpatterns/functions/qfunctionfactorycollection.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 138 lines · 71 code · 21 blank · 46 comment · 10 complexity · d42eb0245d1759ada8feb7f3b5283371 MD5 · raw file

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