Merge branch 'master' into andy128kr
[cl-gtk2.git] / glib / gobject.type-designator.lisp
blob546840301c582807e0c5662cbf630d4c9ba93a3e
1 (in-package :gobject.ffi)
3 (defctype g-type gsize)
5 (define-foreign-type g-type-designator ()
6 ((mangled-p :initarg :mangled-p
7 :reader g-type-designator-mangled-p
8 :initform nil
9 :documentation "Whether the type designator is mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag"))
10 (:documentation "Values of this CFFI foreign type identify the GType. GType is designated by a its name (a string) or a numeric identifier. Functions accept GType designators as a string or integer and return them as a string. Functions @fun{g-type-name} and @fun{g-type-from-name} are used to convert between name and numeric identifier.
12 Numeric identifier of GType may be different between different program runs. But string identifier of GType does not change.")
13 (:actual-type g-type)
14 (:simple-parser g-type-designator))
16 (defun unmangle-g-type (g-type)
17 (logxor g-type (ldb (byte 1 0) g-type)));;subtract the G_SIGNAL_TYPE_STATIC_SCOPE
19 (defmethod translate-from-foreign (value (type g-type-designator))
20 (g-type-name (if (g-type-designator-mangled-p type)
21 (unmangle-g-type value)
22 value)))
24 (defmethod translate-to-foreign (value (type g-type-designator))
25 (etypecase value
26 (string (g-type-from-name value))
27 (integer value)
28 (null 0)))
30 (defun g-type-numeric (g-type-designator)
31 (etypecase g-type-designator
32 (string (g-type-from-name g-type-designator))
33 (integer g-type-designator)
34 (null 0)))
36 (defun g-type-string (g-type-designator)
37 (etypecase g-type-designator
38 (string (g-type-name g-type-designator))
39 (integer (g-type-name g-type-designator))
40 (null nil)))
42 (defcfun (g-type-name "g_type_name") :string
43 "Returns the name of a GType.@see{g-type-from-name}
45 Example:
46 @pre{
47 \(g-type-from-name \"GtkLabel\")
48 => 7151952
49 \(g-type-name 7151952)
50 => \"GtkLabel\"
52 @arg[type]{GType designator (see @class{g-type-designator})}
53 @return{a string}"
54 (type g-type-designator))
56 (defcfun (g-type-from-name "g_type_from_name") g-type
57 "Returns the numeric identifier of a GType by its name. @see{g-type-name}
59 Example:
60 @pre{
61 \(g-type-from-name \"GtkLabel\")
62 => 7151952
63 \(g-type-name 7151952)
64 => \"GtkLabel\"
66 @arg[name]{a string - name of GType}
67 @return{an integer}"
68 (name :string))
70 (defun g-type= (type-1 type-2)
71 (= (g-type-numeric type-1)
72 (g-type-numeric type-2)))
74 (defun g-type/= (type-1 type-2)
75 (/= (g-type-numeric type-1)
76 (g-type-numeric type-2)))