From 1f5b72d49e29a126b35385a6277b411b1f97fbf5 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 28 Mar 2011 19:35:28 -0400 Subject: [PATCH] uobject: Make interface functions take UObjects directly. This makes implementing the functions a little cleaner. --- src/engine/music.gob | 28 ++++++++++++++-------------- src/uobject/exportable.c | 21 +++++++++++++-------- src/uobject/exportable.h | 6 +++--- src/uobject/loadable.c | 20 +++++++++++--------- src/uobject/loadable.h | 7 +++---- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/engine/music.gob b/src/engine/music.gob index 920e23c..879e0ad 100644 --- a/src/engine/music.gob +++ b/src/engine/music.gob @@ -39,10 +39,10 @@ class Engine:Music from U:Object (dynamic) private unsigned loaded = 0; interface U:Object:Loadable - private int load(G:Object *go) + private int load(U:Object *uo) { - struct upkg_file *f = U_OBJECT(go)->pkg_file; - Self *self = SELF(go); + struct upkg_file *f = uo->pkg_file; + Self *self = SELF(uo); if (!self->_priv->loaded) { g_return_val_if_fail(f != NULL, -1); @@ -60,9 +60,9 @@ class Engine:Music from U:Object (dynamic) } interface U:Object:Loadable - private void unload(G:Object *go) + private void unload(U:Object *uo) { - Self *self = SELF(go); + Self *self = SELF(uo); g_return_if_fail(self->_priv->loaded > 0); @@ -71,37 +71,37 @@ class Engine:Music from U:Object (dynamic) } interface U:Object:Exportable - private int export(G:Object *go, FILE *f) + private int export(U:Object *uo, FILE *f) { - Self *self = SELF(go); + Self *self = SELF(uo); int rc; - if (self_load(go) != 0) + if (self_load(uo) != 0) return -1; rc = music_mod_dump(self->_priv->mod, f); - self_unload(go); + self_unload(uo); return rc; } interface U:Object:Exportable - private int export_name(G:Object *go, char *buf, size_t n) + private int export_name(U:Object *uo, char *buf, size_t n) { - Self *self = SELF(go); + Self *self = SELF(uo); const char *type; int rc; - if (self_load(go) != 0) { + if (self_load(uo) != 0) { if (n > 0) buf[0] = '\0'; return 0; } type = music_mod_type(self->_priv->mod); - rc = snprintf(buf, n, "%s.%s", U_OBJECT(go)->pkg_file->name, type); + rc = snprintf(buf, n, "%s.%s", uo->pkg_file->name, type); - self_unload(go); + self_unload(uo); return rc; } diff --git a/src/uobject/exportable.c b/src/uobject/exportable.c index 9cb1de1..541e698 100644 --- a/src/uobject/exportable.c +++ b/src/uobject/exportable.c @@ -17,8 +17,7 @@ */ #include -#include -#include +#include "exportable.h" GType u_object_exportable_get_type(void) { @@ -36,14 +35,20 @@ GType u_object_exportable_get_type(void) return type; } -int u_object_export(GObject *obj, FILE *f) +int u_object_export(GObject *go, FILE *f) { - g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1); - return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export(obj, f); + g_return_val_if_fail(IS_U_OBJECT(go), -1); + g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(go), -1); + UObject *uo = U_OBJECT(go); + + return U_OBJECT_EXPORTABLE_GET_INTERFACE(go)->export(uo, f); } -int u_object_export_name(GObject *obj, char *buf, size_t n) +int u_object_export_name(GObject *go, char *buf, size_t n) { - g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1); - return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export_name(obj, buf, n); + g_return_val_if_fail(IS_U_OBJECT(go), -1); + g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(go), -1); + UObject *uo = U_OBJECT(go); + + return U_OBJECT_EXPORTABLE_GET_INTERFACE(go)->export_name(uo, buf, n); } diff --git a/src/uobject/exportable.h b/src/uobject/exportable.h index d3e9ce8..4033a1a 100644 --- a/src/uobject/exportable.h +++ b/src/uobject/exportable.h @@ -20,7 +20,7 @@ #define U_OBJECT_EXPORTABLE_H_ #include -#include +#include #define U_TYPE_OBJECT_EXPORTABLE (u_object_exportable_get_type()) #define U_OBJECT_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ @@ -39,8 +39,8 @@ typedef struct UObjectExportableIface UObjectExportableIface; struct UObjectExportableIface { GTypeInterface parent; - int (*export)(GObject *obj, FILE *f); - int (*export_name)(GObject *obj, char *buf, size_t n); + int (*export)(UObject *obj, FILE *f); + int (*export_name)(UObject *obj, char *buf, size_t n); }; GType u_object_exportable_get_type(void); diff --git a/src/uobject/loadable.c b/src/uobject/loadable.c index 8ed00ff..1e41c46 100644 --- a/src/uobject/loadable.c +++ b/src/uobject/loadable.c @@ -16,9 +16,7 @@ * along with this program. If not, see . */ -#include -#include -#include +#include "loadable.h" GType u_object_loadable_get_type(void) { @@ -36,14 +34,18 @@ GType u_object_loadable_get_type(void) return type; } -int u_object_load(GObject *obj) +int u_object_load(GObject *go) { - g_return_val_if_fail(U_OBJECT_IS_LOADABLE(obj), -1); - return U_OBJECT_LOADABLE_GET_INTERFACE(obj)->load(obj); + g_return_val_if_fail(IS_U_OBJECT(go), -1); + g_return_val_if_fail(U_OBJECT_IS_LOADABLE(go), -1); + + return U_OBJECT_LOADABLE_GET_INTERFACE(go)->load(U_OBJECT(go)); } -void u_object_unload(GObject *obj) +void u_object_unload(GObject *go) { - g_return_if_fail(U_OBJECT_IS_LOADABLE(obj)); - U_OBJECT_LOADABLE_GET_INTERFACE(obj)->unload(obj); + g_return_if_fail(IS_U_OBJECT(go)); + g_return_if_fail(U_OBJECT_IS_LOADABLE(go)); + + U_OBJECT_LOADABLE_GET_INTERFACE(go)->unload(U_OBJECT(go)); } diff --git a/src/uobject/loadable.h b/src/uobject/loadable.h index 296366b..d862583 100644 --- a/src/uobject/loadable.h +++ b/src/uobject/loadable.h @@ -19,8 +19,7 @@ #ifndef U_OBJECT_LOADABLE_H_ #define U_OBJECT_LOADABLE_H_ -#include -#include +#include #define U_TYPE_OBJECT_LOADABLE (u_object_loadable_get_type()) #define U_OBJECT_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \ @@ -41,8 +40,8 @@ typedef struct UObjectLoadableIface UObjectLoadableIface; struct UObjectLoadableIface { GTypeInterface parent; - int (*load)(GObject *obj); - void (*unload)(GObject *obj); + int (*load)(UObject *obj); + void (*unload)(UObject *obj); }; GType u_object_loadable_get_type(void); -- 2.43.0