[libgda] gda-statement: ported to G_DECLARE/G_DEFINE



commit ee4a620432854553ae7dccacf96a71e3db5406b6
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Sep 19 13:01:46 2018 -0500

    gda-statement: ported to G_DECLARE/G_DEFINE

 libgda/gda-statement.c | 50 ++++++--------------------------------------------
 libgda/gda-statement.h | 15 ++++-----------
 2 files changed, 10 insertions(+), 55 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 515697c05..bed980d0e 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -49,8 +49,6 @@
 /* 
  * Main static functions 
  */
-static void gda_statement_class_init (GdaStatementClass *klass);
-static void gda_statement_init (GdaStatement *stmt);
 static void gda_statement_dispose (GObject *object);
 
 static void gda_statement_set_property (GObject *object,
@@ -61,14 +59,13 @@ static void gda_statement_get_property (GObject *object,
                                        guint param_id,
                                        GValue *value,
                                        GParamSpec *pspec);
-/* get a pointer to the parents to be able to call their destructor */
-static GObjectClass  *parent_class = NULL;
 
 typedef struct {
        GdaSqlStatement *internal_struct;
        GType           *requested_types;
 } GdaStatementPrivate;
-#define gda_statement_get_instance_private(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, GDA_TYPE_STATEMENT, 
GdaStatementPrivate)
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaStatement, gda_statement, G_TYPE_OBJECT)
 /* signals */
 enum
 {
@@ -96,41 +93,10 @@ GQuark gda_statement_error_quark (void)
 }
 
 
-GType
-gda_statement_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               static const GTypeInfo info = {
-                       sizeof (GdaStatementClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gda_statement_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdaStatement),
-                       0,
-                       (GInstanceInitFunc) gda_statement_init,
-                       0
-               };
-               
-               g_mutex_lock (&registering);
-               if (type == 0)
-                       type = g_type_register_static (G_TYPE_OBJECT, "GdaStatement", &info, 0);
-               g_mutex_unlock (&registering);
-       }
-       return type;
-}
-
 static void
 gda_statement_class_init (GdaStatementClass * klass)
 {
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
-       parent_class = g_type_class_peek_parent (klass);
-
-       g_type_class_add_private (object_class, sizeof (GdaStatementPrivate));
 
        /**
         * GdaStatement::reset:
@@ -249,7 +215,7 @@ gda_statement_dispose (GObject *object)
        }
 
        /* parent class */
-       parent_class->dispose (object);
+       G_OBJECT_CLASS (gda_statement_parent_class)->dispose (object);
 }
 
 static void
@@ -262,8 +228,7 @@ gda_statement_set_property (GObject *object,
 
        stmt = GDA_STATEMENT (object);
        GdaStatementPrivate *priv = gda_statement_get_instance_private (stmt);
-       if (priv) {
-               switch (param_id) {
+       switch (param_id) {
                case PROP_STRUCTURE:
                        if (priv->internal_struct) {
                                gda_sql_statement_free (priv->internal_struct);
@@ -279,7 +244,6 @@ gda_statement_set_property (GObject *object,
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-               }
        }
 }
 
@@ -292,16 +256,14 @@ gda_statement_get_property (GObject *object,
        GdaStatement *stmt;
        stmt = GDA_STATEMENT (object);
        GdaStatementPrivate *priv = gda_statement_get_instance_private (stmt);
-       
-       if (priv) {
-               switch (param_id) {
+
+       switch (param_id) {
                case PROP_STRUCTURE:
                        g_value_set_pointer (value, gda_sql_statement_copy (priv->internal_struct));
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-               }       
        }
 }
 
diff --git a/libgda/gda-statement.h b/libgda/gda-statement.h
index c9f51d26e..06c5f43e6 100644
--- a/libgda/gda-statement.h
+++ b/libgda/gda-statement.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2018 Daniel Espinosa <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,11 +27,6 @@
 
 G_BEGIN_DECLS
 
-#define GDA_TYPE_STATEMENT          (gda_statement_get_type())
-#define GDA_STATEMENT(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, gda_statement_get_type(), GdaStatement)
-#define GDA_STATEMENT_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, gda_statement_get_type (), 
GdaStatementClass)
-#define GDA_IS_STATEMENT(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gda_statement_get_type ())
-
 /* error reporting */
 extern GQuark gda_statement_error_quark (void);
 #define GDA_STATEMENT_ERROR gda_statement_error_quark ()
@@ -102,11 +98,9 @@ typedef enum {
         GDA_STATEMENT_SQL_TIMEZONE_TO_GMT    = 1 << 7
 } GdaStatementSqlFlag;
 
-/* struct for the object's data */
-struct _GdaStatement
-{
-       GObject              object;
-};
+
+#define GDA_TYPE_STATEMENT          (gda_statement_get_type())
+G_DECLARE_DERIVABLE_TYPE(GdaStatement, gda_statement, GDA, STATEMENT, GObject)
 
 /* struct for the object's class */
 struct _GdaStatementClass
@@ -148,7 +142,6 @@ struct _GdaStatementClass
  *  Note that it is possible to use the same #GdaStatement object at the same time with several 
#GdaConnection objects.
  */
 
-GType               gda_statement_get_type               (void) G_GNUC_CONST;
 GdaStatement       *gda_statement_new                    (void);
 GdaStatement       *gda_statement_copy                   (GdaStatement *orig);
 


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