[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Tue Nov 21 19:58:53 UTC 2006
SVN commit 606786 by arnorehn:
* Marshalling ItemLists should now fully work. But we still need
many of the DEF_VALUELIST_MARSHALLER things.
CCMAIL: kde-bindings at kde.org
M +5 -0 ChangeLog
M +23 -0 SmokeInvocation.cs
M +73 -35 handlers.cpp
--- trunk/playground/bindings/kimono/ChangeLog #606785:606786
@@ -1,5 +1,10 @@
2006-10-23 Arno Rehn <arno at arnorehn.de>
+ * Marshalling ItemLists should now fully work. But we still need
+ many of the DEF_VALUELIST_MARSHALLER things.
+
+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.
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #606785:606786
@@ -88,7 +88,16 @@
static extern IntPtr StringArrayToQStringList(int length, string[] strArray);
/** Marshalling functions end **/
+ /** Other functions **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr ConstructPointerList();
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddObjectToPointerList(IntPtr ptr, IntPtr obj);
+ /** Other functions end **/
+
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddFreeGCHandle(FromIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -143,6 +152,9 @@
static extern IntPtr AddArrayListToQStringList(GetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr AddArrayListToPointerList(GetIntPtr callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddAddIntPtrToArrayList(SetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -293,6 +305,15 @@
return StringArrayToQStringList(s.Length, s);
}
+ static IntPtr ArrayListToPointerList(IntPtr ptr) {
+ ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
+ IntPtr list = ConstructPointerList();
+ foreach (object o in al) {
+ AddObjectToPointerList(list, (IntPtr) GCHandle.Alloc(o));
+ }
+ return list;
+ }
+
static IntPtr ConstructArrayList() {
ArrayList al = new ArrayList();
return (IntPtr) GCHandle.Alloc(al);
@@ -577,6 +598,7 @@
static private GetIntPtr intPtrToQString = new GetIntPtr(IntPtrToQString);
static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
static private GetIntPtr arrayListToQStringList = new GetIntPtr(ArrayListToQStringList);
+ static private GetIntPtr arrayListToPointerList = new GetIntPtr(ArrayListToPointerList);
static private NoArgs constructArrayList = new NoArgs(ConstructArrayList);
static private SetIntPtr addIntPtrToArrayList = new SetIntPtr(AddIntPtrToArrayList);
@@ -604,6 +626,7 @@
AddIntPtrFromQString(intPtrFromQString);
AddConstructArrayList(constructArrayList);
AddArrayListToQStringList(arrayListToQStringList);
+ AddArrayListToPointerList(arrayListToPointerList);
AddAddIntPtrToArrayList(addIntPtrToArrayList);
AddOverridenMethod(overridenMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #606785:606786
@@ -30,6 +30,7 @@
static GetIntPtr IntPtrToQString;
static GetIntPtr IntPtrFromQString;
static GetIntPtr ArrayListToQStringList;
+static GetIntPtr ArrayListToPointerList;
static NoArgs ConstructArrayList;
static SetIntPtr AddIntPtrToArrayList;
@@ -63,6 +64,11 @@
ArrayListToQStringList = callback;
}
+void AddArrayListToPointerList(GetIntPtr callback)
+{
+ ArrayListToPointerList = callback;
+}
+
void AddConstructArrayList(NoArgs callback)
{
ConstructArrayList = callback;
@@ -73,6 +79,18 @@
AddIntPtrToArrayList = callback;
}
+void* ConstructPointerList()
+{
+ void * list = (void*) new QList<void*>;
+ return list;
+}
+
+void AddObjectToPointerList(void* ptr, void* obj)
+{
+ QList<void*> * list = (QList<void*>*) ptr;
+ list->append(obj);
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -285,6 +303,39 @@
return smoke->binding->className(classId);
}
+/*static bool
+isPrimitive(const char* type) {
+ if (type == "void") {
+ return true;
+ } else if (type == "bool") {
+ return true;
+ } else if (type == "int") {
+ return true;
+ } else if (type == "long") {
+ return true;
+ } else if (type == "uint") {
+ return true;
+ } else if (type == "ulong") {
+ return true;
+ } else if (type == "short") {
+ return true;
+ } else if (type == "ushort") {
+ return true;
+ } else if (type == "byte") {
+ return true;
+ } else if (type == "sbyte") {
+ return true;
+ } else if (type == "double") {
+ return true;
+ } else if (type == "float") {
+ return true;
+ } else if (type == "char") {
+ return true;
+ }
+
+ return false;
+}*/
+
bool
matches_arg(Smoke *smoke, Smoke::Index meth, Smoke::Index argidx, const char *argtype)
{
@@ -874,42 +925,24 @@
switch(m->action()) {
case Marshall::FromObject:
{
-// VALUE list = *(m->var());
-// if (TYPE(list) != T_ARRAY) {
- m->item().s_voidp = 0;
-// break;
-// }
-// int count = RARRAY(list)->len;
- int count = 0;
ItemList *cpplist = new ItemList;
- long i;
- for(i = 0; i < count; i++) {
-// VALUE item = rb_ary_entry(list, i);
- // TODO do type checking!
- smokeqyoto_object *o = value_obj_info(0);
- if(!o || !o->ptr)
- continue;
+ QList<void*>* list = (QList<void*>*) (*ArrayListToPointerList)(m->var().s_voidp);
+
+ for (int i; i < list->size(); ++i) {
+ smokeqyoto_object * o = value_obj_info(list->at(i));
- void *ptr = o->ptr;
+ void* ptr = o->ptr;
ptr = o->smoke->cast(
- ptr, // pointer
- o->classId, // from
- o->smoke->idClass(ItemSTR) // to
+ ptr, // pointer
+ o->classId, // from
+ o->smoke->idClass(ItemSTR) // to
);
- cpplist->append(*(Item*)ptr);
+
+ cpplist->append((Item*) ptr);
}
-
+
m->item().s_voidp = cpplist;
- m->next();
-
- if (!m->type().isConst()) {
-// rb_ary_clear(list);
- for(int i=0; i < cpplist->size(); ++i) {
-// VALUE obj = getPointerObject((void*)&(cpplist->at(i)));
-// rb_ary_push(list, obj);
- }
- }
-
+
if (m->cleanup()) {
delete cpplist;
}
@@ -925,20 +958,25 @@
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
+ //qDebug("original: %s\nmodified: %s", ItemSTR, className);
+ ///
+ /// Do we have a case where there is a QList with a primitve list type? I think not, so commented out.
+ ///
+// bool primitive = isPrimitive(ItemSTR);
+
void * al = (*ConstructArrayList)();
for (int i=0; i < valuelist->size() ; ++i) {
void *p = (void *) &(valuelist->at(i));
- if (isPrimitive == false) { // No primitive, so we have a Qt object
+// if (primitive == 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);
- }
+// } else { // We have a primitive, so add the pointer directly. Not tested, does this work?
+// (*AddIntPtrToArrayList)(al, p);
+// }
}
m->var().s_voidp = al;
More information about the Kde-bindings
mailing list