refactoring: separated gobject.ffi with ffi definitions
[cl-gtk2.git] / glib / gobject.type-designator.lisp
1 (in-package :gobject.ffi)
2
3 (defctype g-type gsize)
4
5 (define-foreign-type g-type-designator ()
6   ()
7   (: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.
8
9 Numeric identifier of GType may be different between different program runs. But string identifier of GType does not change.")
10   (:actual-type g-type)
11   (:simple-parser g-type-designator))
12
13 (defmethod translate-from-foreign (value (type g-type-designator))
14   (g-type-name value))
15
16 (defmethod translate-to-foreign (value (type g-type-designator))
17   (etypecase value
18     (string (g-type-from-name value))
19     (integer value)
20     (null 0)))
21
22 (defcfun (g-type-name "g_type_name") :string
23   "Returns the name of a GType.@see{g-type-from-name}
24
25 Example:
26 @pre{
27 \(g-type-from-name \"GtkLabel\")
28 => 7151952
29 \(g-type-name 7151952)
30 => \"GtkLabel\"
31 }
32 @arg[type]{GType designator (see @class{g-type-designator})}
33 @return{a string}"
34   (type g-type-designator))
35
36 (defcfun (g-type-from-name "g_type_from_name") g-type
37   "Returns the numeric identifier of a GType by its name. @see{g-type-name}
38
39 Example:
40 @pre{
41 \(g-type-from-name \"GtkLabel\")
42 => 7151952
43 \(g-type-name 7151952)
44 => \"GtkLabel\"
45 }
46 @arg[name]{a string - name of GType}
47 @return{an integer}"
48   (name :string))