refactoring: separated gobject.ffi with ffi definitions
[cl-gtk2.git] / glib / gobject.type-info.lisp
1 (defpackage :gobject.type-info
2   (:use :cl :iter :cffi :glib :gobject.ffi)
3   (:export #:+g-type-invalid+
4            #:+g-type-void+
5            #:+g-type-interface+
6            #:+g-type-char+
7            #:+g-type-uchar+
8            #:+g-type-boolean+
9            #:+g-type-int+
10            #:+g-type-uint+
11            #:+g-type-long+
12            #:+g-type-ulong+
13            #:+g-type-int64+
14            #:+g-type-uint64+
15            #:+g-type-enum+
16            #:+g-type-flags+
17            #:+g-type-float+
18            #:+g-type-double+
19            #:+g-type-string+
20            #:+g-type-pointer+
21            #:+g-type-boxed+
22            #:+g-type-param+
23            #:+g-type-object+
24            #:g-type-name
25            #:g-type-from-name
26            #:g-type
27            #:g-type-children
28            #:g-type-parent
29            #:g-type-designator
30            #:g-type-fundamental
31            #:g-type-depth
32            #:g-type-next-base
33            #:g-type-is-a
34            #:g-type-interfaces
35            #:g-type-interface-prerequisites
36            #:g-strv-get-type
37            #:g-closure-get-type)
38   (:documentation
39 "This package contains functions for querying the basic type information from GObject type system. For an overview of GObject type system, see @a[http://library.gnome.org/devel/gobject/stable/index.html]{GObject documentation}
40
41 Types are identified by GType designators that are specified in @class{g-type-designator}. Functions of this package provide means to query basic information about type.
42
43 @begin{itemize}
44 @item{@fun{g-type-name} and @fun{g-type-from-name} convert between numeric and string representation of GType.}
45 @item{@fun{g-type-parent}, @fun{g-type-children} and @fun{g-type-interfaces} traverse across the type hierarchy.}
46 @item{@fun{g-type-depth}, @fun{g-type-fundamental}, @fun{g-type-is-a}, @fun{g-type-next-base} are convenience functions that provide useful information from type hierarchy}
47 @end{itemize}
48
49 This is a list of variables and functions that correspond to basic types:
50 @begin{itemize}
51 @item{@fun{g-closure-get-type}}
52 @item{@fun{g-strv-get-type}}
53 @item{@variable{+g-type-invalid+}}
54 @item{@variable{+g-type-void+}}
55 @item{@variable{+g-type-interface+}}
56 @item{@variable{+g-type-char+}}
57 @item{@variable{+g-type-uchar+}}
58 @item{@variable{+g-type-boolean+}}
59 @item{@variable{+g-type-int+}}
60 @item{@variable{+g-type-uint+}}
61 @item{@variable{+g-type-long+}}
62 @item{@variable{+g-type-ulong+}}
63 @item{@variable{+g-type-int64+}}
64 @item{@variable{+g-type-uint64+}}
65 @item{@variable{+g-type-enum+}}
66 @item{@variable{+g-type-flags+}}
67 @item{@variable{+g-type-float+}}
68 @item{@variable{+g-type-double+}}
69 @item{@variable{+g-type-string+}}
70 @item{@variable{+g-type-pointer+}}
71 @item{@variable{+g-type-boxed+}}
72 @item{@variable{+g-type-param+}}
73 @item{@variable{+g-type-object+}}
74 @end{itemize}
75 "))
76
77 (in-package :gobject.type-info)
78
79 (defctype g-type gsize)
80
81 (eval-when (:load-toplevel :compile-toplevel)
82   (defun gtype-make-fundamental-type (x)
83     (ash x 2)))
84
85 (defconstant +g-type-invalid+ (gtype-make-fundamental-type 0) "An invalid GType used as error return value in some functions which return a GType.")
86 (defconstant +g-type-void+ (gtype-make-fundamental-type 1) "A fundamental type which is used as a replacement for the C @code{void} return type.")
87 (defconstant +g-type-interface+ (gtype-make-fundamental-type 2) "The fundamental type from which all interfaces are derived.")
88 (defconstant +g-type-char+ (gtype-make-fundamental-type 3) "The fundamental type corresponding to gchar. The type designated by @variable{+g-type-char+} is unconditionally an 8-bit signed integer. This may or may not be the same type a the C type @code{gchar}.")
89 (defconstant +g-type-uchar+ (gtype-make-fundamental-type 4) "The fundamental type corresponding to @code{guchar}.")
90 (defconstant +g-type-boolean+ (gtype-make-fundamental-type 5) "The fundamental type corresponding to @code{gboolean}.")
91 (defconstant +g-type-int+ (gtype-make-fundamental-type 6) "The fundamental type corresponding to @code{gint}.")
92 (defconstant +g-type-uint+ (gtype-make-fundamental-type 7) "The fundamental type corresponding to @code{guint}.")
93 (defconstant +g-type-long+ (gtype-make-fundamental-type 8) "The fundamental type corresponding to @code{glong}.")
94 (defconstant +g-type-ulong+ (gtype-make-fundamental-type 9) "The fundamental type corresponding to @code{gulong}.")
95 (defconstant +g-type-int64+ (gtype-make-fundamental-type 10) "The fundamental type corresponding to @code{gint64}.")
96 (defconstant +g-type-uint64+ (gtype-make-fundamental-type 11) "The fundamental type corresponding to @code{guint64}.")
97 (defconstant +g-type-enum+ (gtype-make-fundamental-type 12) "The fundamental type from which all enumeration types are derived.")
98 (defconstant +g-type-flags+ (gtype-make-fundamental-type 13) "The fundamental type from which all flags types are derived.")
99 (defconstant +g-type-float+ (gtype-make-fundamental-type 14) "The fundamental type corresponding to @code{gfloat}.")
100 (defconstant +g-type-double+ (gtype-make-fundamental-type 15) "The fundamental type corresponding to @code{gdouble}.")
101 (defconstant +g-type-string+ (gtype-make-fundamental-type 16) "The fundamental type corresponding to null-terminated C strings.")
102 (defconstant +g-type-pointer+ (gtype-make-fundamental-type 17) "The fundamental type corresponding to @code{gpointer}.")
103 (defconstant +g-type-boxed+ (gtype-make-fundamental-type 18) "The fundamental type from which all boxed types are derived.")
104 (defconstant +g-type-param+ (gtype-make-fundamental-type 19) "The fundamental type from which all GParamSpec types are derived.")
105 (defconstant +g-type-object+ (gtype-make-fundamental-type 20) "The fundamental type for GObject.")
106
107 (defun g-type-children (g-type)
108   "Returns the list of types inherited from @code{g-type}.@see{g-type-parent}
109
110 Example:
111 @pre{
112 \(g-type-children \"GtkObject\")
113 => (\"GtkWidget\" \"GtkAdjustment\" \"GtkTreeViewColumn\" \"GtkCellRenderer\"
114     \"GtkFileFilter\" \"GtkRecentFilter\" \"GtkTooltips\")
115 }
116 @arg[g-type]{GType designator (see @class{g-type-designator})}
117 @return{list of GType designators}"
118   (with-foreign-object (n-children :uint)
119     (let ((g-types-ptr (%g-type-children g-type n-children)))
120       (prog1
121           (loop
122              for i from 0 below (mem-ref n-children :uint)
123              collect (mem-aref g-types-ptr 'g-type-designator i))
124         (g-free g-types-ptr)))))
125
126 (defun g-type-interfaces (g-type)
127   "Returns the list of interfaces the @code{g-type} conforms to.
128
129 Example:
130 @pre{
131 \(g-type-interfaces \"GtkButton\")
132 => (\"AtkImplementorIface\" \"GtkBuildable\" \"GtkActivatable\")
133 }
134 @arg[g-type]{GType designator (see @class{g-type-designator})}
135 @return{list of GType designators}"
136   (with-foreign-object (n-interfaces :uint)
137     (let ((g-types-ptr (%g-type-interfaces g-type n-interfaces)))
138       (prog1
139           (loop
140              for i from 0 below (mem-ref n-interfaces :uint)
141              collect (mem-aref g-types-ptr 'g-type-designator i))
142         (g-free g-types-ptr)))))
143
144 (defun g-type-interface-prerequisites (g-type)
145   "Returns the prerequisites of an interface type. Prerequisite is a type that must be a superclass of an implementing class or an interface that the object must also implement.
146
147 Example:
148 @pre{
149 \(g-type-interface-prerequisites \"GtkTreeModel\")
150 => (\"GObject\")
151 }
152 @arg[g-type]{GType designator (see @class{g-type-designator})}
153 @return{list of GType designators}"
154   (with-foreign-object (n-interface-prerequisites :uint)
155     (let ((g-types-ptr (%g-type-interface-prerequisites g-type n-interface-prerequisites)))
156       (prog1
157           (loop
158              for i from 0 below (mem-ref n-interface-prerequisites :uint)
159              collect (mem-aref g-types-ptr 'g-type-designator i))
160         (g-free g-types-ptr)))))
161