QList<QByteArray> and QList<QVariant> conversion & use cxx:operator== and qt:operator== in cxx:=
Wed May 27 19:18:41 CEST 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
* QList<QByteArray> and QList<QVariant> conversion & use cxx:operator== and qt:operator== in cxx:=
hunk ./qt.mbd 51
+ ("list" (:needs "qt"))
hunk ./qt.mbd 70
- (:needs :smoke :sysdef.cmake :cffi))
+ (:needs :smoke :sysdef.cmake :cffi :alexandria))
hunk ./src/lib/qlist.cpp 15
+
hunk ./src/lib/qlist.h 35
-qt_smoke_list_ ## NAME ## size(const void* list) \
+qt_smoke_list_ ## NAME ## _size(const void* list) \
hunk ./src/lib/qlist.h 65
-qt_smoke_list_ ## NAME ## _append(void* list, void* data, int length) \
+qt_smoke_list_ ## NAME ## _append(void* list, void* data) \
hunk ./src/lib/qlist.h 79
- return &qlist->at(index); \
+ return new TYPE(qlist->at(index)); \
hunk ./src/lib/qlist.h 83
-qt_smoke_list_ ## NAME ## _append(void* list, void* data, int length) \
+qt_smoke_list_ ## NAME ## _append(void* list, void* data) \
addfile ./src/list.lisp
hunk ./src/list.lisp 1
+(in-package :qt)
+
+(defmacro define-qlist-wrapper (type-name)
+ (let* ((type (string-upcase type-name))
+ (list-type (symbolicate 'qlist- type)))
+ `(progn
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_size") :int
+ "Returns the size of LIST."
+ (list :pointer))
+ (defcfun ,(concatenate 'string "qt_smoke_free_list_" type-name) :void
+ "Frees LIST."
+ (list :pointer))
+ (defcfun ,(concatenate 'string "qt_smoke_make_list_" type-name) :pointer
+ "Makes a list.")
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_at") :pointer
+ "Returns the a newly constructed copy of the element at position AT of LIST."
+ (list :pointer)
+ (index :int))
+ (defcfun ,(concatenate 'string "qt_smoke_list_" type-name "_append") :pointer
+ "Appends NEW-ELEMENT to LIST."
+ (list :pointer)
+ (new-element :pointer))
+ (define-foreign-type ,list-type ()
+ ()
+ (:actual-type :pointer))
+ (define-parse-method ,list-type ()
+ (make-instance ',list-type))
+ (eval-when (:load-toplevel :execute)
+ (smoke::add-type ,(format nil "const QList<~A>&" type-name)
+ ',list-type)
+ (smoke::add-type ,(format nil "QList<~A>" type-name) ',list-type))
+ (defmethod translate-from-foreign (list (type ,list-type))
+ (let ((vector (make-array (,(symbolicate 'qt-smoke-list-
+ type '-size)
+ list))))
+ (dotimes (index (length vector) vector)
+ (setf (aref vector index)
+ ;; FIXME the retuned object is not wrapped by Smoke
+ ;; -> change this? [_$_]
+ (smoke::object-to-lisp
+ (,(symbolicate 'qt-smoke-list-
+ type '-at)
+ list index)
+ (smoke::make-smoke-type *qt-smoke* ,type-name))))))
+ (defmethod free-translated-object (pointer (type ,list-type) param)
+ (declare (ignore param))
+ (,(symbolicate 'qt-smoke-free-list- type)
+ pointer))
+ (defun ,(symbolicate 'coerce- list-type) (list)
+ (let ((qlist (,(symbolicate 'qt-smoke-make-list- type))))
+ (loop for element in list do
+ (,(symbolicate 'qt-smoke-list- type '-append)
+ qlist (pointer (make-instance ',type :args (list element)))))
+ (smoke::make-cleanup-pointer
+ qlist
+ (function ,(symbolicate 'qt-smoke-free-list- type)))))
+ (define-from-lisp-translation (,(format nil "const QList<~A>&" type-name)
+ ,(format nil "QLIst<~A>" type-name))
+ list ;; FIXME allow seqence and define element type
+ ,(symbolicate 'coerce- list-type)))))
+
+(define-qlist-wrapper "QVariant")
+;(define-qlist-wrapper "void")
+(define-qlist-wrapper "QByteArray")
hunk ./src/operator.lisp 7
- (qt:operator== object o))
+ ;; Consider Class::operator== and operator==
+ ;; FIXME integrate this in the overload resolution
+ (handler-case (qt:operator== object o)
+ (smoke::no-applicable-cxx-method ()
+ (cxx:operator== object o))))
hunk ./src/package.lisp 2
- (:use :cl :smoke :cffi :bordeaux-threads :cxx-support)
+ (:use :cl :smoke :cffi :bordeaux-threads :cxx-support :alexandria)
hunk ./src/properties.lisp 47
+(defun dynamic-properties (object)
+ (map 'list (compose #'smoke::lispify #'cxx:data)
+ (cxx:dynamic-property-names object)))
+
hunk ./src/properties.lisp 53
- (warn "FIXME: dynamicPropertyNames not implemented")
- (meta-object-properties (cxx:meta-object object)))
+ (nconc (dynamic-properties object)
+ (meta-object-properties (cxx:meta-object object))))
hunk ./src/qstring.lisp 40
-(defmethod translate-to-foreign (string (type qstring))
- (with-foreign-string ((data length) string :null-terminated-p nil)
- (qt-smoke-string-to-qstring data length)))
-
hunk ./src/qstring.lisp 59
- (translate-to-foreign string (make-instance 'qt::qstring))
+ (with-foreign-string ((data length) string :null-terminated-p nil)
+ (qt-smoke-string-to-qstring data length))
hunk ./src/variant.lisp 5
- (if (null-pointer-p (pointer variant))
+ (if (or (not (slot-boundp variant 'pointer))
+ (null-pointer-p (pointer variant)))