~ubuntu-branches/ubuntu/precise/kalgebra/precise-updates

« back to all changes in this revision

Viewing changes to analitza/builtinmethods.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 16:41:53 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20111216164153-ym1s7jhbqwn2ndz6
Tags: 4:4.7.90-0ubuntu2
PPA rebuild, no changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************************************************
2
 
 *  Copyright (C) 2010 by Aleix Pol <aleixpol@kde.org>                               *
3
 
 *                                                                                   *
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.                           *
8
 
 *                                                                                   *
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.                                     *
13
 
 *                                                                                   *
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
 
 *************************************************************************************/
18
 
 
19
 
#ifndef BUILTINMETHODS_H
20
 
#define BUILTINMETHODS_H
21
 
#include <QVariant>
22
 
#include "analitzaexport.h"
23
 
#include "expressiontype.h"
24
 
#include <QStringList>
25
 
 
26
 
namespace Analitza
27
 
{
28
 
 
29
 
class Expression;
30
 
class ExpressionType;
31
 
class Object;
32
 
 
33
 
class FunctionDefinition
34
 
{
35
 
        public:
36
 
                virtual ~FunctionDefinition() {}
37
 
                
38
 
                /** 
39
 
                 * Lets the user specify a function to be injected. When called it should perform whatever
40
 
                 * the function is supposed to do.
41
 
                 * 
42
 
                 * @param args: specifies the values passed as arguments.
43
 
                 * @returns the resulting expression.
44
 
                 */
45
 
                virtual Expression operator()(const QList<Expression>& args)=0;
46
 
};
47
 
 
48
 
class PointerFunctionDefinition : public FunctionDefinition
49
 
{
50
 
        public:
51
 
                typedef Expression (*func)(const QList<Expression>& args);
52
 
                
53
 
                PointerFunctionDefinition(func call);
54
 
                virtual Expression operator()(const QList<Expression>& args);
55
 
        private:
56
 
                func m_function;
57
 
};
58
 
 
59
 
class ANALITZA_EXPORT BuiltinMethods
60
 
{
61
 
        public:
62
 
                ~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);
65
 
                
66
 
                /** @returns whether it exists a builtin function named like @p id */
67
 
                bool contains(const QString& id) const { return m_functions.contains(id); }
68
 
                
69
 
                /** @returns a map that relates all functions with their specified type. */
70
 
                QMap<QString, ExpressionType> varTypes() const { return m_types; }
71
 
                
72
 
                /** @returns the builtin function identified by @p id to be called. */
73
 
                FunctionDefinition* function(const QString& id) const { return m_functions.value(id); }
74
 
                
75
 
                /** @returns a list with the name of all registered identifiers. */
76
 
                QStringList identifiers() const { return m_functions.keys(); }
77
 
        private:
78
 
                QMap<QString, ExpressionType> m_types;
79
 
                QHash<QString, FunctionDefinition*> m_functions;
80
 
};
81
 
 
82
 
}
83
 
 
84
 
#endif