[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Sun Nov 5 16:49:05 UTC 2006
SVN commit 602291 by arnorehn:
* Added more code for marshalling QLists. QList<T> return types
should now work for all QLists where T is not a primitive type.
CCMAIL: kde-bindings at kde.org
M +5 -0 ChangeLog
M +7 -7 SmokeInvocation.cs
M +17 -20 handlers.cpp
M +0 -1 qyoto.h
--- trunk/playground/bindings/kimono/ChangeLog #602290:602291
@@ -1,3 +1,8 @@
+2006-10-23 Arno Rehn <arno at arnorehn.de>
+
+ * Added more code for marshalling QLists. QList<T> return types
+ should now work for all QLists where T is not a primitive type.
+
2006-10-23 Richard Dale <rdale at foton.es>
* When a QMetaObject was constructed, the parent was wrongly being
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #602290:602291
@@ -73,7 +73,6 @@
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)]
@@ -144,7 +143,7 @@
static extern IntPtr AddArrayListToQStringList(GetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
- static extern void AddAddStringToArrayList(AddStringToArrayListFn callback);
+ static extern void AddAddIntPtrToArrayList(SetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern int qt_metacall(IntPtr obj, int _c, int _id, IntPtr a);
@@ -299,9 +298,10 @@
return (IntPtr) GCHandle.Alloc(al);
}
- static void AddStringToArrayList(IntPtr ptr, string str) {
- ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
- al.Add(str);
+ static void AddIntPtrToArrayList(IntPtr obj, IntPtr ptr) {
+ object o = ((GCHandle) ptr).Target;
+ ArrayList al = (ArrayList) ((GCHandle) obj).Target;
+ al.Add(o);
}
// The key is a type name of a class which has overriden one or more
@@ -578,7 +578,7 @@
static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
static private GetIntPtr arrayListToQStringList = new GetIntPtr(ArrayListToQStringList);
static private NoArgs constructArrayList = new NoArgs(ConstructArrayList);
- static private AddStringToArrayListFn addStringToArrayList = new AddStringToArrayListFn(AddStringToArrayList);
+ static private SetIntPtr addIntPtrToArrayList = new SetIntPtr(AddIntPtrToArrayList);
static private OverridenMethodFn overridenMethod = new OverridenMethodFn(OverridenMethod);
static private InvokeMethodFn invokeMethod = new InvokeMethodFn(InvokeMethod);
@@ -604,7 +604,7 @@
AddIntPtrFromQString(intPtrFromQString);
AddConstructArrayList(constructArrayList);
AddArrayListToQStringList(arrayListToQStringList);
- AddAddStringToArrayList(addStringToArrayList);
+ AddAddIntPtrToArrayList(addIntPtrToArrayList);
AddOverridenMethod(overridenMethod);
AddInvokeMethod(invokeMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #602290:602291
@@ -31,7 +31,7 @@
static GetIntPtr IntPtrFromQString;
static GetIntPtr ArrayListToQStringList;
static NoArgs ConstructArrayList;
-static AddStringToArrayListFn AddStringToArrayList;
+static SetIntPtr AddIntPtrToArrayList;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -68,9 +68,9 @@
ConstructArrayList = callback;
}
-void AddAddStringToArrayList(AddStringToArrayListFn callback)
+void AddAddIntPtrToArrayList(SetIntPtr callback)
{
- AddStringToArrayList = callback;
+ AddIntPtrToArrayList = callback;
}
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
@@ -853,7 +853,7 @@
// *(m->var()) = av;
void* al = (*ConstructArrayList)();
for (int i = 0; i < stringlist->count(); i++) {
- (*AddStringToArrayList)(al, (*stringlist)[i].toLatin1().constData());
+ (*AddIntPtrToArrayList)(al, (*IntPtrFromCharStar)((char*) (*stringlist)[i].toLatin1().constData()));
}
m->var().s_voidp = al;
@@ -920,38 +920,34 @@
{
ItemList *valuelist = (ItemList*)m->item().s_voidp;
if (valuelist == 0) {
-// *(m->var()) = Qnil;
break;
}
-// VALUE av = rb_ary_new();
-
int ix = m->smoke()->idClass(ItemSTR);
const char * className = m->smoke()->binding->className(ix);
-
+ bool isPrimitive = false; // we need a method for checking if T is a primitive
+
+ void * al = (*ConstructArrayList)();
+
for (int i=0; i < valuelist->size() ; ++i) {
void *p = (void *) &(valuelist->at(i));
- if (m->item().s_voidp == 0) {
-// *(m->var()) = Qnil;
- break;
+ if (isPrimitive == false) { // No primitive, so we have a Qt object
+ smokeqyoto_object * o = alloc_smokeqyoto_object(false, m->smoke(), ix, p);
+ void * obj = set_obj_info(className, o);
+ (*AddIntPtrToArrayList)(al, obj);
+ } else { // We have a primitive, so add the pointer directly. Not tested, does this work?
+ (*AddIntPtrToArrayList)(al, p);
}
-
-// VALUE obj = getPointerObject(p);
-// if(obj == Qnil) {
- smokeqyoto_object * o = alloc_smokeqyoto_object(false, m->smoke(),o->smoke->idClass(ItemSTR), p);
-// obj = set_obj_info(className, o);
-// }
-
-// rb_ary_push(av, obj);
}
-// *(m->var()) = av;
+ m->var().s_voidp = al;
m->next();
if (m->cleanup()) {
delete valuelist;
}
+
}
break;
@@ -962,6 +958,7 @@
}
}
+
#define DEF_VALUELIST_MARSHALLER(ListIdent,ItemList,Item) namespace { char ListIdent##STR[] = #Item; }; \
Marshall::HandlerFn marshall_##ListIdent = marshall_ValueListItem<Item,ItemList,ListIdent##STR>;
--- trunk/playground/bindings/kimono/qyoto.h #602290:602291
@@ -70,7 +70,6 @@
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