repos
/
qt.gui
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
filehistory
normal
|
plain
|
shade
|
zebra
support packages for symbols as property names.
Annotate for file src/variant.lisp
2010-01-10 tobias
1
(in-package :cl-smoke.qt-impl)
08:52:49 '
2
'
3
(defmethod print-object ((variant qt:variant) stream)
'
4
"Print the type and value of the variant."
'
5
(if (or (not (slot-boundp variant 'pointer))
'
6
(null-pointer-p (pointer variant)))
'
7
(call-next-method)
'
8
(print-unreadable-object (variant stream :type t :identity t)
'
9
(format stream "~A~@[ ~S~]"
'
10
(cxx:type-name variant)
'
11
(handler-case (qt:from-variant variant)
'
12
(error () nil))))))
'
13
'
14
(defun qt:make-variant (&optional (value nil value-p))
'
15
"Returns a new VARIANT containing a C++ version of VALUE
'
16
or an empty variant when VALUE is not specified."
'
17
(if value-p
2009-07-22 tobias
18
(make-instance 'qt:variant :arg0 value)
2010-01-10 tobias
19
(make-instance 'qt:variant)))
08:52:49 '
20
'
21
(defun qt:make-char (character)
'
22
"Returns a char for a lisp CHARACTER."
'
23
(let ((octets (babel:string-to-octets (string character))))
'
24
(case (length octets)
2009-07-22 tobias
25
(1 (make-instance 'qt:char :arg0 (aref octets 0)))
2010-01-10 tobias
26
(2 (make-instance 'qt: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
'
36
(defun qt: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
'
49
(defmethod print-object ((char qt:char) stream)
'
50
(if (or (null-pointer-p (pointer char))
'
51
(surrogate-p char))
'
52
(call-next-method)
'
53
(print-unreadable-object (char stream :type t)
'
54
(princ (qt:from-char char) stream))))
'
55
'
56
2009-07-22 tobias
57
;; FIXME include in MAKE-VARIANT? how??
2010-01-10 tobias
58
(defun qt:make-lisp-variant (value)
08:52:49 '
59
"Returns a new VARIANT that wraps VALUE.
'
60
2009-07-22 tobias
61
The variant contains the actual Lisp object VALUE
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
'
65
(make-instance 'qt:variant :args (list *cxx-lisp-object-metatype*
'
66
object))
'
67
(free-cxx-lisp-object object))))
'
68
'
69
(defcfun qt-smoke-lisp-object-value :pointer
'
70
(variant :pointer))
'
71
'
72
(defun qt:variant-boundp (variant)
'
73
"Returns true when VARIANT is valid (has a value) and false otherwise."
'
74
(cxx:is-valid variant))
'
75
'
76
(defmacro variant-conversions ((variant) &body types)
'
77
`(ecase (cxx:user-type ,variant)
'
78
'
79
,@(loop for type in types collect
'
80
(if (symbolp type)
'
81
`(,(value (symbol-value
'
82
(let ((*package* (find-package :cl-smoke.qt)))
'
83
(alexandria:symbolicate 'variant.+ type '+))))
'
84
(,(intern (format nil "TO-~A" type) :cxx) ,variant))
'
85
type))))
'
86
'
87
(defun qt:from-variant (variant)
'
88
"Returns the value of VARIANT."
'
89
(variant-conversions (variant)
'
90
(#.(value qt:variant.+invalid+)
'
91
(cerror "Return (VALUES)" "Type of variant ~A is invalid." variant)
'
92
(values))
'
93
bit-array bool byte-array
'
94
char
'
95
date date-time double
'
96
int
'
97
line line-f list locale long-long
'
98
point point-f
'
99
rect rect-f reg-exp
'
100
size size-f string string-list
'
101
time
'
102
uint
'
103
ulong-long
'
104
url
'
105
(#.*cxx-lisp-object-metatype*
'
106
(let* ((lisp-object (qt-smoke-lisp-object-value (smoke::pointer variant)))
'
107
(value))
'
108
(setf value (translate-cxx-lisp-object lisp-object))
'
109
(free-cxx-lisp-object lisp-object)
'
110
value))))
'
111
'
112
(defmethod qt:value ((variant qt:variant))
'
113
"Returns the value of VARIANT."
'
114
(qt:from-variant variant))
'
115
'
116
(defmethod (setf qt:value) (new-value (variant qt:variant))
'
117
(cxx:operator= variant (qt:make-variant new-value))
'
118
new-value)