[libgda] GdaMysqlHandlerBoolean: ported to G_DECLARE/G_DEFINE



commit 1dc483fc61a492892b47e320ebab17bcf4d8fb8c
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Apr 5 11:04:41 2019 -0600

    GdaMysqlHandlerBoolean: ported to G_DECLARE/G_DEFINE

 providers/mysql/gda-mysql-handler-boolean.c | 62 ++++-------------------------
 providers/mysql/gda-mysql-handler-boolean.h | 17 +-------
 2 files changed, 9 insertions(+), 70 deletions(-)
---
diff --git a/providers/mysql/gda-mysql-handler-boolean.c b/providers/mysql/gda-mysql-handler-boolean.c
index b8c2b7c90..d5c01b226 100644
--- a/providers/mysql/gda-mysql-handler-boolean.c
+++ b/providers/mysql/gda-mysql-handler-boolean.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2010 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
+ * Copyright (C) 2019 Daniel Espinsa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,48 +43,13 @@ static gboolean     gda_mysql_handler_boolean_accepts_g_type         (GdaDataHan
 
 static const gchar *gda_mysql_handler_boolean_get_descr              (GdaDataHandler *dh);
 
-struct  _GdaMysqlHandlerBooleanPriv {
+typedef struct {
        gchar dummy;
-};
+} GdaMysqlHandlerBooleanPrivate;
 
-/* get a pointer to the parents to be able to call their destructor */
-static GObjectClass *parent_class = NULL;
-
-GType
-gda_mysql_handler_boolean_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               static const GTypeInfo info = {
-                       sizeof (GdaMysqlHandlerBooleanClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gda_mysql_handler_boolean_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdaMysqlHandlerBoolean),
-                       0,
-                       (GInstanceInitFunc) gda_mysql_handler_boolean_init,
-                       NULL
-               };              
-
-               static const GInterfaceInfo data_entry_info = {
-                       (GInterfaceInitFunc) gda_mysql_handler_boolean_data_handler_init,
-                       NULL,
-                       NULL
-               };
-
-               g_mutex_lock (&registering);
-               if (type == 0) {
-                       type = g_type_register_static (G_TYPE_OBJECT, "GdaMysqlHandlerBoolean", &info, 0);
-                       g_type_add_interface_static (type, GDA_TYPE_DATA_HANDLER, &data_entry_info);
-               }
-               g_mutex_unlock (&registering);
-       }
-       return type;
-}
+G_DEFINE_TYPE_WITH_CODE (GdaMysqlHandlerBoolean, gda_mysql_handler_boolean, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (GdaMysqlHandlerBoolean)
+                         G_IMPLEMENT_INTERFACE (GDA_TYPE_DATA_HANDLER, 
gda_mysql_handler_boolean_data_handler_init))
 
 static void
 gda_mysql_handler_boolean_data_handler_init (GdaDataHandlerInterface *iface)
@@ -103,8 +69,6 @@ gda_mysql_handler_boolean_class_init (GdaMysqlHandlerBooleanClass * class)
 {
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
        
-       parent_class = g_type_class_peek_parent (class);
-
        object_class->dispose = gda_mysql_handler_boolean_dispose;
 }
 
@@ -112,7 +76,6 @@ static void
 gda_mysql_handler_boolean_init (GdaMysqlHandlerBoolean *hdl)
 {
        /* Private structure */
-       hdl->priv = g_new0 (GdaMysqlHandlerBooleanPriv, 1);
        g_object_set_data (G_OBJECT (hdl), "name", "MySQLBoolean");
        g_object_set_data (G_OBJECT (hdl), "descr", _("MySQL boolean representation"));
 }
@@ -120,19 +83,8 @@ gda_mysql_handler_boolean_init (GdaMysqlHandlerBoolean *hdl)
 static void
 gda_mysql_handler_boolean_dispose (GObject *object)
 {
-       GdaMysqlHandlerBoolean *hdl;
-
-       g_return_if_fail (GDA_IS_MYSQL_HANDLER_BOOLEAN (object));
-
-       hdl = GDA_MYSQL_HANDLER_BOOLEAN (object);
-
-       if (hdl->priv) {
-               g_free (hdl->priv);
-               hdl->priv = NULL;
-       }
-
        /* for the parent class */
-       parent_class->dispose (object);
+       G_OBJECT_CLASS (gda_mysql_handler_boolean_parent_class)->dispose (object);
 }
 
 /**
diff --git a/providers/mysql/gda-mysql-handler-boolean.h b/providers/mysql/gda-mysql-handler-boolean.h
index 365013ebc..d1da67471 100644
--- a/providers/mysql/gda-mysql-handler-boolean.h
+++ b/providers/mysql/gda-mysql-handler-boolean.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2019 Daniel Espinsa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,22 +27,8 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_MYSQL_HANDLER_BOOLEAN          (gda_mysql_handler_boolean_get_type())
-#define GDA_MYSQL_HANDLER_BOOLEAN(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, 
gda_mysql_handler_boolean_get_type(), GdaMysqlHandlerBoolean)
-#define GDA_MYSQL_HANDLER_BOOLEAN_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, 
gda_mysql_handler_boolean_get_type (), GdaMysqlHandlerBooleanClass)
-#define GDA_IS_MYSQL_HANDLER_BOOLEAN(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, 
gda_mysql_handler_boolean_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GdaMysqlHandlerBoolean, gda_mysql_handler_boolean, GDA, MYSQL_HANDLER_BOOLEAN, 
GObject)
 
-typedef struct _GdaMysqlHandlerBoolean      GdaMysqlHandlerBoolean;
-typedef struct _GdaMysqlHandlerBooleanClass GdaMysqlHandlerBooleanClass;
-typedef struct _GdaMysqlHandlerBooleanPriv  GdaMysqlHandlerBooleanPriv;
-
-/* struct for the object's data */
-struct _GdaMysqlHandlerBoolean
-{
-       GObject                 object;
-       GdaMysqlHandlerBooleanPriv  *priv;
-};
-
-/* struct for the object's class */
 struct _GdaMysqlHandlerBooleanClass
 {
        GObjectClass           parent_class;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]