1 /* guile-gnome 2 * Copyright (C) 2003 Andy Wingo <wingo at pobox dot com> 3 * 4 * gtype.h: Base support for the GLib type system 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, contact: 18 * 19 * Free Software Foundation Voice: +1-617-542-5942 20 * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 21 * Boston, MA 02111-1307, USA gnu@gnu.org 22 */ 23 24 #ifndef __GUILE_GNOME_GOBJECT_GTYPE_H__ 25 #define __GUILE_GNOME_GOBJECT_GTYPE_H__ 26 27 28 #include <glib-object.h> 29 #include <libguile.h> 30 31 32 G_BEGIN_DECLS 33 34 35 typedef gpointer (*scm_t_gtype_instance_ref)(gpointer instance); 36 typedef void (*scm_t_gtype_instance_unref)(gpointer instance); 37 typedef gpointer (*scm_t_gtype_instance_get_qdata)(gpointer instance, 38 GQuark quark); 39 typedef void (*scm_t_gtype_instance_set_qdata)(gpointer instance, GQuark quark, 40 gpointer data); 41 typedef void* (*scm_t_gtype_instance_construct)(SCM object, SCM initargs); 42 typedef void (*scm_t_gtype_instance_initialize_scm)(SCM object, gpointer instance); 43 typedef struct { 44 GType type; 45 scm_t_gtype_instance_ref ref; 46 scm_t_gtype_instance_unref unref; 47 scm_t_gtype_instance_get_qdata get_qdata; 48 scm_t_gtype_instance_set_qdata set_qdata; 49 scm_t_gtype_instance_construct construct; 50 scm_t_gtype_instance_initialize_scm initialize_scm; 51 } scm_t_gtype_instance_funcs; 52 53 54 55 56 57 extern SCM scm_class_gtype_class; 58 extern SCM scm_class_gtype_instance; 59 extern SCM scm_sys_gtype_to_class; 60 61 62 63 64 65 66 #define SCM_GTYPE_CLASSP(scm) SCM_NFALSEP (scm_memq (scm_class_gtype_class, \ 67 scm_class_precedence_list (scm_class_of ((scm))))) 68 #define SCM_GTYPE_INSTANCEP(scm) SCM_IS_A_P (scm, scm_class_gtype_instance) 69 70 #define SCM_VALIDATE_GTYPE_CLASS(pos, scm) SCM_MAKE_VALIDATE (pos, scm, GTYPE_CLASSP) 71 #define SCM_VALIDATE_GTYPE_INSTANCE(pos, scm) SCM_MAKE_VALIDATE (pos, scm, GTYPE_INSTANCEP) 72 73 #define SCM_VALIDATE_GTYPE_CLASS_COPY(pos, scm, cvar) \ 74 do { \ 75 SCM_VALIDATE_GTYPE_CLASS (pos, scm); \ 76 cvar = scm_c_gtype_class_to_gtype (scm); \ 77 } while (0) 78 79 #define SCM_VALIDATE_GTYPE_CLASS_IS_A(pos, scm, is_a, cvar) \ 80 do { \ 81 SCM_VALIDATE_GTYPE_CLASS_COPY (pos, scm, cvar); \ 82 SCM_ASSERT (g_type_is_a (cvar, is_a), scm, pos, FUNC_NAME); \ 83 } while (0) 84 85 #define SCM_VALIDATE_GTYPE_INSTANCE_COPY(pos, value, cvar) \ 86 do { \ 87 SCM_VALIDATE_GTYPE_INSTANCE (pos, value); \ 88 cvar = scm_c_scm_to_gtype_instance (value); \ 89 } while (0) 90 91 #define SCM_VALIDATE_GTYPE_INSTANCE_TYPE_COPY(pos, value, type, cvar) \ 92 do { \ 93 SCM_VALIDATE_GTYPE_INSTANCE (pos, value); \ 94 cvar = scm_c_scm_to_gtype_instance_typed (value, type); \ 95 SCM_ASSERT (cvar != NULL, value, pos, FUNC_NAME); \ 96 } while (0) 97 98 99 100 101 /* SCM API */ 102 103 /* GTypeInstance */ 104 SCM scm_gtype_instance_destroy_x (SCM instance); 105 106 107 108 109 110 /* C-only API */ 111 112 GType gboxed_scm_get_type (void) G_GNUC_CONST; 113 #define G_TYPE_BOXED_SCM (gboxed_scm_get_type ()) 114 115 /* GTypeClass */ 116 SCM scm_c_gtype_lookup_class (GType gtype); 117 SCM scm_c_gtype_to_class (GType gtype); 118 gboolean scm_c_gtype_class_is_a_p (SCM instance, GType gtype); 119 GType scm_c_gtype_class_to_gtype (SCM klass); 120 121 /* GTypeInstance use */ 122 gpointer scm_c_gtype_instance_ref (gpointer instance); 123 void scm_c_gtype_instance_unref (gpointer instance); 124 gboolean scm_c_gtype_instance_is_a_p (SCM instance, GType gtype); 125 gpointer scm_c_scm_to_gtype_instance (SCM instance); 126 gpointer scm_c_scm_to_gtype_instance_typed (SCM instance, GType gtype); 127 SCM scm_c_gtype_instance_to_scm (gpointer ginstance); 128 129 /* GTypeInstance implementations */ 130 void scm_c_gruntime_error (const char *subr, const char *message, SCM args); 131 void scm_register_gtype_instance_funcs (const scm_t_gtype_instance_funcs *funcs); 132 void scm_register_gtype_instance_sinkfunc (GType type, void (*sinkfunc) (gpointer)); 133 134 135 G_END_DECLS 136 137 138 #endif /* __GUILE_GNOME_GOBJECT_GTYPE_H__ */ 139