lib

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 "object.h"
24#include "list.h"
25
26#include <tqstring.h>
27
28namespace Kross { namespace Api {
29
35 {
36 public:
37
43
44 };
45
56 template<class INSTANCE>
57 class Function0 : public Function
58 {
59 private:
60 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr);
61 INSTANCE* m_instance;
62 Method m_method;
63 public:
64 Function0(INSTANCE* instance, Method method)
65 : m_instance(instance), m_method(method) {}
67 { return (m_instance->*m_method)(args); }
68 };
69
94 template<class INSTANCE, typename P1>
95 class Function1 : public Function
96 {
97 private:
98 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1);
99 INSTANCE* m_instance;
100 Method m_method;
101 P1 m_p1;
102 public:
103 Function1(INSTANCE* instance, Method method, P1 p1)
104 : m_instance(instance), m_method(method), m_p1(p1) {}
106 { return (m_instance->*m_method)(args, m_p1); }
107 };
108
112 template<class INSTANCE, typename P1, typename P2>
113 class Function2 : public Function
114 {
115 private:
116 typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1, P2);
117 INSTANCE* m_instance;
118 Method m_method;
119 P1 m_p1;
120 P2 m_p2;
121 public:
122 Function2(INSTANCE* instance, Method method, P1 p1, P2 p2)
123 : m_instance(instance), m_method(method), m_p1(p1), m_p2(p2) {}
125 { return (m_instance->*m_method)(args, m_p1, m_p2); }
126 };
127
128}}
129
130#endif
131
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:66
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:105
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:124
The base class for functions.
Definition function.h:35
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:46
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:56
The common Kross API used as common codebase.
Definition callable.h:33
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:33