[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Thu Oct 19 17:15:54 UTC 2006
SVN commit 597228 by arnorehn:
* Added support for marshalling C++-QStringLists to C#-ArrayLists
(not tested yet)
CCMAIL: kde-bindings at kde.org
M +5 -0 ChangeLog
M +31 -1 SmokeInvocation.cs
M +53 -14 handlers.cpp
--- trunk/playground/bindings/kimono/ChangeLog #597227:597228
@@ -1,3 +1,8 @@
+2006-10-19 Arno Rehn <arno at arnorehn.de>
+
+ * Added support for marshalling C++-QStringLists to C#-ArrayLists
+ (not tested yet)
+
2006-10-19 Richard Dale <rdale at foton.es>
* Removed Qt3 Qyoto sources
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #597227:597228
@@ -73,6 +73,7 @@
delegate IntPtr OverridenMethodFn(IntPtr instance, string method);
delegate void InvokeMethodFn(IntPtr instance, IntPtr method, IntPtr args);
+ /** Marshalling functions begin **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern IntPtr StringArrayToCharStarStar(int length, string[] strArray);
@@ -81,8 +82,15 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern string StringFromQString(IntPtr ptr);
-
+
[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)]
static extern void AddFreeGCHandle(FromIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -131,6 +139,12 @@
static extern void AddInvokeMethod(InvokeMethodFn callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr AddQStringListToArrayList(GetIntPtr callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr AddArrayListToQStringList(GetIntPtr callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern int qt_metacall(IntPtr obj, int _c, int _id, IntPtr a);
/// Extra functions for QMainWindow
@@ -286,6 +300,18 @@
return (IntPtr) GCHandle.Alloc(StringFromQString(ptr));
}
+ static IntPtr ArrayListToQStringList(IntPtr ptr) {
+ ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
+ string[] s = (string[]) al.ToArray();
+ return StringArrayToQStringList(s.Length, s);
+ }
+
+ static IntPtr QStringListToArrayList(IntPtr ptr) {
+ string[] s = QStringListToStringArray(ptr);
+ ArrayList al = new ArrayList(s);
+ return (IntPtr) GCHandle.Alloc(al);
+ }
+
// 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
@@ -558,6 +584,8 @@
static private GetIntPtrFromString intPtrFromString = new GetIntPtrFromString(IntPtrFromString);
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 OverridenMethodFn overridenMethod = new OverridenMethodFn(OverridenMethod);
static private InvokeMethodFn invokeMethod = new InvokeMethodFn(InvokeMethod);
@@ -581,6 +609,8 @@
AddIntPtrFromCharStar(intPtrFromString);
AddIntPtrToQString(intPtrToQString);
AddIntPtrFromQString(intPtrFromQString);
+ AddQStringListToArrayList(qstringListToArrayList);
+ AddArrayListToQStringList(arrayListToQStringList);
AddOverridenMethod(overridenMethod);
AddInvokeMethod(invokeMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #597227:597228
@@ -29,6 +29,8 @@
static GetIntPtrFromCharStar IntPtrFromCharStar;
static GetIntPtr IntPtrToQString;
static GetIntPtr IntPtrFromQString;
+static GetIntPtr ArrayListToQStringList;
+static GetIntPtr QStringListToArrayList;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -55,6 +57,16 @@
IntPtrFromQString = callback;
}
+void AddArrayListToQStringList(GetIntPtr callback)
+{
+ ArrayListToQStringList = callback;
+}
+
+void AddQStringListToArrayList(GetIntPtr callback)
+{
+ QStringListToArrayList = callback;
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -355,8 +367,32 @@
return strdup(ba.constData());
}
+void *
+StringArrayToQStringList(int length, char ** strArray)
+{
+ QStringList * result = new QStringList();
+ char ** ca = (char**) StringArrayToCharStarStar(length, strArray);
+
+ for (int i = 0; i < length; i++) {
+ (*result) << 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)
{
@@ -779,27 +815,29 @@
// }
// int count = RARRAY(list)->len;
- int count = 0;
- QStringList *stringlist = new QStringList;
+// int count = 0;
+// QStringList *stringlist = new QStringList;
- for (long i = 0; i < count; i++) {
+// for (long i = 0; i < count; i++) {
// VALUE item = rb_ary_entry(list, i);
// if(TYPE(item) != T_STRING) {
- stringlist->append(QString());
+// stringlist->append(QString());
// continue;
// }
// stringlist->append(*(qstringFromRString(item)));
- }
-
- m->item().s_voidp = stringlist;
+// }
+
+ QStringList *stringlist = (QStringList*) (*ArrayListToQStringList)(m->var().s_voidp);
+
+ m->item().s_voidp = (void*) stringlist;
m->next();
- if (stringlist != 0 && !m->type().isConst()) {
+// if (stringlist != 0 && !m->type().isConst()) {
// rb_ary_clear(list);
- for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
+// for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
// rb_ary_push(list, rstringFromQString(&(*it)));
- }
- }
+// }
+// }
if (m->cleanup()) {
delete stringlist;
@@ -812,17 +850,18 @@
{
QStringList *stringlist = static_cast<QStringList *>(m->item().s_voidp);
if (!stringlist) {
-// *(m->var()) = Qnil;
+// m->var().s_voidp = 0;
break;
}
// VALUE av = rb_ary_new();
- for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
+// for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
// VALUE rv = rstringFromQString(&(*it));
// rb_ary_push(av, rv);
- }
+// }
// *(m->var()) = av;
+ m->var().s_voidp = (*QStringListToArrayList)(stringlist);
if (m->cleanup()) {
delete stringlist;
More information about the Kde-bindings
mailing list