From 9d0947a4500c6613cf4232a42ec2e7c329619b16 Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Sat, 20 Feb 2016 11:12:24 +0100 Subject: [PATCH] Added suppoer QHashIntQByteArray --- src/nimqml.nim | 2 +- src/private/dotherside.nim | 6 ++++ src/private/nimqmltypes.nim | 4 +++ src/private/qhashintbytearray.nim | 47 +++++++++++++------------------ 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/nimqml.nim b/src/nimqml.nim index 7f96ae9..9631d2d 100644 --- a/src/nimqml.nim +++ b/src/nimqml.nim @@ -21,10 +21,10 @@ include private/qapplication.nim include private/qguiapplication.nim include private/qurl.nim include private/qquickview.nim +include private/qhashintbytearray.nim #include private.nimqmltypes #var qobjectRegistry = initTable[ptr QObjectObj, bool]() #include private/qguiapplication.nim #include private/qmodelindex.nim -#include private/qhashintbytearray.nim #include private/qabstractlistmodel.nim #include private.nimqmlmacros diff --git a/src/private/dotherside.nim b/src/private/dotherside.nim index 4fe2e77..c7b0f34 100644 --- a/src/private/dotherside.nim +++ b/src/private/dotherside.nim @@ -10,6 +10,7 @@ type DosQMetaTypeArray* {.unchecked.} = array[0..0, DosQMetaType] DosQUrl* = distinct pointer DosQQuickView* = distinct pointer + DosQHashIntByteArray* = distinct pointer DosSignalDefinition* = object name*: cstring @@ -128,4 +129,9 @@ proc dos_qquickview_show(view: DosQQuickView) {.cdecl, importc.} proc dos_qquickview_source(view: DosQQuickView, filename: var cstring, length: var int) {.cdecl, importc.} proc dos_qquickview_set_source(view: DosQQuickView, filename: cstring) {.cdecl, importc.} +# QHash +proc dos_qhash_int_qbytearray_create(qHash: var DosQHashIntByteArray) {.cdecl, importc.} +proc dos_qhash_int_qbytearray_delete(qHash: DosQHashIntByteArray) {.cdecl, importc.} +proc dos_qhash_int_qbytearray_insert(qHash: DosQHashIntByteArray, key: int, value: cstring) {.cdecl, importc.} +proc dos_qhash_int_qbytearray_value(qHash: DosQHashIntByteArray, key: int, value: var cstring) {.cdecl, importc.} diff --git a/src/private/nimqmltypes.nim b/src/private/nimqmltypes.nim index 643ab37..dcd2669 100644 --- a/src/private/nimqmltypes.nim +++ b/src/private/nimqmltypes.nim @@ -23,6 +23,10 @@ type # A QQuickView vptr: DosQQuickView + QHashIntByteArray* = ref object of RootObj ## \ + # A QHash + vptr: DosQHashIntByteArray + QtItemFlag* {.pure.} = enum ## \ ## Item flags ## diff --git a/src/private/qhashintbytearray.nim b/src/private/qhashintbytearray.nim index 7a2ff9c..605c8cf 100644 --- a/src/private/qhashintbytearray.nim +++ b/src/private/qhashintbytearray.nim @@ -1,33 +1,26 @@ -proc dos_qhash_int_qbytearray_create(qHash: var RawQHashIntByteArray) {.cdecl, importc.} -proc dos_qhash_int_qbytearray_delete(qHash: RawQHashIntByteArray) {.cdecl, importc.} -proc dos_qhash_int_qbytearray_insert(qHash: RawQHashIntByteArray, key: int, value: cstring) {.cdecl, importc.} -proc dos_qhash_int_qbytearray_value(qHash: RawQHashIntByteArray, key: int, value: var cstring) {.cdecl, importc.} +proc setup*(self: var QHashIntByteArray) = + ## Setup the QHash + dos_qhash_int_qbytearray_create(self.vptr) -proc create*(qHash: var QHashIntByteArray) = - ## Create the QHash - debugMsg("QHashIntByteArray", "create") - dos_qhash_int_qbytearray_create(qHash.data) - qHash.deleted = false - -proc delete*(qHash: QHashIntByteArray) = +proc delete*(self: QHashIntByteArray) = ## Delete the QHash - if not qHash.deleted: - debugMsg("QHashIntByteArray", "delete") - dos_qhash_int_qbytearray_delete(qHash.data) - qHash.deleted = true - -proc insert*(qHash: QHashIntByteArray, key: int, value: cstring) = - ## Insert the value at the given key - dos_qhash_int_qbytearray_insert(qHash.data, key, value) - -proc value*(qHash: QHashIntByteArray, key: int): string = - ## Return the value associated at the given key - var rawString: cstring - dos_qhash_int_qbytearray_value(qHash.data, key, rawString) - result = $rawString - dos_chararray_delete(rawString) + if self.vptr.isNil: + return + debugMsg("QHashIntByteArray", "delete") + dos_qhash_int_qbytearray_delete(self.vptr) proc newQHashIntQByteArray*(): QHashIntByteArray = ## Create a new QHashIntQByteArray new(result, delete) - result.create() + result.setup() + +proc insert*(self: QHashIntByteArray, key: int, value: cstring) = + ## Insert the value at the given key + dos_qhash_int_qbytearray_insert(self.vptr, key, value) + +proc value*(self: QHashIntByteArray, key: int): string = + ## Return the value associated at the given key + var rawString: cstring + dos_qhash_int_qbytearray_value(self.vptr, key, rawString) + result = $rawString + dos_chararray_delete(rawString)