File indexing completed on 2024-05-05 16:11:45

0001 /*
0002  * functions.h - Copyright 2005 Frerich Raabe <raabe@kde.org>
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  *
0014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 #ifndef FUNCTIONS_H
0026 #define FUNCTIONS_H
0027 
0028 #include "expression.h"
0029 
0030 #include <QHash>
0031 #include <QList>
0032 
0033 #include "dom/dom_string.h"
0034 #include "xml/dom_stringimpl.h"
0035 
0036 namespace khtml
0037 {
0038 namespace XPath
0039 {
0040 
0041 class Function : public Expression
0042 {
0043 public:
0044     void setArguments(const QList<Expression *> &args);
0045     void setName(const DOM::DOMString &name);
0046 
0047     QString dump() const override;
0048 
0049 protected:
0050     Expression *arg(int pos);
0051     const Expression *arg(int pos) const;
0052     unsigned int argCount() const;
0053     DOM::DOMString name() const;
0054 
0055 private:
0056     DOM::DOMString m_name;
0057 };
0058 
0059 class FunctionLibrary
0060 {
0061     friend struct FunctionMapping;
0062 public:
0063     static FunctionLibrary &self();
0064 
0065     Function *getFunction(const DOM::DOMString &name,
0066                           const QList<Expression *> &args = QList<Expression *>()) const;
0067 
0068 private:
0069     struct FunctionRec;
0070 
0071     FunctionLibrary();
0072     FunctionLibrary(const FunctionLibrary &rhs);
0073     FunctionLibrary &operator=(const FunctionLibrary &rhs);
0074 
0075     QHash<DOM::DOMString, FunctionRec> m_functionDict;
0076 };
0077 
0078 } // namespace XPath
0079 
0080 } // namespace khtml
0081 
0082 #endif // FUNCTIONS_H
0083