lib

function.h

00001 /***************************************************************************
00002  * function.h
00003  * This file is part of the KDE project
00004  * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #ifndef KROSS_API_FUNCTION_H
00021 #define KROSS_API_FUNCTION_H
00022 
00023 #include "../main/krossconfig.h"
00024 #include "object.h"
00025 #include "list.h"
00026 
00027 #include <qstring.h>
00028 
00029 namespace Kross { namespace Api {
00030 
00035     class Function
00036     {
00037         public:
00038 
00043             virtual Object::Ptr call(List::Ptr) = 0;
00044 
00045     };
00046 
00057     template<class INSTANCE>
00058     class Function0 : public Function
00059     {
00060         private:
00061             typedef Object::Ptr(INSTANCE::*Method)(List::Ptr);
00062             INSTANCE* m_instance;
00063             Method m_method;
00064         public:
00065             Function0(INSTANCE* instance, Method method)
00066                 : m_instance(instance), m_method(method) {}
00067             Object::Ptr call(List::Ptr args)
00068                 { return (m_instance->*m_method)(args); }
00069     };
00070 
00095     template<class INSTANCE, typename P1>
00096     class Function1 : public Function
00097     {
00098         private:
00099             typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1);
00100             INSTANCE* m_instance;
00101             Method m_method;
00102             P1 m_p1;
00103         public:
00104             Function1(INSTANCE* instance, Method method, P1 p1)
00105                 : m_instance(instance), m_method(method), m_p1(p1) {}
00106             Object::Ptr call(List::Ptr args)
00107                 { return (m_instance->*m_method)(args, m_p1); }
00108     };
00109 
00113     template<class INSTANCE, typename P1, typename P2>
00114     class Function2 : public Function
00115     {
00116         private:
00117             typedef Object::Ptr(INSTANCE::*Method)(List::Ptr, P1, P2);
00118             INSTANCE* m_instance;
00119             Method m_method;
00120             P1 m_p1;
00121             P2 m_p2;
00122         public:
00123             Function2(INSTANCE* instance, Method method, P1 p1, P2 p2)
00124                 : m_instance(instance), m_method(method), m_p1(p1), m_p2(p2) {}
00125             Object::Ptr call(List::Ptr args)
00126                 { return (m_instance->*m_method)(args, m_p1, m_p2); }
00127     };
00128 
00129 }}
00130 
00131 #endif
00132 
KDE Home | KDE Accessibility Home | Description of Access Keys