src/xmlpatterns/functions/qfunctionfactory_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    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 
       
    53 #ifndef Patternist_FunctionFactory_H
       
    54 #define Patternist_FunctionFactory_H
       
    55 
       
    56 #include <QHash>
       
    57 #include <QSharedData>
       
    58 
       
    59 #include "qexpression_p.h"
       
    60 #include "qfunctionsignature_p.h"
       
    61 #include "qprimitives_p.h"
       
    62 #include "qxmlname.h"
       
    63 
       
    64 QT_BEGIN_HEADER
       
    65 
       
    66 QT_BEGIN_NAMESPACE
       
    67 
       
    68 namespace QPatternist
       
    69 {
       
    70 
       
    71     /**
       
    72      * @short An entry point for looking up and creating FunctionCall instances.
       
    73      *
       
    74      * @ingroup Patternist_functions
       
    75      * @see <a href ="http://www.w3.org/TR/xpath-functions/">XQuery 1.0
       
    76      * and XPath 2.0 Functions and Operators</a>
       
    77      * @see <a href="http://www.w3.org/TR/xpath20/#dt-function-signature">XML Path
       
    78      * Language (XPath) 2.0, Definition: Function signatures</a>
       
    79      * @author Frans Englich <frans.englich@nokia.com>
       
    80      */
       
    81     class FunctionFactory : public QSharedData
       
    82     {
       
    83     public:
       
    84 
       
    85         typedef QExplicitlySharedDataPointer<FunctionFactory> Ptr;
       
    86         typedef QList<FunctionFactory::Ptr> List;
       
    87 
       
    88         virtual ~FunctionFactory();
       
    89 
       
    90         /**
       
    91          * Creates a function call implementation.
       
    92          *
       
    93          * A FunctionFactory represents a set of functions, which it
       
    94          * is able to instantiate and to serve FunctionSignatures for. Conventionally,
       
    95          * a FunctionFactory per namespace exists.
       
    96          *
       
    97          * @note This function should not issue any error unless it is absolutely
       
    98          * confident that the error cannot be fixed in another way. For example, in
       
    99          * some cases it might be that a function is available in another FunctionFactory
       
   100          * and it would therefore be wrong to issue an error signalling that no function
       
   101          * by that @p name exists, but leave that to the callee.
       
   102          * @param name the name of the function to create. In Clark syntax, this could
       
   103          * for example be {http://www.w3.org/2005/04/xpath-functions}lower-case
       
   104          * @param arguments the function's operands
       
   105          * @param context the usual StaticContext which supplies compile time data
       
   106          * and reporting functionality.
       
   107          * @param r the SourceLocationReflection that identifies the callsite.
       
   108          * @returns an instance of Expression which is the function implementation
       
   109          * for @p name. Or, a static error was raised.
       
   110          */
       
   111         virtual Expression::Ptr createFunctionCall(const QXmlName name,
       
   112                                                    const Expression::List &arguments,
       
   113                                                    const StaticContext::Ptr &context,
       
   114                                                    const SourceLocationReflection *const r) = 0;
       
   115 
       
   116         /**
       
   117          * Determines whether a function with the name @p name and arity @p arity
       
   118          * is available. The implementation operates on the result of
       
   119          * retrieveFunctionSignature() to determine the result.
       
   120          *
       
   121          * @param np the NamePool.
       
   122          * @param name the name of the function. For example fn:string-join.
       
   123          * @param arity the number of arguments the function must have.
       
   124          */
       
   125         virtual bool isAvailable(const NamePool::Ptr &np,
       
   126                                  const QXmlName name,
       
   127                                  const xsInteger arity);
       
   128 
       
   129         virtual FunctionSignature::Hash functionSignatures() const = 0;
       
   130 
       
   131         /**
       
   132          * Determines whether this FunctionFactory contains the function signature
       
   133          * @p signature.
       
   134          *
       
   135          * The implementation uses functionSignatures().
       
   136          */
       
   137         bool hasSignature(const FunctionSignature::Ptr &signature) const;
       
   138 
       
   139     protected:
       
   140         /**
       
   141          * @short This constructor cannot be removed, because it can't be synthesized, for
       
   142          * some reason.
       
   143          */
       
   144         inline FunctionFactory()
       
   145         {
       
   146         }
       
   147 
       
   148         /**
       
   149          * This is a convenience function for sub-classes. It retrieves the
       
   150          * function signature for function with name @p name.
       
   151          *
       
   152          * According to the specifications are function signatures identified by their
       
   153          * name and arity, but currently is the arity not part of the signature.
       
   154          *
       
   155          * If no function could be found for the given name, @c null is returned.
       
   156          */
       
   157         virtual FunctionSignature::Ptr retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name) = 0;
       
   158 
       
   159     private:
       
   160         Q_DISABLE_COPY(FunctionFactory)
       
   161     };
       
   162 }
       
   163 
       
   164 QT_END_NAMESPACE
       
   165 
       
   166 QT_END_HEADER
       
   167 
       
   168 #endif