[libgda] GdaColumn: removed GdaAttributesManager
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaColumn: removed GdaAttributesManager
- Date: Mon, 11 Feb 2019 04:26:37 +0000 (UTC)
commit 88f8ca280fb8895a8d8f9c84d17a140842a68724
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Sun Feb 10 22:14:40 2019 -0600
GdaColumn: removed GdaAttributesManager
libgda/gda-column.c | 203 +++++++++++++++++++------------------------
libgda/gda-column.h | 3 -
libgda/gda-data-model-iter.c | 3 -
3 files changed, 88 insertions(+), 121 deletions(-)
---
diff --git a/libgda/gda-column.c b/libgda/gda-column.c
index 2e274be25..eb9edea72 100644
--- a/libgda/gda-column.c
+++ b/libgda/gda-column.c
@@ -46,6 +46,8 @@ typedef struct {
glong auto_increment_step;
gint position;
GValue *default_value;
+ gchar *name;
+ gchar *desc;
} GdaColumnPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(GdaColumn,gda_column,G_TYPE_OBJECT)
@@ -75,12 +77,12 @@ static guint gda_column_signals[LAST_SIGNAL] = {0 , 0};
/* properties */
enum
{
- PROP_0,
- PROP_ID,
+ PROP_0,
+ PROP_ID,
+ PROP_NAME,
+ PROP_DESC
};
-GdaAttributesManager *_gda_column_attributes_manager;
-
static void
gda_column_class_init (GdaColumnClass *klass)
{
@@ -125,16 +127,23 @@ gda_column_class_init (GdaColumnClass *klass)
object_class->set_property = gda_column_set_property;
object_class->get_property = gda_column_get_property;
- g_object_class_install_property (object_class, PROP_ID,
- g_param_spec_string ("id", NULL,
- "Column's Id (warning: the column's ID is not "
- "guaranteed to be unique in a GdaDataModel)",
- NULL, G_PARAM_WRITABLE | G_PARAM_READABLE));
+ g_object_class_install_property (object_class, PROP_ID,
+ g_param_spec_string ("id", NULL,
+ "Column's Id (warning: the column's ID is not guaranteed to be
unique in a GdaDataModel)",
+ NULL, G_PARAM_WRITABLE | G_PARAM_READABLE));
- object_class->finalize = gda_column_finalize;
- /* extra */
- _gda_column_attributes_manager = gda_attributes_manager_new (TRUE, NULL, NULL);
+ g_object_class_install_property (object_class, PROP_NAME,
+ g_param_spec_string ("name", NULL,
+ "Column's name",
+ NULL, G_PARAM_WRITABLE | G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class, PROP_DESC,
+ g_param_spec_string ("desc", NULL,
+ "Column's description",
+ NULL, G_PARAM_WRITABLE | G_PARAM_READABLE));
+
+ object_class->finalize = gda_column_finalize;
}
static void
@@ -152,6 +161,8 @@ gda_column_init (GdaColumn *column)
priv->auto_increment_step = 0;
priv->position = -1;
priv->default_value = NULL;
+ priv->name = NULL;
+ priv->desc = NULL;
}
static void
@@ -164,8 +175,22 @@ gda_column_finalize (GObject *object)
gda_value_free (priv->default_value);
- g_free (priv->id);
- g_free (priv->dbms_type);
+ if (priv->id != NULL) {
+ g_free (priv->id);
+ priv->id = NULL;
+ }
+ if (priv->dbms_type != NULL) {
+ g_free (priv->dbms_type);
+ priv->dbms_type = NULL;
+ }
+ if (priv->name != NULL) {
+ g_free (priv->name);
+ priv->name = NULL;
+ }
+ if (priv->desc != NULL) {
+ g_free (priv->desc);
+ priv->desc = NULL;
+ }
G_OBJECT_CLASS (gda_column_parent_class)->finalize (object);
}
@@ -183,12 +208,32 @@ gda_column_set_property (GObject *object,
GdaColumnPrivate *priv = gda_column_get_instance_private (col);
switch (param_id) {
case PROP_ID:
- g_free (priv->id);
+ if (priv->id != NULL) {
+ g_free (priv->id);
+ }
if (g_value_get_string (value))
priv->id = g_strdup (g_value_get_string (value));
else
priv->id = NULL;
break;
+ case PROP_NAME:
+ if (priv->name != NULL) {
+ g_free (priv->name);
+ }
+ if (g_value_get_string (value))
+ priv->name = g_strdup (g_value_get_string (value));
+ else
+ priv->name = NULL;
+ break;
+ case PROP_DESC:
+ if (priv->desc != NULL) {
+ g_free (priv->desc);
+ }
+ if (g_value_get_string (value))
+ priv->desc = g_strdup (g_value_get_string (value));
+ else
+ priv->desc = NULL;
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -209,6 +254,12 @@ gda_column_get_property (GObject *object,
case PROP_ID:
g_value_set_string (value, priv->id);
break;
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ case PROP_DESC:
+ g_value_set_string (value, priv->desc);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -248,6 +299,10 @@ gda_column_copy (GdaColumn *column)
cpriv->defined_size = priv->defined_size;
if (priv->id)
cpriv->id = g_strdup (priv->id);
+ if (priv->name)
+ cpriv->name = g_strdup (priv->name);
+ if (priv->desc)
+ cpriv->desc = g_strdup (priv->desc);
cpriv->g_type = priv->g_type;
cpriv->allow_null = priv->allow_null;
cpriv->auto_increment = priv->auto_increment;
@@ -256,9 +311,8 @@ gda_column_copy (GdaColumn *column)
cpriv->position = priv->position;
if (priv->default_value)
cpriv->default_value = gda_value_copy (priv->default_value);
- gda_attributes_manager_copy (_gda_column_attributes_manager, (gpointer) column,
_gda_column_attributes_manager, (gpointer) column_copy);
- return column_copy;
+ return column_copy;
}
/**
@@ -270,13 +324,11 @@ gda_column_copy (GdaColumn *column)
const gchar *
gda_column_get_name (GdaColumn *column)
{
- const GValue *cvalue;
+ g_return_val_if_fail (column != NULL, NULL);
g_return_val_if_fail (GDA_IS_COLUMN (column), NULL);
- cvalue = gda_column_get_attribute (column, GDA_ATTRIBUTE_NAME);
- if (cvalue)
- return g_value_get_string (cvalue);
- else
- return NULL;
+
+ GdaColumnPrivate *priv = gda_column_get_instance_private (column);
+ return priv->name;
}
/**
@@ -289,27 +341,12 @@ gda_column_get_name (GdaColumn *column)
void
gda_column_set_name (GdaColumn *column, const gchar *name)
{
- const gchar *old_name = NULL;
- gchar *nname = NULL;
- GValue *value = NULL;
-
+ g_return_if_fail (column != NULL);
+ g_return_if_fail (name != NULL);
g_return_if_fail (GDA_IS_COLUMN (column));
- old_name = gda_column_get_name (column);
- if (old_name)
- nname = g_strdup (old_name);
-
- if (name)
- g_value_set_string ((value = gda_value_new (G_TYPE_STRING)), name);
- gda_column_set_attribute_static (column, GDA_ATTRIBUTE_NAME, value);
- if (value)
- gda_value_free (value);
-
- g_signal_emit (G_OBJECT (column),
- gda_column_signals[NAME_CHANGED],
- 0, nname);
-
- g_free (nname);
+ GdaColumnPrivate *priv = gda_column_get_instance_private (column);
+ priv->name = g_strdup (name);
}
/**
@@ -321,34 +358,29 @@ gda_column_set_name (GdaColumn *column, const gchar *name)
const gchar *
gda_column_get_description (GdaColumn *column)
{
- const GValue *cvalue;
+ g_return_val_if_fail (column != NULL, NULL);
g_return_val_if_fail (GDA_IS_COLUMN (column), NULL);
- cvalue = gda_column_get_attribute (column, GDA_ATTRIBUTE_DESCRIPTION);
- if (cvalue)
- return g_value_get_string (cvalue);
- else
- return NULL;
+
+ GdaColumnPrivate *priv = gda_column_get_instance_private (column);
+ return priv->desc;
}
/**
* gda_column_set_description:
* @column: a #GdaColumn.
- * @title: title name.
+ * @descr: description.
*
* Sets the column's description
*/
void
gda_column_set_description (GdaColumn *column, const gchar *descr)
{
- GValue *value = NULL;
-
+ g_return_if_fail (column != NULL);
+ g_return_if_fail (descr != NULL);
g_return_if_fail (GDA_IS_COLUMN (column));
- if (descr)
- g_value_set_string ((value = gda_value_new (G_TYPE_STRING)), descr);
- gda_column_set_attribute_static (column, GDA_ATTRIBUTE_DESCRIPTION, value);
- if (value)
- gda_value_free (value);
+ GdaColumnPrivate *priv = gda_column_get_instance_private (column);
+ priv->desc = g_strdup (descr);
}
/**
@@ -549,62 +581,3 @@ gda_column_set_default_value (GdaColumn *column, const GValue *default_value)
priv->default_value = NULL;
}
-/**
- * gda_column_get_attribute:
- * @column: a #GdaColumn
- * @attribute: attribute name as a string
- *
- * Get the value associated to a named attribute.
- *
- * Attributes can have any name, but Libgda proposes some default names, see <link
linkend="libgda-40-Attributes-manager.synopsis">this section</link>.
- *
- * Returns: a read-only #GValue, or %NULL if not attribute named @attribute has been set for @column
- */
-const GValue *
-gda_column_get_attribute (GdaColumn *column, const gchar *attribute)
-{
- g_return_val_if_fail (GDA_IS_COLUMN (column), NULL);
- return gda_attributes_manager_get (_gda_column_attributes_manager, column, attribute);
-}
-
-/**
- * gda_column_set_attribute:
- * @column: a #GdaColumn
- * @attribute: attribute name as a static string
- * @value: (nullable): a #GValue, or %NULL
- * @destroy: (nullable): a function to be called when @attribute is not needed anymore, or %NULL
- *
- * Set the value associated to a named attribute. The @attribute string is 'stolen' by this method, and
- * the memory it uses will be freed using the @destroy function when no longer needed (if @destroy is %NULL,
- * then the string will not be freed at all).
- *
- * Attributes can have any name, but Libgda proposes some default names,
- * see <link linkend="libgda-40-Attributes-manager.synopsis">this section</link>.
- *
- * If there is already an attribute named @attribute set, then its value is replaced with the new value
(@value is
- * copied), except if @value is %NULL, in which case the attribute is removed.
- *
- * For example one would use it as:
- *
- * <code>
- * gda_column_set_attribute (holder, g_strdup (my_attribute), g_free, my_value);
- * gda_column_set_attribute (holder, GDA_ATTRIBUTE_NAME, NULL, my_value);
- * </code>
- *
- * Note: this method does not modify in any way the contents of the data model for which @column is a column
(nor
- * does it modify the table definition of the tables used by a SELECT statement is the model was created
from a
- * SELECT statement).
- */
-void
-gda_column_set_attribute (GdaColumn *column, const gchar *attribute, const GValue *value, GDestroyNotify
destroy)
-{
- const GValue *cvalue;
- g_return_if_fail (GDA_IS_COLUMN (column));
-
- cvalue = gda_attributes_manager_get (_gda_column_attributes_manager, column, attribute);
- if ((value && cvalue && !gda_value_differ (cvalue, value)) ||
- (!value && !cvalue))
- return;
-
- gda_attributes_manager_set_full (_gda_column_attributes_manager, column, attribute, value, destroy);
-}
diff --git a/libgda/gda-column.h b/libgda/gda-column.h
index f8748a5e7..f5bba45a5 100644
--- a/libgda/gda-column.h
+++ b/libgda/gda-column.h
@@ -84,9 +84,6 @@ void gda_column_set_position (GdaColumn *column, gint position)
const GValue *gda_column_get_default_value (GdaColumn *column);
void gda_column_set_default_value (GdaColumn *column, const GValue *default_value);
-const GValue *gda_column_get_attribute (GdaColumn *column, const gchar *attribute);
-void gda_column_set_attribute (GdaColumn *column, const gchar *attribute, const GValue
*value,
- GDestroyNotify destroy);
/**
* gda_column_set_attribute_static:
diff --git a/libgda/gda-data-model-iter.c b/libgda/gda-data-model-iter.c
index cdcd5070f..79a302bb3 100644
--- a/libgda/gda-data-model-iter.c
+++ b/libgda/gda-data-model-iter.c
@@ -289,9 +289,6 @@ define_holder_for_data_model_column (GdaDataModel *model, gint col, GdaDataModel
gda_holder_set_default_value (param, v);
gda_value_free (v);
}
- /* copy extra attributes */
- gda_attributes_manager_copy (_gda_column_attributes_manager, (gpointer) column,
- gda_holder_attributes_manager, (gpointer) param);
gda_set_add_holder ((GdaSet *) iter, param);
g_object_set_data (G_OBJECT (param), "model_col", GINT_TO_POINTER (col + 1));
g_object_unref (param);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]