[Kde-bindings] playground/bindings/kimono
Arno Rehn
kde at arnorehn.de
Mon Dec 4 19:28:38 UTC 2006
SVN commit 610629 by arnorehn:
* Added marshallers for QMaps
CCMAIL: kde-bindings at kde.org
M +4 -0 ChangeLog
M +76 -0 SmokeInvocation.cs
M +183 -0 handlers.cpp
M +2 -0 qyoto.h
--- trunk/playground/bindings/kimono/ChangeLog #610628:610629
@@ -1,3 +1,7 @@
+2006-12-04 Arno Rehn <arno at arnorehn.de>
+
+ * Added marshallers for QMaps
+
2006-12-02 Arno Rehn <arno at arnorehn.de>
* Added marshalling function for QList<int>
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #610628:610629
@@ -74,6 +74,8 @@
delegate IntPtr OverridenMethodFn(IntPtr instance, string method);
delegate void InvokeMethodFn(IntPtr instance, IntPtr method, IntPtr args);
delegate void AddInt(IntPtr obj, int i);
+ delegate void AddIntObject(IntPtr hash, int key, IntPtr val);
+ delegate IntPtr HashToMap(IntPtr ptr, int type);
/** Marshalling functions begin **/
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -101,6 +103,19 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern void AddIntToQList(IntPtr ptr, int i);
+
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr ConstructQMap(int type);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddIntQVariantToQMap(IntPtr ptr, int i, IntPtr qv);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddQStringQStringToQMap(IntPtr ptr, string str1, string str2);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddQStringQVariantToQMap(IntPtr ptr, string str, IntPtr qv);
/** Other functions end **/
@@ -171,6 +186,18 @@
static extern void AddAddIntToArrayList(AddInt callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern IntPtr AddConstructHashtable(NoArgs callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddAddObjectObjectToHashtable(InvokeMethodFn callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddAddIntObjectToHashtable(AddIntObject callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ static extern void AddHashtableToQMap(HashToMap callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
static extern int qt_metacall(IntPtr obj, int _c, int _id, IntPtr a);
static void FreeGCHandle(IntPtr handle) {
@@ -352,6 +379,43 @@
al.Add(i);
}
+ static IntPtr ConstructHashtable() {
+ Hashtable hash = new Hashtable();
+ return (IntPtr) GCHandle.Alloc(hash);
+ }
+
+ static void AddObjectObjectToHashtable(IntPtr hash, IntPtr key, IntPtr val) {
+ Hashtable h = (Hashtable) ((GCHandle) hash).Target;
+ object k = ((GCHandle) key).Target;
+ object v = ((GCHandle) val).Target;
+ h.Add(k, v);
+ }
+
+ static void AddIntObjectToHashtable(IntPtr hash, int key, IntPtr val) {
+ Hashtable h = (Hashtable) ((GCHandle) hash).Target;
+ object v = ((GCHandle) val).Target;
+ h.Add(key, v);
+ }
+
+ static IntPtr HashtableToQMap(IntPtr hash, int type) {
+ Hashtable h = (Hashtable) ((GCHandle) hash).Target;
+ IntPtr map = ConstructQMap(type);
+
+ if (type == 0) {
+ foreach (DictionaryEntry de in h) {
+ AddIntQVariantToQMap(map, (int) de.Key, (IntPtr) GCHandle.Alloc(de.Value));
+ }
+ } else if (type == 1) {
+ foreach (DictionaryEntry de in h) {
+ AddQStringQStringToQMap(map, (string) de.Key, (string) de.Value);
+ }
+ } else if (type == 2) {
+ foreach (DictionaryEntry de in h) {
+ AddQStringQVariantToQMap(map, (string) de.Key, (IntPtr) GCHandle.Alloc(de.Value));
+ }
+ }
+ return map;
+ }
// 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
@@ -624,13 +688,20 @@
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 arrayListToPointerList = new GetIntPtr(ArrayListToPointerList);
static private GetIntPtr arrayListToQListInt = new GetIntPtr(ArrayListToQListInt);
+ static private HashToMap hashtableToQMap = new HashToMap(HashtableToQMap);
+
static private NoArgs constructArrayList = new NoArgs(ConstructArrayList);
static private SetIntPtr addIntPtrToArrayList = new SetIntPtr(AddIntPtrToArrayList);
static private AddInt addIntToArrayList = new AddInt(AddIntToArrayList);
+ static private NoArgs constructHashtable = new NoArgs(ConstructHashtable);
+ static private InvokeMethodFn addObjectObjectToHashtable = new InvokeMethodFn(AddObjectObjectToHashtable);
+ static private AddIntObject addIntObjectToHashtable = new AddIntObject(AddIntObjectToHashtable);
+
static private OverridenMethodFn overridenMethod = new OverridenMethodFn(OverridenMethod);
static private InvokeMethodFn invokeMethod = new InvokeMethodFn(InvokeMethod);
@@ -660,6 +731,11 @@
AddAddIntPtrToArrayList(addIntPtrToArrayList);
AddAddIntToArrayList(addIntToArrayList);
+ AddConstructHashtable(constructHashtable);
+ AddAddObjectObjectToHashtable(addObjectObjectToHashtable);
+ AddAddIntObjectToHashtable(addIntObjectToHashtable);
+ AddHashtableToQMap(hashtableToQMap);
+
AddOverridenMethod(overridenMethod);
AddInvokeMethod(invokeMethod);
--- trunk/playground/bindings/kimono/handlers.cpp #610628:610629
@@ -70,6 +70,10 @@
static NoArgs ConstructArrayList;
static SetIntPtr AddIntPtrToArrayList;
static AddInt AddIntToArrayList;
+static NoArgs ConstructHashtable;
+static InvokeMethodFn AddObjectObjectToHashtable;
+static AddIntObject AddIntObjectToHashtable;
+static HashToMap HashtableToQMap;
void AddIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -126,6 +130,26 @@
AddIntToArrayList = callback;
}
+void AddConstructHashtable(NoArgs callback)
+{
+ ConstructHashtable = callback;
+}
+
+void AddAddObjectObjectToHashtable(InvokeMethodFn callback)
+{
+ AddObjectObjectToHashtable = callback;
+}
+
+void AddAddIntObjectToHashtable(AddIntObject callback)
+{
+ AddIntObjectToHashtable = callback;
+}
+
+void AddHashtableToQMap(HashToMap callback)
+{
+ HashtableToQMap = callback;
+}
+
void* ConstructPointerList()
{
void * list = (void*) new QList<void*>;
@@ -150,6 +174,38 @@
list->append(i);
}
+void* ConstructQMap(int type)
+{
+ if (type == 0) {
+ return (void*) new QMap<int, QVariant>();
+ } else if (type == 1) {
+ return (void*) new QMap<QString, QString>();
+ } else if (type == 2) {
+ return (void*) new QMap<QString, QVariant>();
+ }
+ return 0;
+}
+
+void AddIntQVariantToQMap(void* ptr, int i, void* qv)
+{
+ QMap<int, QVariant>* map = (QMap<int, QVariant>*) ptr;
+ QVariant* variant = (QVariant*) value_obj_info(qv)->ptr;
+ map->insert(i, *variant);
+}
+
+void AddQStringQStringToQMap(void* ptr, char* str1, char* str2)
+{
+ QMap<QString, QString>* map = (QMap<QString, QString>*) ptr;
+ map->insert(QString(str1), QString(str2));
+}
+
+void AddQStringQVariantToQMap(void* ptr, char* str, void* qv)
+{
+ QMap<QString, QVariant>* map = (QMap<QString, QVariant>*) ptr;
+ QVariant* variant = (QVariant*) value_obj_info(qv)->ptr;
+ map->insert(QString(str), *variant);
+}
+
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
//extern void * IntPtrToCharStarStar(void * item);
};
@@ -904,6 +960,125 @@
}
}
+void marshall_QMapintQVariant(Marshall *m) {
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ QMap<int, QVariant>* map = (QMap<int, QVariant>*) (*HashtableToQMap)(m->var().s_voidp, 0);
+ m->item().s_voidp = (void*) map;
+ m->next();
+
+ if (m->cleanup()) {
+ delete map;
+ }
+ break;
+ }
+
+ case Marshall::ToObject:
+ {
+ QMap<int, QVariant>* map = (QMap<int, QVariant>*) m->item().s_voidp;
+ void* hash = (*ConstructHashtable)();
+
+ int id = m->smoke()->idClass("QVariant");
+
+ for (QMap<int, QVariant>::iterator i = map->begin(); i != map->end(); ++i) {
+ void* v = (void*) &(i.value());
+ smokeqyoto_object * vo = alloc_smokeqyoto_object(false, m->smoke(), id, v);
+ void* value = set_obj_info("Qyoto.QVariant", vo);
+ (*AddIntObjectToHashtable)(hash, i.key(), value);
+ }
+
+ m->var().s_voidp = hash;
+ m->next();
+
+ break;
+ }
+
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
+void marshall_QMapQStringQString(Marshall *m) {
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ QMap<QString, QString>* map = (QMap<QString, QString>*) (*HashtableToQMap)(m->var().s_voidp, 1);
+ m->item().s_voidp = (void*) map;
+ m->next();
+
+ if (m->cleanup()) {
+ delete map;
+ }
+ break;
+ }
+
+ case Marshall::ToObject:
+ {
+ QMap<QString, QString>* map = (QMap<QString, QString>*) m->item().s_voidp;
+ void* hash = (*ConstructHashtable)();
+
+ for (QMap<QString, QString>::iterator i = map->begin(); i != map->end(); ++i) {
+ (*AddObjectObjectToHashtable)( hash,
+ (void*) StringFromQString((void*) &(i.key())),
+ (void*) StringFromQString((void*) &(i.value())));
+ }
+
+ m->var().s_voidp = hash;
+ m->next();
+
+ break;
+ }
+
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
+void marshall_QMapQStringQVariant(Marshall *m) {
+ switch(m->action()) {
+ case Marshall::FromObject:
+ {
+ QMap<QString, QVariant>* map = (QMap<QString, QVariant>*) (*HashtableToQMap)(m->var().s_voidp, 2);
+ m->item().s_voidp = (void*) map;
+ m->next();
+
+ if (m->cleanup()) {
+ delete map;
+ }
+ break;
+ }
+
+ case Marshall::ToObject:
+ {
+ QMap<QString, QVariant>* map = (QMap<QString, QVariant>*) m->item().s_voidp;
+ void* hash = (*ConstructHashtable)();
+
+ int id = m->smoke()->idClass("QVariant");
+
+ for (QMap<QString, QVariant>::iterator i = map->begin(); i != map->end(); ++i) {
+ void* v = (void*) &(i.value());
+ smokeqyoto_object * vo = alloc_smokeqyoto_object(false, m->smoke(), id, v);
+ void* value = set_obj_info("Qyoto.QVariant", vo);
+ (*AddObjectObjectToHashtable)( hash,
+ (void*) StringFromQString((void*) &(i.key())),
+ value);
+ }
+
+ m->var().s_voidp = hash;
+ m->next();
+
+ break;
+ }
+
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
void marshall_QStringList(Marshall *m) {
switch(m->action()) {
case Marshall::FromObject:
@@ -966,6 +1141,7 @@
(*AddIntPtrToArrayList)(al, (*IntPtrFromCharStar)((char*) (*stringlist)[i].toLatin1().constData()));
}
m->var().s_voidp = al;
+ m->next();
if (m->cleanup()) {
delete stringlist;
@@ -1001,6 +1177,7 @@
}
m->item().s_voidp = cpplist;
+ m->next();
if (m->cleanup()) {
delete cpplist;
@@ -1129,6 +1306,7 @@
}
m->item().s_voidp = cpplist;
+ m->next();
if (m->cleanup()) {
delete cpplist;
@@ -1255,6 +1433,11 @@
{ "QVector<QTextFormat>&", marshall_QTextFormatVector },
{ "QVector<QTextLength>", marshall_QTextLengthVector },
{ "QVector<QTextLength>&", marshall_QTextLengthVector },
+ { "QMap<int,QVariant>", marshall_QMapintQVariant },
+ { "QMap<QString,QString>", marshall_QMapQStringQString },
+ { "QMap<QString,QString>&", marshall_QMapQStringQString },
+ { "QMap<QString,QVariant>", marshall_QMapQStringQVariant },
+ { "QMap<QString,QVariant>&", marshall_QMapQStringQVariant },
{ "QList<QTextFrame*>", marshall_QTextFrameList },
{ "QList<QAction*>", marshall_QActionList },
{ "QList<QWidget*>", marshall_QWidgetPtrList },
--- trunk/playground/bindings/kimono/qyoto.h #610628:610629
@@ -71,6 +71,8 @@
typedef void (*InvokeCustomSlotFn)(void*, const char*, void*, void*);
typedef bool (*IsSmokeClassFn)(void*);
typedef void (*AddInt)(void*, int);
+typedef void (*AddIntObject)(void*, int, void*);
+typedef void* (*HashToMap)(void*, int);
extern FromIntPtr FreeGCHandle;
More information about the Kde-bindings
mailing list