[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/lib/kross
From: Sebastian Sauer <mail () dipe ! org>
Date: 2005-12-28 3:50:49
Message-ID: 1135741849.424982.15187.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 491945 by sebsauer:
Added addProxyFunction() methods to the Event class.
M +70 -6 api/event.h
M +0 -18 api/proxy.h
M +7 -7 test/testplugin.cpp
--- trunk/koffice/lib/kross/api/event.h #491944:491945
@@ -27,6 +27,8 @@
#include "list.h"
#include "exception.h"
#include "function.h"
+#include "proxy.h"
+#include "variant.h"
#include <qstring.h>
#include <qvaluelist.h>
@@ -61,6 +63,10 @@
/**
* Constructor.
+ *
+ * \param name The name this \a Event has.
+ * \param parent The \a Object that this \a Event is
+ * child of.
*/
Event(const QString& name, Object::Ptr parent)
: Callable(name, parent, ArgumentList())
@@ -91,9 +97,9 @@
* should handle calls.
* \param arglist A list of arguments for the function.
*/
+//TODO remove this method as soon as there is no code using it any longer.
void addFunction(const QString& name, FunctionPtr function, const \
ArgumentList& /*arglist*/ = ArgumentList()) {
- //FIXME arglist
m_functions.replace(name, new VarFunction0<T>(static_cast<T*>(this), \
function)); }
@@ -115,13 +121,71 @@
m_functions.replace(name, function);
}
- /**
- * Check if a function is a member of this \a Callable
- * \param name the function name
- * \return true if the function is available in this \a Callable
+ /**
+ * Template function to add a \a Kross::Api::ProxyFunction as
+ * builtin-function to this \a Event instance.
*/
- bool isAFunction(const QString & name)
+ template<class RET, class ARG1, class ARG2, class ARG3, class ARG4, \
class INSTANCE, typename METHOD> + inline void addProxyFunction(const \
QString& name, INSTANCE* instance, METHOD method) {
+ m_functions.replace(name,
+ new Kross::Api::ProxyFunction <
+ INSTANCE, METHOD,
+ RET, ARG1, ARG2, ARG3, ARG4
+ > ( instance, method ) );
+ }
+
+ /// Same as above, but with three arguments.
+ template<class RET, class ARG1, class ARG2, class ARG3, class INSTANCE, \
typename METHOD> + inline void addProxyFunction(const QString& name, \
INSTANCE* instance, METHOD method) + {
+ m_functions.replace(name,
+ new Kross::Api::ProxyFunction <
+ INSTANCE, METHOD,
+ RET, ARG1, ARG2, ARG3
+ > ( instance, method ) );
+ }
+
+ /// Same as above, but with two arguments.
+ template<class RET, class ARG1, class ARG2, class INSTANCE, typename \
METHOD> + inline void addProxyFunction(const QString& name, INSTANCE* \
instance, METHOD method) + {
+ m_functions.replace(name,
+ new Kross::Api::ProxyFunction <
+ INSTANCE, METHOD,
+ RET, ARG1, ARG2
+ > ( instance, method ) );
+ }
+
+ /// Same as above, but with one argument.
+ template<class RET, class ARG1, class INSTANCE, typename METHOD>
+ inline void addProxyFunction(const QString& name, INSTANCE* instance, \
METHOD method) + {
+ m_functions.replace(name,
+ new Kross::Api::ProxyFunction <
+ INSTANCE, METHOD,
+ RET, ARG1
+ > ( instance, method ) );
+ }
+
+ /// Same as above, but with no arguments.
+ template<class RET, class INSTANCE, typename METHOD>
+ inline void addProxyFunction(const QString& name, INSTANCE* instance, \
METHOD method) + {
+ m_functions.replace(name,
+ new Kross::Api::ProxyFunction <
+ INSTANCE, METHOD,
+ RET
+ > ( instance, method ) );
+ }
+
+ /**
+ * Check if a function is a member of this \a Callable
+ * \param name the function name
+ * \return true if the function is available in this \a Callable
+ */
+ bool isAFunction(const QString & name) const
+ {
return m_functions.contains(name);
}
--- trunk/koffice/lib/kross/api/proxy.h #491944:491945
@@ -23,8 +23,6 @@
#include "../main/krossconfig.h"
#include "object.h"
#include "list.h"
-#include "class.h"
-#include "variant.h"
#include <qstring.h>
@@ -273,22 +271,6 @@
}
};
- /**
- * The ProxyClass provides us a template-class to create a
- * \a Kross::Api::Class on the fly.
- */
- template<class INSTANCE>
- class ProxyClass : public Class< ProxyClass<INSTANCE> >
- {
- protected:
- INSTANCE* m_instance;
- public:
- typedef INSTANCE type;
- ProxyClass(const QString& classname, INSTANCE* instance)
- : Class< ProxyClass<INSTANCE> >(classname)
- , m_instance(instance) {}
- };
-
}}
#endif
--- trunk/koffice/lib/kross/test/testplugin.cpp #491944:491945
@@ -153,11 +153,11 @@
addChild( new TestPluginObject("testpluginobject1") );
// Let's wrap a whole instance and it's methodfunctions.
- Kross::Api::ProxyClass<TestObject> *proxyclass =
- new Kross::Api::ProxyClass<TestObject>("testpluginobject2", m_testobject);
- addChild(proxyclass);
+ Kross::Api::Event<TestObject> *testobjectclass =
+ new Kross::Api::Event<TestObject>("testpluginobject2", this);
+ addChild(testobjectclass);
- proxyclass->addFunction("func1",
+ testobjectclass->addFunction("func1",
new Kross::Api::ProxyFunction <
TestObject,
uint (TestObject::*)(uint),
@@ -165,7 +165,7 @@
Kross::Api::ProxyValue< Kross::Api::Variant, uint > // first argument
> ( m_testobject, &TestObject::func1 )
);
- proxyclass->addFunction("func2",
+ testobjectclass->addFunction("func2",
new Kross::Api::ProxyFunction <
TestObject,
void (TestObject::*)(QString, int),
@@ -174,7 +174,7 @@
Kross::Api::ProxyValue< Kross::Api::Variant, int > // second argument
> ( m_testobject, &TestObject::func2 )
);
- proxyclass->addFunction("func3",
+ testobjectclass->addFunction("func3",
new Kross::Api::ProxyFunction<
TestObject,
QString (TestObject::*)(QString, int),
@@ -182,7 +182,7 @@
Kross::Api::ProxyValue< Kross::Api::Variant, QString >, // first \
argument
Kross::Api::ProxyValue< Kross::Api::Variant, int > // second argument
> ( m_testobject, &TestObject::func3) );
- proxyclass->addFunction("func4",
+ testobjectclass->addFunction("func4",
new Kross::Api::ProxyFunction<
TestObject,
const QString& (TestObject::*)(const QString&, int) const,
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic