diff options
author | Diego Escalante Urrelo <diegoe@gnome.org> | 2019-11-04 10:51:42 -0500 |
---|---|---|
committer | Fabiano FidĂȘncio <fidencio@redhat.com> | 2019-11-06 14:21:31 +0100 |
commit | 706b6fd0d97ed572d92c4a33882605d561ebe3c8 (patch) | |
tree | 5ae7adf8a1753f48d09e5d7378654e5452cd8343 | |
parent | d061a1aa89ce237e391c2a8e34d15dad7c0160b8 (diff) | |
download | libosinfo-706b6fd0d97ed572d92c4a33882605d561ebe3c8.tar.gz |
list: Update GObject boilerplate
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
-rw-r--r-- | osinfo/osinfo_list.c | 37 | ||||
-rw-r--r-- | osinfo/osinfo_list.h | 36 |
2 files changed, 20 insertions, 53 deletions
diff --git a/osinfo/osinfo_list.c b/osinfo/osinfo_list.c index 3fce5d0..20192a7 100644 --- a/osinfo/osinfo_list.c +++ b/osinfo/osinfo_list.c @@ -26,10 +26,6 @@ #include <osinfo/osinfo.h> #include <glib/gi18n-lib.h> -G_DEFINE_ABSTRACT_TYPE(OsinfoList, osinfo_list, G_TYPE_OBJECT); - -#define OSINFO_LIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_LIST, OsinfoListPrivate)) - /** * SECTION:osinfo_list * @short_description: Abstract base class for entity lists @@ -39,20 +35,22 @@ G_DEFINE_ABSTRACT_TYPE(OsinfoList, osinfo_list, G_TYPE_OBJECT); * */ -struct _OsinfoListPrivate +typedef struct { GPtrArray *array; GHashTable *entities; GType elementType; -}; +} OsinfoListPrivate; enum { PROP_O, - - PROP_ELEMENT_TYPE + PROP_ELEMENT_TYPE, + LAST_PROP }; +static GParamSpec *properties[LAST_PROP]; +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(OsinfoList, osinfo_list, G_TYPE_OBJECT) static void osinfo_list_set_property(GObject *object, @@ -112,7 +110,6 @@ static void osinfo_list_class_init(OsinfoListClass *klass) { GObjectClass *g_klass = G_OBJECT_CLASS(klass); - GParamSpec *pspec; g_klass->set_property = osinfo_list_set_property; g_klass->get_property = osinfo_list_get_property; @@ -125,19 +122,15 @@ osinfo_list_class_init(OsinfoListClass *klass) * restricted to storing #OsinfoEntity objects of * the specified type. */ - pspec = g_param_spec_gtype("element-type", - "Element type", - _("List element type"), - OSINFO_TYPE_ENTITY, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_property(g_klass, - PROP_ELEMENT_TYPE, - pspec); - - g_type_class_add_private(klass, sizeof(OsinfoListPrivate)); + properties[PROP_ELEMENT_TYPE] = g_param_spec_gtype("element-type", + "Element type", + _("List element type"), + OSINFO_TYPE_ENTITY, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(g_klass, LAST_PROP, properties); } static void diff --git a/osinfo/osinfo_list.h b/osinfo/osinfo_list.h index 4955066..07731f0 100644 --- a/osinfo/osinfo_list.h +++ b/osinfo/osinfo_list.h @@ -27,44 +27,16 @@ # include <osinfo/osinfo_filter.h> -/* - * Type macros. - */ -# define OSINFO_TYPE_LIST (osinfo_list_get_type ()) -# define OSINFO_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_LIST, OsinfoList)) -# define OSINFO_IS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_LIST)) -# define OSINFO_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_LIST, OsinfoListClass)) -# define OSINFO_IS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_LIST)) -# define OSINFO_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_LIST, OsinfoListClass)) - -typedef struct _OsinfoList OsinfoList; - -typedef struct _OsinfoListClass OsinfoListClass; - -typedef struct _OsinfoListPrivate OsinfoListPrivate; - -/* object */ -struct _OsinfoList -{ - GObject parent_instance; - - /* public */ +G_BEGIN_DECLS - /* private */ - OsinfoListPrivate *priv; -}; +# define OSINFO_TYPE_LIST (osinfo_list_get_type ()) +G_DECLARE_DERIVABLE_TYPE(OsinfoList, osinfo_list, OSINFO, LIST, GObject) -/* class */ struct _OsinfoListClass { - /*< private >*/ GObjectClass parent_class; - - /* class members */ }; -GType osinfo_list_get_type(void); - GType osinfo_list_get_element_type(OsinfoList *list); gint osinfo_list_get_length(OsinfoList *list); OsinfoEntity *osinfo_list_get_nth(OsinfoList *list, gint idx); @@ -83,4 +55,6 @@ OsinfoList *osinfo_list_new_filtered(OsinfoList *source, OsinfoFilter *filter); OsinfoList *osinfo_list_new_intersection(OsinfoList *sourceOne, OsinfoList *sourceTwo); OsinfoList *osinfo_list_new_union(OsinfoList *sourceOne, OsinfoList *sourceTwo); +G_END_DECLS + #endif /* __OSINFO_LIST_H__ */ |