Support ownership transfer to non smoke wrapped QObjects & cleanup C++ to Lisp translation.
Annotate for file src/list.lisp
2010-01-10 tobias 1 (in-package :cl-smoke.qt-impl)
08:52:49 ' 2
2009-09-02 tobias 3 (defmacro define-qlist-wrapper (type-name &optional c-name)
2010-01-10 tobias 4 (let* ((c-name (or c-name type-name))
08:52:49 ' 5 (type (string-upcase c-name))
' 6 (list-type (symbolicate 'qlist- type)))
' 7 `(progn
' 8 (defcfun ,(concatenate 'string "qt_smoke_list_" c-name "_size") :int
' 9 "Returns the size of LIST."
' 10 (list :pointer))
' 11 (defcfun ,(concatenate 'string "qt_smoke_free_list_" c-name) :void
' 12 "Frees LIST."
' 13 (list :pointer))
' 14 (defcfun ,(concatenate 'string "qt_smoke_make_list_" c-name) :pointer
' 15 "Makes a list.")
' 16 (defcfun ,(concatenate 'string "qt_smoke_list_" c-name "_at") :pointer
' 17 "Returns the a newly constructed copy of the element at position AT of LIST."
' 18 (list :pointer)
' 19 (index :int))
' 20 (defcfun ,(concatenate 'string "qt_smoke_list_" c-name "_append") :pointer
' 21 "Appends NEW-ELEMENT to LIST."
' 22 (list :pointer)
' 23 (new-element :pointer))
2009-08-02 tobias 24 ;; To Lisp
2010-01-10 tobias 25 ,@(loop for type-name in (ensure-list type-name) collect
2009-08-02 tobias 26 `(defun ,(symbolicate 'from- type-name) (list-pointer)
2010-01-10 tobias 27 (let ((vector (make-array (,(symbolicate 'qt-smoke-list-
08:52:49 ' 28 type '-size)
2009-08-02 tobias 29 list-pointer))))
2010-01-10 tobias 30 (dotimes (index (length vector) vector)
08:52:49 ' 31 (setf (aref vector index)
' 32 ;; FIXME the returned object is not wrapped by Smoke
' 33 ;; -> change this?
' 34 (smoke::object-to-lisp
' 35 (,(symbolicate 'qt-smoke-list-
' 36 type '-at)
2009-08-02 tobias 37 list-pointer index)
11:15:21 ' 38 (smoke::make-smoke-type *smoke-module*
' 39 ,type-name)))))))
' 40 ,@(loop for type-name in (ensure-list type-name) collect
' 41 `(define-to-lisp-translation
' 42 (,(format nil "const QList<~A>&" type-name)
' 43 ,(format nil "QList<~A>" type-name))
' 44 ,(symbolicate 'from- type-name)
' 45 ,(symbolicate 'qt-smoke-free-list- type)))
' 46 ;; From Lisp
2010-01-10 tobias 47 (defun ,(symbolicate 'coerce- list-type) (list)
08:52:49 ' 48 (let ((qlist (,(symbolicate 'qt-smoke-make-list- type))))
2009-09-02 tobias 49 (loop for element in list do
2010-01-10 tobias 50 (,(symbolicate 'qt-smoke-list- type '-append)
2009-09-02 tobias 51 qlist (pointer (make-instance ',type :args (list element)))))
2009-08-02 tobias 52 (make-cleanup-pointer
2010-01-10 tobias 53 qlist
08:52:49 ' 54 (function ,(symbolicate 'qt-smoke-free-list- type)))))
' 55 ,@(loop for type-name in (ensure-list type-name) collect
' 56 `(define-from-lisp-translation (,(format nil "const QList<~A>&" type-name)
2009-08-02 tobias 57 ,(format nil "QList<~A>" type-name))
2009-09-02 tobias 58 list ;; FIXME allow sequence and define element type
2010-01-10 tobias 59 ,(symbolicate 'coerce- list-type))))))
08:52:49 ' 60
2009-09-02 tobias 61 (define-qlist-wrapper "QVariant")
12:00:35 ' 62 (define-qlist-wrapper ("QObject*" "QWidget*") "void")
' 63 (define-qlist-wrapper "QByteArray")