1 (defpackage :gobject.type-info
2 (:use :cl :iter :cffi :glib)
3 (:export #:+g-type-invalid+
35 #:g-type-interface-prerequisites
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}
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.
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}
49 This is a list of variables and functions that correspond to basic types:
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+}}
77 (in-package :gobject.type-info)
79 (defctype g-type gsize)
81 (eval-when (:load-toplevel :compile-toplevel)
82 (defun gtype-make-fundamental-type (x)
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.")
107 (define-foreign-type g-type-designator ()
109 (: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.
111 Numeric identifier of GType may be different between different program runs. But string identifier of GType does not change.")
112 (:actual-type g-type)
113 (:simple-parser g-type-designator))
115 (defmethod translate-from-foreign (value (type g-type-designator))
118 (defmethod translate-to-foreign (value (type g-type-designator))
120 (string (g-type-from-name value))
122 (null +g-type-invalid+)))
124 (defcfun (g-type-fundamental "g_type_fundamental") g-type-designator
125 "Returns the fundamental type which is the ancestor of @code{type}.
129 \(g-type-fundamental \"GtkWindowType\")
131 \(g-type-fundamental \"GtkLabel\")
134 @arg[type]{GType designator (see @class{g-type-designator})}
135 @return{GType designator}"
136 (type g-type-designator))
138 (defcfun (%g-type-init "g_type_init") :void)
140 (at-init () (%g-type-init))
142 (defcfun (g-type-name "g_type_name") :string
143 "Returns the name of a GType.@see{g-type-from-name}
147 \(g-type-from-name \"GtkLabel\")
149 \(g-type-name 7151952)
152 @arg[type]{GType designator (see @class{g-type-designator})}
154 (type g-type-designator))
156 (defcfun (g-type-from-name "g_type_from_name") g-type
157 "Returns the numeric identifier of a GType by its name. @see{g-type-name}
161 \(g-type-from-name \"GtkLabel\")
163 \(g-type-name 7151952)
166 @arg[name]{a string - name of GType}
170 (defcfun g-type-parent g-type-designator
171 "Returns the parent of a GType. @see{g-type-chilren}
175 \(g-type-parent \"GtkLabel\")
178 @arg[type]{GType designator (see @class{g-type-designator})}
179 @return{GType designator}"
180 (type g-type-designator))
182 (defcfun g-type-depth :uint
183 "Returns the length of the ancestry of @code{type}. This includes the @code{type} itself, so that e.g. a fundamental type has depth 1.
187 \(g-type-depth \"GtkLabel\")
190 @arg[type]{GType designator (see @class{g-type-designator})}
192 (type g-type-designator))
194 (defcfun g-type-next-base g-type-designator
195 "Determines the type that is derived directly from @code{root-type} which is also a base class of @code{leaf-type}.
199 \(g-type-next-base \"GtkButton\" \"GtkWidget\")
202 @arg[leaf-type]{GType designator (see @class{g-type-designator})}
203 @arg[root-type]{GType designator}
204 @return{GType designator}"
205 (leaf-type g-type-designator)
206 (root-type g-type-designator))
208 (defcfun g-type-is-a :boolean
209 "If @code{is-a-type} is a derivable type, check whether type is a descendant of @code{is-a-type}. If @code{is-a-type} is an interface, check whether type conforms to it.
213 \(g-type-is-a \"GtkButton\" \"GtkWidget\")
215 \(g-type-is-a \"GtkButton\" \"AtkImplementorIface\")
217 \(g-type-is-a \"GtkButton\" \"GtkLabel\")
220 @arg[type]{GType designator (see @class{g-type-designator})}
221 @arg[is-a-type]{GType designator}
223 (type g-type-designator)
224 (is-a-type g-type-designator))
226 (defcfun (%g-type-children "g_type_children") (:pointer g-type)
227 (type g-type-designator)
228 (n-children (:pointer :uint)))
230 (defun g-type-children (g-type)
231 "Returns the list of types inherited from @code{g-type}.@see{g-type-parent}
235 \(g-type-children \"GtkObject\")
236 => (\"GtkWidget\" \"GtkAdjustment\" \"GtkTreeViewColumn\" \"GtkCellRenderer\"
237 \"GtkFileFilter\" \"GtkRecentFilter\" \"GtkTooltips\")
239 @arg[g-type]{GType designator (see @class{g-type-designator})}
240 @return{list of GType designators}"
241 (with-foreign-object (n-children :uint)
242 (let ((g-types-ptr (%g-type-children g-type n-children)))
245 for i from 0 below (mem-ref n-children :uint)
246 collect (mem-aref g-types-ptr 'g-type-designator i))
247 (g-free g-types-ptr)))))
249 (defcfun (%g-type-interfaces "g_type_interfaces") (:pointer g-type)
250 (type g-type-designator)
251 (n-interfaces (:pointer :uint)))
253 (defun g-type-interfaces (g-type)
254 "Returns the list of interfaces the @code{g-type} conforms to.
258 \(g-type-interfaces \"GtkButton\")
259 => (\"AtkImplementorIface\" \"GtkBuildable\" \"GtkActivatable\")
261 @arg[g-type]{GType designator (see @class{g-type-designator})}
262 @return{list of GType designators}"
263 (with-foreign-object (n-interfaces :uint)
264 (let ((g-types-ptr (%g-type-interfaces g-type n-interfaces)))
267 for i from 0 below (mem-ref n-interfaces :uint)
268 collect (mem-aref g-types-ptr 'g-type-designator i))
269 (g-free g-types-ptr)))))
271 (defcfun (%g-type-interface-prerequisites "g_type_interface_prerequisites") (:pointer g-type)
272 (type g-type-designator)
273 (n-interface-prerequisites (:pointer :uint)))
275 (defun g-type-interface-prerequisites (g-type)
276 "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.
280 \(g-type-interface-prerequisites \"GtkTreeModel\")
283 @arg[g-type]{GType designator (see @class{g-type-designator})}
284 @return{list of GType designators}"
285 (with-foreign-object (n-interface-prerequisites :uint)
286 (let ((g-types-ptr (%g-type-interface-prerequisites g-type n-interface-prerequisites)))
289 for i from 0 below (mem-ref n-interface-prerequisites :uint)
290 collect (mem-aref g-types-ptr 'g-type-designator i))
291 (g-free g-types-ptr)))))
293 (defcfun g-strv-get-type g-type-designator
294 "Returns the type designator (see @class{g-type-designator}) for GStrv type. As a side effect, ensures that the type is registered.")
296 (at-init nil (g-strv-get-type))
298 (defcfun g-closure-get-type g-type-designator
299 "Returns the type designator (see @class{g-type-designator}) for GClosure type. As a side effect, ensure that the type is registered.")
301 (at-init nil (g-closure-get-type))