1
/*************************************************************************************
2
* Copyright (C) 2010 by Aleix Pol <aleixpol@kde.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License *
6
* as published by the Free Software Foundation; either version 2 *
7
* of the License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the Free Software *
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17
*************************************************************************************/
19
#ifndef BUILTINMETHODS_H
20
#define BUILTINMETHODS_H
22
#include "analitzaexport.h"
23
#include "expressiontype.h"
24
#include <QStringList>
33
class FunctionDefinition
36
virtual ~FunctionDefinition() {}
39
* Lets the user specify a function to be injected. When called it should perform whatever
40
* the function is supposed to do.
42
* @param args: specifies the values passed as arguments.
43
* @returns the resulting expression.
45
virtual Expression operator()(const QList<Expression>& args)=0;
48
class PointerFunctionDefinition : public FunctionDefinition
51
typedef Expression (*func)(const QList<Expression>& args);
53
PointerFunctionDefinition(func call);
54
virtual Expression operator()(const QList<Expression>& args);
59
class ANALITZA_EXPORT BuiltinMethods
63
/** Adds a new function to the system identified @p id with @p type that can be called using @p f. */
64
void insertFunction(const QString& id, const ExpressionType& type, FunctionDefinition* f);
66
/** @returns whether it exists a builtin function named like @p id */
67
bool contains(const QString& id) const { return m_functions.contains(id); }
69
/** @returns a map that relates all functions with their specified type. */
70
QMap<QString, ExpressionType> varTypes() const { return m_types; }
72
/** @returns the builtin function identified by @p id to be called. */
73
FunctionDefinition* function(const QString& id) const { return m_functions.value(id); }
75
/** @returns a list with the name of all registered identifiers. */
76
QStringList identifiers() const { return m_functions.keys(); }
78
QMap<QString, ExpressionType> m_types;
79
QHash<QString, FunctionDefinition*> m_functions;