[libgda] GdaCapiRecordset: Ported to G_DEFINE/G_DECLARE
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaCapiRecordset: Ported to G_DEFINE/G_DECLARE
- Date: Thu, 4 Apr 2019 19:49:49 +0000 (UTC)
commit 8ae318c8b2139d56d8d39dd6b2f4fe4cf1e9e475
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Apr 4 13:09:55 2019 -0600
GdaCapiRecordset: Ported to G_DEFINE/G_DECLARE
.../skel-implementation/capi/gda-capi-recordset.c | 85 +++++++---------------
.../skel-implementation/capi/gda-capi-recordset.h | 16 +---
2 files changed, 26 insertions(+), 75 deletions(-)
---
diff --git a/providers/skel-implementation/capi/gda-capi-recordset.c
b/providers/skel-implementation/capi/gda-capi-recordset.c
index 104749a91..d87c5d4db 100644
--- a/providers/skel-implementation/capi/gda-capi-recordset.c
+++ b/providers/skel-implementation/capi/gda-capi-recordset.c
@@ -35,8 +35,7 @@
#define _GDA_PSTMT(x) ((GdaPStmt*)(x))
static void gda_capi_recordset_class_init (GdaCapiRecordsetClass *klass);
-static void gda_capi_recordset_init (GdaCapiRecordset *recset,
- GdaCapiRecordsetClass *klass);
+static void gda_capi_recordset_init (GdaCapiRecordset *recset);
static void gda_capi_recordset_dispose (GObject *object);
/* virtual methods */
@@ -47,22 +46,21 @@ static gboolean gda_capi_recordset_fetch_prev (GdaDataSelect *model, GdaRow **pr
static gboolean gda_capi_recordset_fetch_at (GdaDataSelect *model, GdaRow **prow, gint rownum, GError
**error);
-struct _GdaCapiRecordsetPrivate {
+typedef struct {
GdaConnection *cnc;
/* TO_ADD: specific information */
-};
-static GObjectClass *parent_class = NULL;
+} GdaCapiRecordsetPrivate;
+G_DEFINE_TYPE_WITH_PRIVATE (GdaCapiRecordset, gda_capi_recordset, GDA_TYPE_DATA_SELECT)
/*
* Object init and finalize
*/
static void
-gda_capi_recordset_init (GdaCapiRecordset *recset,
- G_GNUC_UNUSED GdaCapiRecordsetClass *klass)
+gda_capi_recordset_init (GdaCapiRecordset *recset)
{
g_return_if_fail (GDA_IS_CAPI_RECORDSET (recset));
- recset->priv = g_new0 (GdaCapiRecordsetPrivate, 1);
- recset->priv->cnc = NULL;
+ GdaCapiRecordsetPrivate *priv = gda_capi_recordset_get_instance_private (recset);
+ priv->cnc = NULL;
/* initialize specific information */
TO_IMPLEMENT;
@@ -74,8 +72,6 @@ gda_capi_recordset_class_init (GdaCapiRecordsetClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdaDataSelectClass *pmodel_class = GDA_DATA_SELECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->dispose = gda_capi_recordset_dispose;
pmodel_class->fetch_nb_rows = gda_capi_recordset_fetch_nb_rows;
pmodel_class->fetch_random = gda_capi_recordset_fetch_random;
@@ -91,51 +87,19 @@ gda_capi_recordset_dispose (GObject *object)
GdaCapiRecordset *recset = (GdaCapiRecordset *) object;
g_return_if_fail (GDA_IS_CAPI_RECORDSET (recset));
+ GdaCapiRecordsetPrivate *priv = gda_capi_recordset_get_instance_private (recset);
- if (recset->priv) {
- if (recset->priv->cnc)
- g_object_unref (recset->priv->cnc);
+ if (priv->cnc)
+ g_object_unref (priv->cnc);
- /* free specific information */
- TO_IMPLEMENT;
- g_free (recset->priv);
- recset->priv = NULL;
- }
+ /* free specific information */
+ TO_IMPLEMENT;
+ g_free (priv);
+ priv = NULL;
- parent_class->dispose (object);
+ G_OBJECT_CLASS (gda_capi_recordset_parent_class)->dispose (object);
}
-/*
- * Public functions
- */
-
-GType
-gda_capi_recordset_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0)) {
- static GMutex registering;
- static const GTypeInfo info = {
- sizeof (GdaCapiRecordsetClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_capi_recordset_class_init,
- NULL,
- NULL,
- sizeof (GdaCapiRecordset),
- 0,
- (GInstanceInitFunc) gda_capi_recordset_init,
- 0
- };
- g_mutex_lock (®istering);
- if (type == 0)
- type = g_type_register_static (GDA_TYPE_DATA_SELECT, "GdaCapiRecordset", &info, 0);
- g_mutex_unlock (®istering);
- }
-
- return type;
-}
/*
* the @ps struct is modified and transferred to the new data model created in
@@ -146,12 +110,12 @@ gda_capi_recordset_new (GdaConnection *cnc, GdaCapiPStmt *ps, GdaSet *exec_param
GdaDataModelAccessFlags flags, GType *col_types)
{
GdaCapiRecordset *model;
- CapiConnectionData *cdata;
- gint i;
+ CapiConnectionData *cdata;
+ gint i;
GdaDataModelAccessFlags rflags;
- g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
- g_return_val_if_fail (ps != NULL, NULL);
+ g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+ g_return_val_if_fail (ps != NULL, NULL);
cdata = (CapiConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL);
if (!cdata)
@@ -213,11 +177,12 @@ gda_capi_recordset_new (GdaConnection *cnc, GdaCapiPStmt *ps, GdaSet *exec_param
rflags = GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD;
/* create data model */
- model = g_object_new (GDA_TYPE_CAPI_RECORDSET,
- "prepared-stmt", ps,
- "model-usage", rflags,
- "exec-params", exec_params, NULL);
- model->priv->cnc = cnc;
+ model = g_object_new (GDA_TYPE_CAPI_RECORDSET,
+ "prepared-stmt", ps,
+ "model-usage", rflags,
+ "exec-params", exec_params, NULL);
+ GdaCapiRecordsetPrivate *priv = gda_capi_recordset_get_instance_private (model);
+ priv->cnc = cnc;
g_object_ref (cnc);
/* post init specific code */
diff --git a/providers/skel-implementation/capi/gda-capi-recordset.h
b/providers/skel-implementation/capi/gda-capi-recordset.h
index d96620481..748b856b8 100644
--- a/providers/skel-implementation/capi/gda-capi-recordset.h
+++ b/providers/skel-implementation/capi/gda-capi-recordset.h
@@ -31,25 +31,11 @@
G_BEGIN_DECLS
#define GDA_TYPE_CAPI_RECORDSET (gda_capi_recordset_get_type())
-#define GDA_CAPI_RECORDSET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_CAPI_RECORDSET,
GdaCapiRecordset))
-#define GDA_CAPI_RECORDSET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_CAPI_RECORDSET,
GdaCapiRecordsetClass))
-#define GDA_IS_CAPI_RECORDSET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_CAPI_RECORDSET))
-#define GDA_IS_CAPI_RECORDSET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_CAPI_RECORDSET))
-
-typedef struct _GdaCapiRecordset GdaCapiRecordset;
-typedef struct _GdaCapiRecordsetClass GdaCapiRecordsetClass;
-typedef struct _GdaCapiRecordsetPrivate GdaCapiRecordsetPrivate;
-
-struct _GdaCapiRecordset {
- GdaDataSelect model;
- GdaCapiRecordsetPrivate *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE (GdaCapiRecordset, gda_capi_recordset, GDA, CAPI_RECORDSET, GdaDataSelect)
struct _GdaCapiRecordsetClass {
GdaDataSelectClass parent_class;
};
-GType gda_capi_recordset_get_type (void) G_GNUC_CONST;
GdaDataModel *gda_capi_recordset_new (GdaConnection *cnc, GdaCapiPStmt *ps, GdaSet *exec_params,
GdaDataModelAccessFlags flags, GType *col_types);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]