[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Sat Dec 2 11:30:58 UTC 2006
SVN commit 609812 by arnorehn:
* Added marshalling function for QList<int>
CCMAIL: kde-bindings at kde.org
M +4 -0 ChangeLog
M +31 -0 SmokeInvocation.cs
M +72 -14 handlers.cpp
M +1 -0 qyoto.h
--- trunk/playground/bindings/kimono/ChangeLog #609811:609812
@@ -1,3 +1,7 @@
+2006-12-02 Arno Rehn <arno at arnorehn.de>
+
+ * Added marshalling function for QList<int>
+
2006-11-26 Arno Rehn <arno at arnorehn.de>
* Added marshall_ItemList and all DEF_LIST_MARSHALLER and
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #609811:609812
@@ -73,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 AddInt(IntPtr obj, int i);
/** Marshalling functions begin **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -94,6 +95,12 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddObjectToPointerList(IntPtr ptr, IntPtr obj);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr ConstructQListInt();
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddIntToQList(IntPtr ptr, int i);
/** Other functions end **/
@@ -155,9 +162,15 @@
static extern IntPtr AddArrayListToPointerList(GetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr AddArrayListToQListInt(GetIntPtr callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddAddIntPtrToArrayList(SetIntPtr callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddAddIntToArrayList(AddInt callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern int qt_metacall(IntPtr obj, int _c, int _id, IntPtr a);
static void FreeGCHandle(IntPtr handle) {
@@ -305,6 +318,15 @@
return StringArrayToQStringList(s.Length, s);
}
+ static IntPtr ArrayListToQListInt(IntPtr ptr) {
+ ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
+ IntPtr QList = ConstructQListInt();
+ foreach (int i in al) {
+ AddIntToQList(QList, i);
+ }
+ return QList;
+ }
+
static IntPtr ArrayListToPointerList(IntPtr ptr) {
ArrayList al = (ArrayList) ((GCHandle) ptr).Target;
IntPtr list = ConstructPointerList();
@@ -325,6 +347,11 @@
al.Add(o);
}
+ static void AddIntToArrayList(IntPtr obj, int i) {
+ ArrayList al = (ArrayList) ((GCHandle) obj).Target;
+ al.Add(i);
+ }
+
// 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
@@ -599,8 +626,10 @@
static private GetIntPtr intPtrFromQString = new GetIntPtr(IntPtrFromQString);
static private GetIntPtr arrayListToQStringList = new GetIntPtr(ArrayListToQStringList);
static private GetIntPtr arrayListToPointerList = new GetIntPtr(ArrayListToPointerList);
+ static private GetIntPtr arrayListToQListInt = new GetIntPtr(ArrayListToQListInt);
static private NoArgs constructArrayList = new NoArgs(ConstructArrayList);
static private SetIntPtr addIntPtrToArrayList = new SetIntPtr(AddIntPtrToArrayList);
+ static private AddInt addIntToArrayList = new AddInt(AddIntToArrayList);
static private OverridenMethodFn overridenMethod = new OverridenMethodFn(OverridenMethod);
static private InvokeMethodFn invokeMethod = new InvokeMethodFn(InvokeMethod);
@@ -627,7 +656,9 @@
AddConstructArrayList(constructArrayList);
AddArrayListToQStringList(arrayListToQStringList);
AddArrayListToPointerList(arrayListToPointerList);
+ AddArrayListToQListInt(arrayListToQListInt);
AddAddIntPtrToArrayList(addIntPtrToArrayList);
+ AddAddIntToArrayList(addIntToArrayList);
AddOverridenMethod(overridenMethod);
AddInvokeMethod(invokeMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #609811:609812
@@ -66,8 +66,10 @@
static GetIntPtr IntPtrFromQString;
static GetIntPtr ArrayListToQStringList;
static GetIntPtr ArrayListToPointerList;
+static GetIntPtr ArrayListToQListInt;
static NoArgs ConstructArrayList;
static SetIntPtr AddIntPtrToArrayList;
+static AddInt AddIntToArrayList;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -104,6 +106,11 @@
ArrayListToPointerList = callback;
}
+void AddArrayListToQListInt(GetIntPtr callback)
+{
+ ArrayListToQListInt = callback;
+}
+
void AddConstructArrayList(NoArgs callback)
{
ConstructArrayList = callback;
@@ -114,6 +121,11 @@
AddIntPtrToArrayList = callback;
}
+void AddAddIntToArrayList(AddInt callback)
+{
+ AddIntToArrayList = callback;
+}
+
void* ConstructPointerList()
{
void * list = (void*) new QList<void*>;
@@ -126,6 +138,18 @@
list->append(obj);
}
+void* ConstructQListInt()
+{
+ void* list = (void*) new QList<int>;
+ return list;
+}
+
+void AddIntToQList(void* ptr, int i)
+{
+ QList<int>* list = (QList<int>*) ptr;
+ list->append(i);
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -1021,6 +1045,49 @@
}
}
+void marshall_QListInt(Marshall *m) {
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ void* list = m->var().s_voidp;
+ void* valuelist = (*ArrayListToQListInt)(list);
+ m->item().s_voidp = valuelist;
+ m->next();
+
+ /*if (m->cleanup()) {
+ delete valuelist;
+ }*/
+ }
+ break;
+ case Marshall::ToObject:
+ {
+ QList<int> *valuelist = (QList<int>*)m->item().s_voidp;
+ if(!valuelist) {
+ m->var().s_voidp = 0;
+ break;
+ }
+
+ void* av = (*ConstructArrayList)();
+
+ for (QList<int>::iterator i = valuelist->begin(); i != valuelist->end(); ++i )
+ {
+ (*AddIntToArrayList)(av, (int) *i);
+ }
+
+ m->var().s_voidp = av;
+ m->next();
+
+ if (m->cleanup()) {
+ delete valuelist;
+ }
+ }
+ break;
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
#define DEF_LIST_MARSHALLER(ListIdent,ItemList,Item) namespace { char ListIdent##STR[] = #Item; }; \
Marshall::HandlerFn marshall_##ListIdent = marshall_ItemList<Item,ItemList,ListIdent##STR>;
@@ -1078,25 +1145,14 @@
int ix = m->smoke()->idClass(ItemSTR);
const char * className = m->smoke()->binding->className(ix);
- //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 (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);
-// }
+ smokeqyoto_object * o = alloc_smokeqyoto_object(false, m->smoke(), ix, p);
+ void * obj = set_obj_info(className, o);
+ (*AddIntPtrToArrayList)(al, obj);
}
m->var().s_voidp = al;
@@ -1157,6 +1213,8 @@
{ "QStringList&", marshall_QStringList },
{ "QStringList*", marshall_QStringList },
// { "void**", marshall_voidP_array },
+ { "QList<int>", marshall_QListInt },
+ { "QList<int>&", marshall_QListInt },
{ "QList<QTableWidgetSelectionRange>", marshall_QTableWidgetSelectionRangeList },
{ "QList<QTextLayout::FormatRange>", marshall_QTextLayoutFormatRangeList },
{ "QList<QTextLayout::FormatRange>&", marshall_QTextLayoutFormatRangeList },
--- trunk/playground/bindings/kimono/qyoto.h #609811:609812
@@ -70,6 +70,7 @@
typedef void* (*CreateInstanceFn)(const char *);
typedef void (*InvokeCustomSlotFn)(void*, const char*, void*, void*);
typedef bool (*IsSmokeClassFn)(void*);
+typedef void (*AddInt)(void*, int);
extern FromIntPtr FreeGCHandle;
More information about the Kde-bindings
mailing list