[libgda] GI improvements on GdaDataModel, GdaDataModelIter, GdaHolder, GdaRow and GdaNumeric. Added API to Gd
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GI improvements on GdaDataModel, GdaDataModelIter, GdaHolder, GdaRow and GdaNumeric. Added API to Gd
- Date: Fri, 11 Nov 2011 04:24:18 +0000 (UTC)
commit 3b5c67b0535093c91b32dfa08bb02b9f9b39474b
Author: Daniel Espinosa <despinosa src gnome org>
Date: Thu Nov 10 22:15:17 2011 -0600
GI improvements on GdaDataModel, GdaDataModelIter, GdaHolder, GdaRow and GdaNumeric. Added API to GdaNumeric.
* Added API to GdaNumeric. Now must be considered as opaque
struct
* Added GSEAL() macro as initial work to seal GdaNumeric
* Fixed some GObject Introspection annotations
* Fixed Vala bindings for GdaDataModel, GdaDataModelIter,
GdaHolder, GdaRow and GdaNumeric
libgda/Gda-5.0.metadata | 23 +++++--
libgda/Makefile.am | 3 +-
libgda/gda-data-model.c | 3 +-
libgda/gda-data-proxy.c | 2 +-
libgda/gda-decl.h | 14 ++++
libgda/gda-holder.c | 4 +-
libgda/gda-row.c | 2 +-
libgda/gda-value.c | 172 +++++++++++++++++++++++++++++++++++++++++++++--
libgda/gda-value.h | 26 ++++++--
9 files changed, 225 insertions(+), 24 deletions(-)
---
diff --git a/libgda/Gda-5.0.metadata b/libgda/Gda-5.0.metadata
index 6d63728..1c034d1 100644
--- a/libgda/Gda-5.0.metadata
+++ b/libgda/Gda-5.0.metadata
@@ -1,5 +1,4 @@
// Vala Bindings for GDA
-Gda cheader_filename="libgda/libgda.h"
ServerProviderMeta skip
ServerProviderXa skip
// libxml2: replace xml.NodePtr by xml.Node* used by Vala bindings
@@ -11,11 +10,10 @@ value_new_from_xml.node type="Xml.Node*"
DataModelImport.new_xml_node.node type="Xml.Node*"
ServerOperation.load_data_from_xml.node type="Xml.Node*"
// type overrides for GIR not well detected
-MetaStore.meta_changed.changes type="GLib.SList<Gda.MetaStoreChange>"
-MetaStore.meta_changed.changes out=true
-PStmt.param_ids type="GLib.List<string>"
-PStmt.tmpl_columns type="GLib.List<Gda.Column>"
-ServerProvider.statement_to_sql.params_used type="GLib.List<Gda.Holder>"
+// MetaStore.meta_changed has introspectable="0" property. Removing these metas
+//MetaStore.meta_changed.changes type="GLib.SList<Gda.MetaStoreChange>"
+// ServerProvider.statement_to_sql has introspectable="0" property. Removing these metas
+//ServerProvider.statement_to_sql.params_used type="GLib.List<Gda.Holder>"
Set.groups_list type="GLib.List<Gda.SetGroup>"
Set.nodes_list type="GLib.List<Gda.SetNode>"
Set.sources_list type="GLib.List<Gda.SetSource>"
@@ -27,3 +25,16 @@ MetaTable.fk_list type="GLib.List<Gda.MetaTableForeignKey>"
SetGroup.nodes type="GLib.List<Gda.SetNode>"
SetSource.nodes type="GLib.List<Gda.SetNode>"
SqlRenderingContext.params_used type="GLib.List<Gda.Holder>"
+DataModel.i_get_value_at unowned=true
+DataModel.i_get_value_at nullable=true
+DataModelIter.get_value_at unowned=true
+DataModelIter.get_value_at nullable=true
+DataModelIter.get_value_at_e unowned=true
+DataModelIter.get_value_at_e nullable=true
+DataModelIter.get_value_for_field unowned=true
+DataModelIter.get_value_for_field nullable=true
+Holder.get_value nullable=true
+Row.get_value nullable=true
+Numeric.get_string nullable=true
+//Numeric.number hidden=true
+
diff --git a/libgda/Makefile.am b/libgda/Makefile.am
index bcb895b..e55c963 100644
--- a/libgda/Makefile.am
+++ b/libgda/Makefile.am
@@ -301,7 +301,8 @@ if ENABLE_GDA_GI
INTROSPECTION_GIRS =
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \
--namespace Gda \
- --warn-all
+ --warn-all \
+ --c-include=libgda/libgda.h
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
psupport = \
diff --git a/libgda/gda-data-model.c b/libgda/gda-data-model.c
index dbe4ca4..b0a9306 100644
--- a/libgda/gda-data-model.c
+++ b/libgda/gda-data-model.c
@@ -644,10 +644,11 @@ gda_data_model_set_column_title (GdaDataModel *model, gint col, const gchar *tit
* Upon errors %NULL will be returned and @error will be assigned a
* #GError from the #GDA_DATA_MODEL_ERROR domain.
*
- * Returns: (transfer none): a #GValue containing the value stored in the given
+ * Returns: (allow-none) (transfer none): a #GValue containing the value stored in the given
* position, or %NULL on error (out-of-bound position, etc).
*
* Virtual: i_get_value_at
+ *
*/
const GValue *
gda_data_model_get_value_at (GdaDataModel *model, gint col, gint row, GError **error)
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index 545abf0..459b144 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -1399,7 +1399,7 @@ gda_data_proxy_get_values (GdaDataProxy *proxy, gint proxy_row, gint *cols_index
* Get the attributes of the value stored at (proxy_row, col) in @proxy, which
* is an ORed value of #GdaValueAttribute flags
*
- * Returns: (transfer none): the attribute
+ * Returns: a #GdaValueAttribute with the value's attributes at given position
*/
GdaValueAttribute
gda_data_proxy_get_value_attributes (GdaDataProxy *proxy, gint proxy_row, gint col)
diff --git a/libgda/gda-decl.h b/libgda/gda-decl.h
index 4b72338..abaad41 100644
--- a/libgda/gda-decl.h
+++ b/libgda/gda-decl.h
@@ -135,4 +135,18 @@ typedef struct _GdaTreeNodePrivate GdaTreeNodePrivate;
#define strtok_r(s,d,p) strtok(s,d)
#endif
+/*
+ *
+ */
+#ifndef GSEAL
+
+/* introduce GSEAL() here for all API without the need to modify GDA */
+
+# ifdef GSEAL_ENABLE
+# define GSEAL(ident) _g_sealed__ ## ident
+# else
+# define GSEAL(ident) ident
+# endif
+#endif /* !GSEAL */
+
#endif
diff --git a/libgda/gda-holder.c b/libgda/gda-holder.c
index 0318b77..ecedf45 100644
--- a/libgda/gda-holder.c
+++ b/libgda/gda-holder.c
@@ -767,7 +767,7 @@ gda_holder_get_id (GdaHolder *holder)
*
* If @holder is invalid, then the returned value is %NULL.
*
- * Returns: the value, or %NULL
+ * Returns: (allow-none) (transfer none): the value, or %NULL
*/
const GValue *
gda_holder_get_value (GdaHolder *holder)
@@ -1272,7 +1272,7 @@ real_gda_holder_set_const_value (GdaHolder *holder, const GValue *value,
* of which can prevent the change from happening) which can be connected to to have a greater control
* of which values @holder can have, or implement some business rules.
*
- * Returns: (transfer none): NULL if an error occurred or if the previous GValue was NULL itself. It returns
+ * Returns: NULL if an error occurred or if the previous GValue was NULL itself. It returns
* the static GValue user set previously, so that he can free it.
*/
GValue *
diff --git a/libgda/gda-row.c b/libgda/gda-row.c
index f236b10..445f4fc 100644
--- a/libgda/gda-row.c
+++ b/libgda/gda-row.c
@@ -236,7 +236,7 @@ gda_row_new (gint count)
* This is a pointer to the internal array of values. Don't try to free
* or modify it (modifying is reserved to database provider's implementations).
*
- * Returns: (transfer none): a pointer to the #GValue in the position @num of @row.
+ * Returns: a pointer to the #GValue in the position @num of @row.
*/
GValue *
gda_row_get_value (GdaRow *row, gint num)
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index e462531..7b345d2 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -766,6 +766,36 @@ numeric_to_boolean (const GValue *src, GValue *dest)
g_value_set_boolean (dest, 0);
}
+static void
+numeric_to_double (const GValue *src, GValue *dest)
+{
+ const GdaNumeric *numeric;
+
+ g_return_if_fail (G_VALUE_HOLDS_DOUBLE (dest) &&
+ GDA_VALUE_HOLDS_NUMERIC (src));
+
+ numeric = gda_value_get_numeric (src);
+ if (numeric)
+ g_value_set_double (dest, g_strtod (numeric->number, NULL));
+ else
+ g_value_set_double (dest, 0.0);
+}
+
+static void
+numeric_to_float (const GValue *src, GValue *dest)
+{
+ const GdaNumeric *numeric;
+
+ g_return_if_fail (G_VALUE_HOLDS_FLOAT (dest) &&
+ GDA_VALUE_HOLDS_NUMERIC (src));
+
+ numeric = gda_value_get_numeric (src);
+ if (numeric)
+ g_value_set_float (dest, (float) g_strtod (numeric->number, NULL));
+ else
+ g_value_set_float (dest, 0.0);
+}
+
GType
gda_numeric_get_type (void)
{
@@ -782,6 +812,8 @@ gda_numeric_get_type (void)
g_value_register_transform_func (type, G_TYPE_INT, numeric_to_int);
g_value_register_transform_func (type, G_TYPE_UINT, numeric_to_uint);
g_value_register_transform_func (type, G_TYPE_BOOLEAN, numeric_to_boolean);
+ g_value_register_transform_func (type, G_TYPE_DOUBLE, numeric_to_double);
+ g_value_register_transform_func (type, G_TYPE_FLOAT, numeric_to_float);
}
return type;
@@ -802,15 +834,14 @@ gpointer
gda_numeric_copy (gpointer boxed)
{
GdaNumeric *src = (GdaNumeric*) boxed;
- GdaNumeric *copy = NULL;
+ GdaNumeric *copy;
g_return_val_if_fail (src, NULL);
- copy = g_new0 (GdaNumeric, 1);
- copy->number = g_strdup (src->number);
- copy->precision = src->precision;
- copy->width = src->width;
-
+ copy = gda_numeric_new();
+ gda_numeric_set_from_string(copy, gda_numeric_get_string(src));
+ gda_numeric_set_width(copy, gda_numeric_get_width(src));
+ gda_numeric_set_precision(copy, gda_numeric_get_precision(src));
return copy;
}
@@ -830,7 +861,136 @@ gda_numeric_free (gpointer boxed)
g_free (numeric);
}
+/**
+ * gda_numeric_new:
+ *
+ */
+GdaNumeric*
+gda_numeric_new()
+{
+ GdaNumeric *n = g_new0(GdaNumeric, 1);
+ n->number = g_strdup_printf("0.0");
+ return n;
+}
+/**
+ * gda_numeric_set_from_string:
+ * @numeric: a #GdaNumeric
+ * @number: a string representing a number
+ *
+ *
+ */
+void
+gda_numeric_set_from_string (GdaNumeric *numeric, const gchar* str)
+{
+ g_return_if_fail(numeric);
+ g_return_if_fail(str);
+ if(numeric->number)
+ g_free(numeric->number);
+ numeric->number = g_strdup(str); // FIXME: May a pre-verification is required in order to check string validity
+}
+
+
+/**
+ * gda_numeric_set_double:
+ * @numeric: a #GdaNumeric
+ * @number: a #gdouble
+ *
+ *
+ */
+void
+gda_numeric_set_double (GdaNumeric *numeric, gdouble number)
+{
+ g_return_if_fail(numeric);
+ g_return_if_fail(number);
+ if(numeric->number)
+ g_free(numeric->number);
+ numeric->number = g_strdup_printf("%lf", number);
+}
+
+/**
+ * gda_numeric_get_double:
+ * @numeric: a #GdaNumeric
+ *
+ * Returns: a #gdouble representation of @numeric
+ */
+gdouble
+gda_numeric_get_double (GdaNumeric *numeric)
+{
+ g_return_val_if_fail(numeric, 0.0);
+ if(numeric->number)
+ return atof(numeric->number);
+ else
+ return 0.0;
+}
+
+/**
+ * gda_numeric_set_width:
+ * @numeric: a #GdaNumeric
+ * @number: a #glong
+ *
+ *
+ */
+void
+gda_numeric_set_width (GdaNumeric *numeric, glong width)
+{
+ g_return_if_fail(numeric);
+ numeric->width = width;
+}
+
+/**
+ * gda_numeric_get_width:
+ * @numeric: a #GdaNumeric
+ *
+ * Returns: a #gdouble representation of @numeric
+ */
+glong
+gda_numeric_get_width (GdaNumeric *numeric)
+{
+ g_return_val_if_fail(numeric, 0.0);
+ return numeric->width;
+}
+
+/**
+ * gda_numeric_set_precision:
+ * @numeric: a #GdaNumeric
+ * @number: a #glong
+ *
+ *
+ */
+void
+gda_numeric_set_precision (GdaNumeric *numeric, glong precision)
+{
+ g_return_if_fail(numeric);
+ numeric->precision = precision;
+}
+
+/**
+ * gda_numeric_get_precision:
+ * @numeric: a #GdaNumeric
+ *
+ * Returns: a #gdouble representation of @numeric
+ */
+glong
+gda_numeric_get_precision (GdaNumeric *numeric)
+{
+ g_return_val_if_fail(numeric, -1);
+ return numeric->precision;
+}
+/**
+ * gda_numeric_get_string:
+ * @numeric: a #GdaNumeric
+ *
+ * Get the string representation of @numeric.
+ *
+ * Returns: (transfer full) (allow-none): a new string representing the stored valued in @numeric
+ */
+gchar*
+gda_numeric_get_string (GdaNumeric *numeric)
+{
+ g_return_val_if_fail(numeric, NULL);
+ return g_strdup(numeric->number);
+}
/*
* Register the GdaTime type in the GType system
diff --git a/libgda/gda-value.h b/libgda/gda-value.h
index 9a0d193..cf78bd9 100644
--- a/libgda/gda-value.h
+++ b/libgda/gda-value.h
@@ -76,14 +76,19 @@ typedef struct {
/**
* GdaNumeric:
- * @number:
- * @precision:
- * @width:
+ * @number: a string representing a number
+ * @precision: precision to use when @number is converted (not implemented jet)
+ * @width: (not implemented jet)
+ *
+ * Holds numbers represented as strings.
+ *
+ * Set value func: gda_value_set_numeric
+ * Get value func: gda_value_get_numeric
*/
typedef struct {
- gchar *number;
- glong precision;
- glong width;
+ gchar* GSEAL(number);
+ glong GSEAL(precision);
+ glong GSEAL(width);
/*< private >*/
gpointer reserved; /* reserved for future usage with GMP (http://gmplib.org/) */
@@ -255,7 +260,16 @@ GdaBlob *gda_string_to_blob (const gchar *str);
GType gda_null_get_type (void) G_GNUC_CONST;
GType gda_default_get_type (void) G_GNUC_CONST;
GType gda_numeric_get_type (void) G_GNUC_CONST;
+GdaNumeric* gda_numeric_new();
gpointer gda_numeric_copy (gpointer boxed);
+void gda_numeric_set_from_string (GdaNumeric *numeric, const gchar* str);
+void gda_numeric_set_double (GdaNumeric *numeric, gdouble number);
+gdouble gda_numeric_get_double (GdaNumeric *numeric);
+void gda_numeric_set_precision (GdaNumeric *numeric, glong precision);
+glong gda_numeric_get_precision (GdaNumeric *numeric);
+void gda_numeric_set_width (GdaNumeric *numeric, glong width);
+glong gda_numeric_get_width (GdaNumeric *numeric);
+gchar* gda_numeric_get_string (GdaNumeric *numeric);
void gda_numeric_free (gpointer boxed);
GType gda_time_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]