function.h
1/***************************************************************************
2 * function.h
3 * This file is part of the KDE project
4 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#ifndef KROSS_API_FUNCTION_H
21#define KROSS_API_FUNCTION_H
22
23#include "../main/krossconfig.h"
24#include "object.h"
25#include "list.h"
26
27#include <tqstring.h>
28
29namespace Kross { namespace Api {
30
36 {
37 public:
38
44
45 };
46
57 template<class INSTANCE>
58 class Function0 : public Function
59 {
60 private:
61 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr);
62 INSTANCE* m_instance;
63 Method m_method;
64 public:
65 Function0(INSTANCE* instance, Method method)
66 : m_instance(instance), m_method(method) {}
68 { return (m_instance->*m_method)(args); }
69 };
70
95 template<class INSTANCE, typename P1>
96 class Function1 : public Function
97 {
98 private:
99 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1);
100 INSTANCE* m_instance;
101 Method m_method;
102 P1 m_p1;
103 public:
104 Function1(INSTANCE* instance, Method method, P1 p1)
105 : m_instance(instance), m_method(method), m_p1(p1) {}
107 { return (m_instance->*m_method)(args, m_p1); }
108 };
109
113 template<class INSTANCE, typename P1, typename P2>
114 class Function2 : public Function
115 {
116 private:
117 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1, P2);
118 INSTANCE* m_instance;
119 Method m_method;
120 P1 m_p1;
121 P2 m_p2;
122 public:
123 Function2(INSTANCE* instance, Method method, P1 p1, P2 p2)
124 : m_instance(instance), m_method(method), m_p1(p1), m_p2(p2) {}
126 { return (m_instance->*m_method)(args, m_p1, m_p2); }
127 };
128
129}}
130
131#endif
132
This class implements the most abstract way to work with functions.
Definition function.h:59
Object::Ptr call(List::Ptr args)
Each function needs to implement the call-method which will be executed if the function itself should...
Definition function.h:67
Specialization of the Function0 which takes as additional parameter a const-value.
Definition function.h:97
Object::Ptr call(List::Ptr args)
Each function needs to implement the call-method which will be executed if the function itself should...
Definition function.h:106
Same as Function1 but with 2 additional parameters.
Definition function.h:115
Object::Ptr call(List::Ptr args)
Each function needs to implement the call-method which will be executed if the function itself should...
Definition function.h:125
The base class for functions.
Definition function.h:36
virtual Object::Ptr call(List::Ptr)=0
Each function needs to implement the call-method which will be executed if the function itself should...
TDESharedPtr< List > Ptr
Shared pointer to implement reference-counting.
Definition list.h:44
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:57
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:31