[Kde-bindings] KDE/kdebindings/csharp/qyoto
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Tue Jul 8 08:36:02 UTC 2008
SVN commit 829350 by rdale:
* Add marshallers for QHash types such as QHash<QString, QVariant> based
on the QMap marshalling code.
CCMAIL: kde-bindings at kde.org
M +5 -0 ChangeLog
M +6 -12 src/SmokeInvocation.cs
M +48 -0 src/SmokeMarshallers.cs
M +40 -3 src/handlers.cpp
M +7 -0 src/qyoto.h
--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #829349:829350
@@ -1,3 +1,8 @@
+2008-07-08 Richard Dale <richard.j.dale at gmail.com>
+
+ * Add marshallers for QHash types such as QHash<QString, QVariant> based
+ on the QMap marshalling code.
+
2008-07-07 Arno Rehn <arno at arnorehn.de>
* Allow to call InitRuntime() multiple times to make sure every binding
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeInvocation.cs #829349:829350
@@ -425,25 +425,19 @@
}
static bool runtimeInitialized = false;
- static List<Assembly> initializedAssemblies = new List<Assembly>();
public static void InitRuntime() {
- if (!runtimeInitialized) {
- Qyoto.Init_qyoto();
- SmokeMarshallers.SetUp();
- runtimeInitialized = true;
- }
+ if (runtimeInitialized)
+ return;
+ Qyoto.Init_qyoto();
+ SmokeMarshallers.SetUp();
// initialize other referenced smoke bindings
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
- if (initializedAssemblies.Contains(a)) return;
AssemblySmokeInitializer attr = (AssemblySmokeInitializer) Attribute.GetCustomAttribute(a, typeof(AssemblySmokeInitializer));
- if (attr != null) {
- Console.WriteLine("Init {0}", a);
- attr.CallInitSmoke();
- }
- initializedAssemblies.Add(a);
+ if (attr != null) attr.CallInitSmoke();
}
+ runtimeInitialized = true;
}
static SmokeInvocation() {
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeMarshallers.cs #829349:829350
@@ -69,6 +69,18 @@
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ public static extern IntPtr ConstructQHash(int type);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ public static extern void AddIntQVariantToQHash(IntPtr ptr, int i, IntPtr qv);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ public static extern void AddQStringQStringToQHash(IntPtr ptr, string str1, string str2);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ public static extern void AddQStringQVariantToQHash(IntPtr ptr, string str, IntPtr qv);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
public static extern IntPtr ConstructQMap(int type);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -182,6 +194,9 @@
public static extern void InstallAddIntObjectToDictionary(AddIntObject callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
+ public static extern void InstallDictionaryToQHash(DictToHash callback);
+
+ [DllImport("libqyoto", CharSet=CharSet.Ansi)]
public static extern void InstallDictionaryToQMap(DictToMap callback);
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
@@ -206,6 +221,7 @@
public delegate void AddInt(IntPtr obj, int i);
public delegate void AddUInt(IntPtr obj, uint i);
public delegate void AddIntObject(IntPtr hash, int key, IntPtr val);
+ public delegate IntPtr DictToHash(IntPtr ptr, int type);
public delegate IntPtr DictToMap(IntPtr ptr, int type);
public delegate IntPtr ConstructDict(string type1, string type2);
public delegate void SetPropertyFn(IntPtr obj, string name, IntPtr variant);
@@ -692,6 +708,37 @@
d.GetType().GetMethod("Add").Invoke(d, args);
}
+ public static IntPtr DictionaryToQHash(IntPtr dict, int type) {
+ object d = ((GCHandle) dict).Target;
+ IntPtr hash = ConstructQHash(type);
+
+ if (type == 0) {
+ Dictionary<int, QVariant> d1 = (Dictionary<int, QVariant>) d;
+ foreach (KeyValuePair<int, QVariant> kvp in d1) {
+#if DEBUG
+ AddIntQVariantToQHash(hash, kvp.Key, (IntPtr) DebugGCHandle.Alloc(kvp.Value));
+#else
+ AddIntQVariantToQHash(hash, kvp.Key, (IntPtr) GCHandle.Alloc(kvp.Value));
+#endif
+ }
+ } else if (type == 1) {
+ Dictionary<string, string> d1 = (Dictionary<string, string>) d;
+ foreach (KeyValuePair<string, string> kvp in d1) {
+ AddQStringQStringToQHash(hash, kvp.Key, kvp.Value);
+ }
+ } else if (type == 2) {
+ Dictionary<string, QVariant> d1 = (Dictionary<string, QVariant>) d;
+ foreach (KeyValuePair<string, QVariant> kvp in d1) {
+#if DEBUG
+ AddQStringQVariantToQHash(hash, kvp.Key, (IntPtr) DebugGCHandle.Alloc(kvp.Value));
+#else
+ AddQStringQVariantToQHash(hash, kvp.Key, (IntPtr) GCHandle.Alloc(kvp.Value));
+#endif
+ }
+ }
+ return hash;
+ }
+
public static IntPtr DictionaryToQMap(IntPtr dict, int type) {
object d = ((GCHandle) dict).Target;
IntPtr map = ConstructQMap(type);
@@ -758,6 +805,7 @@
InstallAddObjectObjectToDictionary(AddObjectObjectToDictionary);
InstallAddIntObjectToDictionary(AddIntObjectToDictionary);
+ InstallDictionaryToQHash(DictionaryToQHash);
InstallDictionaryToQMap(DictionaryToQMap);
InstallOverridenMethod(SmokeInvocation.OverridenMethod);
--- trunk/KDE/kdebindings/csharp/qyoto/src/handlers.cpp #829349:829350
@@ -85,6 +85,10 @@
Q_DECL_EXPORT GetIntPtr ListToPointerList;
Q_DECL_EXPORT CreateListFn ConstructList;
Q_DECL_EXPORT SetIntPtr AddIntPtrToList;
+Q_DECL_EXPORT ConstructDict ConstructDictionary;
+Q_DECL_EXPORT DictToMap DictionaryToQMap;
+Q_DECL_EXPORT DictToHash DictionaryToQHash;
+Q_DECL_EXPORT InvokeMethodFn AddObjectObjectToDictionary;
static GetIntPtr IntPtrToCharStarStar;
static GetCharStarFromIntPtr IntPtrToCharStar;
@@ -99,10 +103,7 @@
static GetIntPtr ListWizardButtonToQListWizardButton;
static AddInt AddIntToListInt;
static AddUInt AddUIntToListUInt;
-static ConstructDict ConstructDictionary;
-static InvokeMethodFn AddObjectObjectToDictionary;
static AddIntObject AddIntObjectToDictionary;
-static DictToMap DictionaryToQMap;
Q_DECL_EXPORT void InstallIntPtrToCharStarStar(GetIntPtr callback)
{
@@ -184,6 +185,11 @@
AddIntObjectToDictionary = callback;
}
+Q_DECL_EXPORT void InstallDictionaryToQHash(DictToHash callback)
+{
+ DictionaryToQHash = callback;
+}
+
Q_DECL_EXPORT void InstallDictionaryToQMap(DictToMap callback)
{
DictionaryToQMap = callback;
@@ -227,7 +233,38 @@
QList<int>* list = (QList<int>*) ptr;
list->append(i);
}
+Q_DECL_EXPORT void* ConstructQHash(int type)
+{
+ if (type == 0) {
+ return (void*) new QHash<int, QVariant>();
+ } else if (type == 1) {
+ return (void*) new QHash<QString, QString>();
+ } else if (type == 2) {
+ return (void*) new QHash<QString, QVariant>();
+ }
+ return 0;
+}
+Q_DECL_EXPORT void AddIntQVariantToQHash(void* ptr, int i, void* qv)
+{
+ QHash<int, QVariant>* hash = (QHash<int, QVariant>*) ptr;
+ QVariant* variant = (QVariant*) ((smokeqyoto_object*) (*GetSmokeObject)(qv))->ptr;
+ hash->insert(i, *variant);
+}
+
+Q_DECL_EXPORT void AddQStringQStringToQHash(void* ptr, char* str1, char* str2)
+{
+ QHash<QString, QString>* hash = (QHash<QString, QString>*) ptr;
+ hash->insert(QString(str1), QString(str2));
+}
+
+Q_DECL_EXPORT void AddQStringQVariantToQHash(void* ptr, char* str, void* qv)
+{
+ QHash<QString, QVariant>* hash = (QHash<QString, QVariant>*) ptr;
+ QVariant* variant = (QVariant*) ((smokeqyoto_object*) (*GetSmokeObject)(qv))->ptr;
+ hash->insert(QString(str), *variant);
+}
+
Q_DECL_EXPORT void* ConstructQMap(int type)
{
if (type == 0) {
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.h #829349:829350
@@ -78,6 +78,7 @@
typedef void (*AddUInt)(void *, uint);
typedef void (*AddIntObject)(void *, int, void *);
typedef void * (*DictToMap)(void *, int);
+typedef void * (*DictToHash)(void *, int);
typedef void * (*ConstructDict)(const char*, const char*);
typedef void (*SetPropertyFn)(void *, const char*, void *);
@@ -139,6 +140,12 @@
extern GetIntPtr ListToPointerList;
extern CreateListFn ConstructList;
extern SetIntPtr AddIntPtrToList;
+
+extern ConstructDict ConstructDictionary;
+extern DictToHash DictionaryToQHash;
+extern DictToMap DictionaryToQMap;
+extern char *StringFromQString(void *ptr);
+extern InvokeMethodFn AddObjectObjectToDictionary;
}
#endif
More information about the Kde-bindings
mailing list