lib
function.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
|