QList<QByteArray> and QList<QVariant> conversion & use cxx:operator== and qt:operator== in cxx:=
Annotate for file src/variant.lisp
2009-06-11 tobias 1 (in-package :qt)
2010-01-10 tobias 2
2009-06-11 tobias 3 (defmethod print-object ((variant variant) stream)
2010-01-10 tobias 4 "Print the type and value of the variant."
2009-05-27 tobias 5 (if (or (not (slot-boundp variant 'pointer))
17:18:41 ' 6 (null-pointer-p (pointer variant)))
2010-01-10 tobias 7 (call-next-method)
08:52:49 ' 8 (print-unreadable-object (variant stream :type t :identity t)
' 9 (format stream "~A~@[ ~S~]"
' 10 (cxx:type-name variant)
2009-06-11 tobias 11 (handler-case (from-variant variant)
2010-01-10 tobias 12 (error () nil))))))
08:52:49 ' 13
2009-06-11 tobias 14 (defun make-variant (&optional (value nil value-p))
2010-01-10 tobias 15 "Returns a new VARIANT containing a C++ version of VALUE
08:52:49 ' 16 or an empty variant when VALUE is not specified."
' 17 (if value-p
2009-06-11 tobias 18 (make-instance 'variant :args (list value))
14:59:48 ' 19 (make-instance 'variant)))
2010-01-10 tobias 20
2009-06-11 tobias 21 (defun make-char (character)
2010-01-10 tobias 22 "Returns a char for a lisp CHARACTER."
08:52:49 ' 23 (let ((octets (babel:string-to-octets (string character))))
' 24 (case (length octets)
2009-06-11 tobias 25 (1 (make-instance 'char :args (list (aref octets 0))))
14:59:48 ' 26 (2 (make-instance 'char :args (list (aref octets 0)
2009-07-22 tobias 27 (aref octets 1))))
2010-01-10 tobias 28 (t (error "qt:char requires the character ~A to be encoded
08:52:49 ' 29 in one or two octets, but it is using ~A."
' 30 character (length octets))))))
' 31
' 32 (defun surrogate-p (char)
' 33 (or (cxx:is-high-surrogate char)
' 34 (cxx:is-low-surrogate char)))
' 35
2009-06-11 tobias 36 (defun from-char (char)
2009-07-22 tobias 37 "Returns the lisp character represented by CHAR."
2010-01-10 tobias 38 (assert (not (surrogate-p char))
08:52:49 ' 39 (char)
' 40 "The char ~A is part of a surrogate.")
' 41 (char
' 42 (babel:octets-to-string (make-array 2 :element-type '(unsigned-byte 8)
' 43 :initial-contents
' 44 (list
' 45 (char-code (cxx:cell char))
' 46 (char-code (cxx:row char)))))
' 47 0))
' 48
2009-06-11 tobias 49 (defmethod print-object ((char char) stream)
2010-01-10 tobias 50 (if (or (null-pointer-p (pointer char))
08:52:49 ' 51 (surrogate-p char))
' 52 (call-next-method)
' 53 (print-unreadable-object (char stream :type t)
2009-06-11 tobias 54 (princ (from-char char) stream))))
2010-01-10 tobias 55
08:52:49 ' 56
2009-07-22 tobias 57 ;; FIXME include in MAKE-VARIANT?
2009-06-11 tobias 58 (defun make-lisp-variant (value)
2010-01-10 tobias 59 "Returns a new VARIANT that wraps VALUE.
08:52:49 ' 60
2009-07-22 tobias 61 The variant contains the actual Lisp object
2010-01-10 tobias 62 and not its C++ value like in MAKE-VARIANT."
08:52:49 ' 63 (let ((object (make-cxx-lisp-object value)))
' 64 (unwind-protect
2009-06-11 tobias 65 (make-instance 'variant :args (list *cxx-lisp-object-metatype*
14:59:48 ' 66 object))
2010-01-10 tobias 67 (free-cxx-lisp-object object))))
08:52:49 ' 68
' 69 (defcfun qt-smoke-lisp-object-value :pointer
' 70 (variant :pointer))
' 71
2009-06-11 tobias 72 (defun variant-boundp (variant)
2010-01-10 tobias 73 "Returns true when VARIANT is valid (has a value) and false otherwise."
08:52:49 ' 74 (cxx:is-valid variant))
' 75
2009-06-11 tobias 76 (defun from-variant (variant)
2010-01-10 tobias 77 "Returns the value of VARIANT."
2009-06-10 tobias 78 (ecase (cxx:user-type variant)
2009-06-11 tobias 79 (#.(value variant.+invalid+)
2010-01-10 tobias 80 (cerror "Return (VALUES)" "Type of variant ~A is invalid." variant)
08:52:49 ' 81 (values))
2009-06-10 tobias 82 (#.(value variant.+string+)
12:02:01 ' 83 (cxx:to-string variant))
' 84 (#.(value variant.+string-list+)
' 85 (cxx:to-string-list variant))
' 86 (#.(value variant.+uint+)
' 87 (cxx:to-uint variant))
' 88 (#.(value variant.+int+)
' 89 (cxx:to-int variant))
' 90 (#.(value variant.+double+)
' 91 (cxx:to-double variant))
' 92 (#.(value variant.+char+)
' 93 (cxx:to-char variant))
' 94 (#.(value variant.+bool+)
' 95 (cxx:to-bool variant))
2010-01-10 tobias 96 (#.*cxx-lisp-object-metatype*
08:52:49 ' 97 (let* ((lisp-object (qt-smoke-lisp-object-value (smoke::pointer variant)))
' 98 (value))
' 99 (setf value (translate-cxx-lisp-object lisp-object))
' 100 (free-cxx-lisp-object lisp-object)
' 101 value))))
2009-06-10 tobias 102
2009-06-11 tobias 103 (defmethod value ((variant variant))
2010-01-10 tobias 104 "Returns the value of VARIANT."
2009-06-11 tobias 105 (from-variant variant))
2010-01-10 tobias 106
2009-06-11 tobias 107 (defmethod (setf value) (new-value (variant variant))
14:59:48 ' 108 (cxx:operator= variant (make-variant new-value))
2010-01-10 tobias 109 new-value)