[libgda] gda-tree-mgr-columns: ported to G_DECLARE/G_DEFINE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] gda-tree-mgr-columns: ported to G_DECLARE/G_DEFINE
- Date: Thu, 20 Sep 2018 00:23:16 +0000 (UTC)
commit e34a9f6208b11f5a1ddf5f4b297c54433d4bfba8
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Sep 19 14:46:53 2018 -0500
gda-tree-mgr-columns: ported to G_DECLARE/G_DEFINE
libgda/gda-tree-mgr-columns.c | 173 +++++++++++++++++-------------------------
libgda/gda-tree-mgr-columns.h | 18 +----
2 files changed, 71 insertions(+), 120 deletions(-)
---
diff --git a/libgda/gda-tree-mgr-columns.c b/libgda/gda-tree-mgr-columns.c
index 156cd4e17..5ce0a1172 100644
--- a/libgda/gda-tree-mgr-columns.c
+++ b/libgda/gda-tree-mgr-columns.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
+ * 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
@@ -24,7 +25,7 @@
#include "gda-tree-mgr-columns.h"
#include "gda-tree-node.h"
-struct _GdaTreeMgrColumnsPriv {
+typedef struct {
GdaConnection *cnc;
GdaMetaStore *mstore;
gchar *schema; /* imposed upon construction */
@@ -32,10 +33,10 @@ struct _GdaTreeMgrColumnsPriv {
GdaStatement *stmt;
GdaSet *params;
-};
+} GdaTreeMgrColumnsPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdaTreeMgrColumns, gda_tree_mgr_columns, GDA_TYPE_TREE_MANAGER)
-static void gda_tree_mgr_columns_class_init (GdaTreeMgrColumnsClass *klass);
-static void gda_tree_mgr_columns_init (GdaTreeMgrColumns *tmgr1, GdaTreeMgrColumnsClass *klass);
static void gda_tree_mgr_columns_dispose (GObject *object);
static void gda_tree_mgr_columns_set_property (GObject *object,
guint param_id,
@@ -50,8 +51,6 @@ static void gda_tree_mgr_columns_get_property (GObject *object,
static GSList *gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node,
const GSList *children_nodes, gboolean *out_error,
GError **error);
-static GObjectClass *parent_class = NULL;
-
/* properties */
enum {
PROP_0,
@@ -70,8 +69,6 @@ gda_tree_mgr_columns_class_init (GdaTreeMgrColumnsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
/* virtual methods */
((GdaTreeManagerClass*) klass)->update_children = gda_tree_mgr_columns_update_children;
@@ -128,11 +125,7 @@ gda_tree_mgr_columns_class_init (GdaTreeMgrColumnsClass *klass)
}
static void
-gda_tree_mgr_columns_init (GdaTreeMgrColumns *mgr, G_GNUC_UNUSED GdaTreeMgrColumnsClass *klass)
-{
- g_return_if_fail (GDA_IS_TREE_MGR_COLUMNS (mgr));
- mgr->priv = g_new0 (GdaTreeMgrColumnsPriv, 1);
-}
+gda_tree_mgr_columns_init (GdaTreeMgrColumns *mgr) {}
static void
gda_tree_mgr_columns_dispose (GObject *object)
@@ -140,61 +133,34 @@ gda_tree_mgr_columns_dispose (GObject *object)
GdaTreeMgrColumns *mgr = (GdaTreeMgrColumns *) object;
g_return_if_fail (GDA_IS_TREE_MGR_COLUMNS (mgr));
+ GdaTreeMgrColumnsPrivate *priv = gda_tree_mgr_columns_get_instance_private (mgr);
- if (mgr->priv) {
- if (mgr->priv->cnc)
- g_object_unref (mgr->priv->cnc);
- if (mgr->priv->mstore)
- g_object_unref (mgr->priv->mstore);
- g_free (mgr->priv->schema);
- g_free (mgr->priv->table_name);
-
- if (mgr->priv->stmt)
- g_object_unref (mgr->priv->stmt);
- if (mgr->priv->params)
- g_object_unref (mgr->priv->params);
-
- g_free (mgr->priv);
- mgr->priv = NULL;
+ if (priv) {
+ if (priv->cnc) {
+ g_object_unref (priv->cnc);
+ priv->cnc = NULL;
+ }
+ if (priv->mstore) {
+ g_object_unref (priv->mstore);
+ priv->mstore = NULL;
+ }
+ g_free (priv->schema);
+ priv->schema = NULL;
+ g_free (priv->table_name);
+ priv->table_name = NULL;
+
+ if (priv->stmt) {
+ g_object_unref (priv->stmt);
+ priv->stmt = NULL;
+ }
+ if (priv->params) {
+ g_object_unref (priv->params);
+ priv->params = NULL;
+ }
}
/* chain to parent class */
- parent_class->dispose (object);
-}
-
-/**
- * gda_tree_mgr_columns_get_type:
- *
- * Returns: the GType
- *
- * Since: 4.2
- */
-GType
-gda_tree_mgr_columns_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static const GTypeInfo info = {
- sizeof (GdaTreeMgrColumnsClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_tree_mgr_columns_class_init,
- NULL,
- NULL,
- sizeof (GdaTreeMgrColumns),
- 0,
- (GInstanceInitFunc) gda_tree_mgr_columns_init,
- 0
- };
-
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (GDA_TYPE_TREE_MANAGER, "GdaTreeMgrColumns", &info, 0);
- g_mutex_unlock (®istering);
- }
- return type;
+ G_OBJECT_CLASS (gda_tree_mgr_columns_parent_class)->dispose (object);
}
static void
@@ -203,32 +169,31 @@ gda_tree_mgr_columns_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GdaTreeMgrColumns *mgr;
+ GdaTreeMgrColumns *mgr;
- mgr = GDA_TREE_MGR_COLUMNS (object);
- if (mgr->priv) {
- switch (param_id) {
+ mgr = GDA_TREE_MGR_COLUMNS (object);
+ GdaTreeMgrColumnsPrivate *priv = gda_tree_mgr_columns_get_instance_private (mgr);
+ switch (param_id) {
case PROP_CNC:
- mgr->priv->cnc = (GdaConnection*) g_value_get_object (value);
- if (mgr->priv->cnc)
- g_object_ref (mgr->priv->cnc);
+ priv->cnc = (GdaConnection*) g_value_get_object (value);
+ if (priv->cnc)
+ g_object_ref (priv->cnc);
break;
case PROP_META_STORE:
- mgr->priv->mstore = (GdaMetaStore*) g_value_get_object (value);
- if (mgr->priv->mstore)
- g_object_ref (mgr->priv->mstore);
+ priv->mstore = (GdaMetaStore*) g_value_get_object (value);
+ if (priv->mstore)
+ g_object_ref (priv->mstore);
break;
case PROP_SCHEMA:
- mgr->priv->schema = g_value_dup_string (value);
+ priv->schema = g_value_dup_string (value);
break;
case PROP_TABLE:
- mgr->priv->table_name = g_value_dup_string (value);
+ priv->table_name = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
- }
- }
+ }
}
static void
@@ -237,28 +202,27 @@ gda_tree_mgr_columns_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GdaTreeMgrColumns *mgr;
+ GdaTreeMgrColumns *mgr;
- mgr = GDA_TREE_MGR_COLUMNS (object);
- if (mgr->priv) {
- switch (param_id) {
+ mgr = GDA_TREE_MGR_COLUMNS (object);
+ GdaTreeMgrColumnsPrivate *priv = gda_tree_mgr_columns_get_instance_private (mgr);
+ switch (param_id) {
case PROP_CNC:
- g_value_set_object (value, mgr->priv->cnc);
+ g_value_set_object (value, priv->cnc);
break;
case PROP_META_STORE:
- g_value_set_object (value, mgr->priv->mstore);
+ g_value_set_object (value, priv->mstore);
break;
case PROP_SCHEMA:
- g_value_set_string (value, mgr->priv->schema);
+ g_value_set_string (value, priv->schema);
break;
case PROP_TABLE:
- g_value_set_string (value, mgr->priv->table_name);
+ g_value_set_string (value, priv->table_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
- }
- }
+ }
}
/**
@@ -296,23 +260,24 @@ gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node
GdaDataModel *model;
GSList *list = NULL;
GdaConnection *scnc;
+ GdaTreeMgrColumnsPrivate *priv = gda_tree_mgr_columns_get_instance_private (mgr);
- if (!mgr->priv->cnc && !mgr->priv->mstore) {
+ if (!priv->cnc && !priv->mstore) {
g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
"%s", _("No connection and no GdaMetaStore specified"));
if (out_error)
*out_error = TRUE;
return NULL;
}
- else if (mgr->priv->mstore)
- store = mgr->priv->mstore;
+ else if (priv->mstore)
+ store = priv->mstore;
else
- store = gda_connection_get_meta_store (mgr->priv->cnc);
+ store = gda_connection_get_meta_store (priv->cnc);
scnc = gda_meta_store_get_internal_connection (store);
/* create statements if necessary */
- if (!mgr->priv->stmt) {
+ if (!priv->stmt) {
GdaSqlParser *parser;
GdaStatement *stmt;
@@ -332,34 +297,34 @@ gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node
return NULL;
}
- if (!gda_statement_get_parameters (stmt, &(mgr->priv->params), error)) {
+ if (!gda_statement_get_parameters (stmt, &(priv->params), error)) {
if (out_error)
*out_error = TRUE;
g_object_unref (stmt);
return NULL;
}
- mgr->priv->stmt = stmt;
+ priv->stmt = stmt;
}
gboolean schema_specified = FALSE;
gboolean table_specified = FALSE;
- if (mgr->priv->schema) {
+ if (priv->schema) {
schema_specified = TRUE;
- g_assert (gda_set_set_holder_value (mgr->priv->params, NULL, "schema",
- mgr->priv->schema));
+ g_assert (gda_set_set_holder_value (priv->params, NULL, "schema",
+ priv->schema));
}
- if (mgr->priv->table_name) {
+ if (priv->table_name) {
table_specified = TRUE;
- g_assert (gda_set_set_holder_value (mgr->priv->params, NULL, "table_name",
- mgr->priv->table_name));
+ g_assert (gda_set_set_holder_value (priv->params, NULL, "table_name",
+ priv->table_name));
}
if (!schema_specified && node) {
/* looking for a schema in @node's attributes */
const GValue *cvalue;
cvalue = gda_tree_node_fetch_attribute (node, "schema");
if (cvalue) {
- GdaHolder *h = gda_set_get_holder (mgr->priv->params, "schema");
+ GdaHolder *h = gda_set_get_holder (priv->params, "schema");
if (!gda_holder_set_value (h, cvalue, error)) {
if (out_error)
*out_error = TRUE;
@@ -373,7 +338,7 @@ gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node
const GValue *cvalue;
cvalue = gda_tree_node_fetch_attribute (node, "table_name");
if (cvalue) {
- GdaHolder *h = gda_set_get_holder (mgr->priv->params, "table_name");
+ GdaHolder *h = gda_set_get_holder (priv->params, "table_name");
if (!gda_holder_set_value (h, cvalue, error)) {
if (out_error)
*out_error = TRUE;
@@ -399,7 +364,7 @@ gda_tree_mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node
return NULL;
}
- model = gda_connection_statement_execute_select (scnc, mgr->priv->stmt, mgr->priv->params, error);
+ model = gda_connection_statement_execute_select (scnc, priv->stmt, priv->params, error);
if (!model) {
if (out_error)
diff --git a/libgda/gda-tree-mgr-columns.h b/libgda/gda-tree-mgr-columns.h
index a330c860d..0819ac791 100644
--- a/libgda/gda-tree-mgr-columns.h
+++ b/libgda/gda-tree-mgr-columns.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009 - 2011 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,21 +27,7 @@
G_BEGIN_DECLS
#define GDA_TYPE_TREE_MGR_COLUMNS (gda_tree_mgr_columns_get_type())
-#define GDA_TREE_MGR_COLUMNS(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_TREE_MGR_COLUMNS,
GdaTreeMgrColumns))
-#define GDA_TREE_MGR_COLUMNS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_TREE_MGR_COLUMNS,
GdaTreeMgrColumnsClass))
-#define GDA_IS_TREE_MGR_COLUMNS(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_TREE_MGR_COLUMNS))
-#define GDA_IS_TREE_MGR_COLUMNS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_TREE_MGR_COLUMNS))
-#define GDA_TREE_MGR_COLUMNS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDA_TYPE_TREE_MGR_COLUMNS,
GdaTreeMgrColumnsClass))
-
-typedef struct _GdaTreeMgrColumns GdaTreeMgrColumns;
-typedef struct _GdaTreeMgrColumnsPriv GdaTreeMgrColumnsPriv;
-typedef struct _GdaTreeMgrColumnsClass GdaTreeMgrColumnsClass;
-
-struct _GdaTreeMgrColumns {
- GdaTreeManager object;
- GdaTreeMgrColumnsPriv *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE(GdaTreeMgrColumns, gda_tree_mgr_columns, GDA, TREE_MGR_COLUMNS, GdaTreeManager)
struct _GdaTreeMgrColumnsClass {
GdaTreeManagerClass object_class;
};
@@ -65,7 +52,6 @@ struct _GdaTreeMgrColumnsClass {
* gda_tree_node_fetch_attribute()).
*/
-GType gda_tree_mgr_columns_get_type (void) G_GNUC_CONST;
GdaTreeManager* gda_tree_mgr_columns_new (GdaConnection *cnc, const gchar *schema,
const gchar *table_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]