[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Thu Oct 19 21:15:08 UTC 2006
SVN commit 597303 by arnorehn:
* Fixed marshalling of QStringLists
CCMAIL: kde-bindings at kde.org
M +4 -0 ChangeLog
M +17 -9 SmokeInvocation.cs
M +15 -17 handlers.cpp
M +2 -0 qyoto.h
--- trunk/playground/bindings/kimono/ChangeLog #597302:597303
@@ -1,5 +1,9 @@
2006-10-19 Arno Rehn <arno at arnorehn.de>
+ * Fixed marshalling of QStringLists
+
+2006-10-19 Arno Rehn <arno at arnorehn.de>
+
* Added support for marshalling C++-QStringLists to C#-ArrayLists
(not tested yet)
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #597302:597303
@@ -62,6 +62,7 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void CallSmokeMethod(int methodId, IntPtr target, IntPtr sp, int items);
+ delegate IntPtr NoArgs();
delegate IntPtr GetIntPtr(IntPtr instance);
delegate void SetIntPtr(IntPtr instance, IntPtr ptr);
delegate void FromIntPtr(IntPtr ptr);
@@ -72,6 +73,7 @@
delegate string GetStringFromIntPtr(IntPtr ptr);
delegate IntPtr OverridenMethodFn(IntPtr instance, string method);
delegate void InvokeMethodFn(IntPtr instance, IntPtr method, IntPtr args);
+ delegate void AddStringToArrayListFn (IntPtr ptr, string str);
/** Marshalling functions begin **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -85,9 +87,6 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern IntPtr StringArrayToQStringList(int length, string[] strArray);
-
- [DllImport("libqyoto", CharSet=CharSet.Ansi)]
- static extern string[] QStringListToStringArray(IntPtr ptr);
/** Marshalling functions end **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -139,12 +138,15 @@
static extern void AddInvokeMethod(InvokeMethodFn callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
- static extern IntPtr AddQStringListToArrayList(GetIntPtr callback);
+ static extern IntPtr AddConstructArrayList(NoArgs callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern IntPtr AddArrayListToQStringList(GetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddAddStringToArrayList(AddStringToArrayListFn callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern int qt_metacall(IntPtr obj, int _c, int _id, IntPtr a);
/// Extra functions for QMainWindow
@@ -306,12 +308,16 @@
return StringArrayToQStringList(s.Length, s);
}
- static IntPtr QStringListToArrayList(IntPtr ptr) {
- string[] s = QStringListToStringArray(ptr);
- ArrayList al = new ArrayList(s);
+ static IntPtr ConstructArrayList() {
+ ArrayList al = new ArrayList();
return (IntPtr) GCHandle.Alloc(al);
}
+ static void AddStringToArrayList(IntPtr ptr, string str) {
+ ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
+ al.Add(str);
+ }
+
// The key is a type name of a class which has overriden one or more
// virtual methods, and the value is a Hashtable of the smoke type
// signatures as keys retrieving a suitable MethodInfo to invoke via
@@ -585,7 +591,8 @@
static private GetIntPtr intPtrToQString = new GetIntPtr(IntPtrToQString);
static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
static private GetIntPtr arrayListToQStringList = new GetIntPtr(ArrayListToQStringList);
- static private GetIntPtr qstringListToArrayList = new GetIntPtr(QStringListToArrayList);
+ static private NoArgs constructArrayList = new NoArgs(ConstructArrayList);
+ static private AddStringToArrayListFn addStringToArrayList = new AddStringToArrayListFn(AddStringToArrayList);
static private OverridenMethodFn overridenMethod = new OverridenMethodFn(OverridenMethod);
static private InvokeMethodFn invokeMethod = new InvokeMethodFn(InvokeMethod);
@@ -609,8 +616,9 @@
AddIntPtrFromCharStar(intPtrFromString);
AddIntPtrToQString(intPtrToQString);
AddIntPtrFromQString(intPtrFromQString);
- AddQStringListToArrayList(qstringListToArrayList);
+ AddConstructArrayList(constructArrayList);
AddArrayListToQStringList(arrayListToQStringList);
+ AddAddStringToArrayList(addStringToArrayList);
AddOverridenMethod(overridenMethod);
AddInvokeMethod(invokeMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #597302:597303
@@ -30,7 +30,8 @@
static GetIntPtr IntPtrToQString;
static GetIntPtr IntPtrFromQString;
static GetIntPtr ArrayListToQStringList;
-static GetIntPtr QStringListToArrayList;
+static NoArgs ConstructArrayList;
+static AddStringToArrayListFn AddStringToArrayList;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -62,11 +63,16 @@
ArrayListToQStringList = callback;
}
-void AddQStringListToArrayList(GetIntPtr callback)
+void AddConstructArrayList(NoArgs callback)
{
- QStringListToArrayList = callback;
+ ConstructArrayList = callback;
}
+void AddAddStringToArrayList(AddStringToArrayListFn callback)
+{
+ AddStringToArrayList = callback;
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -374,25 +380,13 @@
char ** ca = (char**) StringArrayToCharStarStar(length, strArray);
for (int i = 0; i < length; i++) {
- (*result) << ca[i];
+ (*result) << QString(ca[i]);
}
return (void*) result;
}
-char **
-QStringListToStringArray(void* ptr)
-{
- QStringList * s = (QStringList*) ptr;
- char ** result = (char **) calloc(s->count(), sizeof(char *));
-
- for (int i = 0; i < s->count(); i++) {
- result[i] = strdup((*s)[i].toLatin1().constData());
- }
- return result;
}
-}
-
void
marshall_basetype(Marshall *m)
{
@@ -861,7 +855,11 @@
// }
// *(m->var()) = av;
- m->var().s_voidp = (*QStringListToArrayList)(stringlist);
+ void* al = (*ConstructArrayList)();
+ for (int i = 0; i < stringlist->count(); i++) {
+ (*AddStringToArrayList)(al, (*stringlist)[i].toLatin1().constData());
+ }
+ m->var().s_voidp = al;
if (m->cleanup()) {
delete stringlist;
--- trunk/playground/bindings/kimono/qyoto.h #597302:597303
@@ -52,6 +52,7 @@
smokeqyoto_object *value_obj_info(void * value);
void * getPointerObject(void *ptr);
+typedef void* (*NoArgs)();
typedef void* (*GetIntPtr)(void *);
typedef void (*SetIntPtr)(void *, void *);
typedef void (*FromIntPtr)(void *);
@@ -62,6 +63,7 @@
typedef void* (*CreateInstanceFn)(const char *);
typedef void (*InvokeCustomSlotFn)(void*, const char*, void*, void*);
typedef bool (*IsSmokeClassFn)(void*);
+typedef void (*AddStringToArrayListFn)(void *, const char *);
extern FromIntPtr FreeGCHandle;
More information about the Kde-bindings
mailing list