[goffice] GOData: add context arguments to serialization.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [goffice] GOData: add context arguments to serialization.
- Date: Wed, 29 Apr 2009 16:28:20 -0400 (EDT)
commit c0479b029d938972cd70afab4700adc87a843e00
Author: Morten Welinder <terra gnome org>
Date: Wed Apr 29 16:27:38 2009 -0400
GOData: add context arguments to serialization.
---
ChangeLog | 11 ++++++++
goffice/data/go-data-impl.h | 4 +-
goffice/data/go-data-simple.c | 54 ++++++++++++++++++++--------------------
goffice/data/go-data.c | 24 ++++++++++-------
goffice/data/go-data.h | 4 +-
goffice/graph/gog-object-xml.c | 31 +++++++++++++---------
goffice/graph/gog-object-xml.h | 9 +++---
7 files changed, 79 insertions(+), 58 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2cd7d73..47d261b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-29 Morten Welinder <terra gnome org>
+
+ * goffice/graph/gog-object-xml.h (gog_object_new_from_xml,
+ gog_object_sax_push_parser): Add user pointer argument for
+ serialization. All callers changed.
+
+ * goffice/data/go-data.c (go_data_serialize): Rename from
+ go_data_as_str. Add user pointer argument. All callers changed.
+ (go_data_unserialize): Rename from go_data_from_str. Add user
+ pointer argument. All callers changed.
+
2009-04-28 Morten Welinder <terra gnome org>
* goffice/graph/gog-axis.c (map_log_calc_ticks): Handle
diff --git a/goffice/data/go-data-impl.h b/goffice/data/go-data-impl.h
index 6fb72dc..479107e 100644
--- a/goffice/data/go-data-impl.h
+++ b/goffice/data/go-data-impl.h
@@ -44,8 +44,8 @@ typedef struct {
GOData * (*dup) (GOData const *src);
gboolean (*eq) (GOData const *a, GOData const *b);
GOFormat * (*preferred_fmt) (GOData const *dat);
- char * (*as_str) (GOData const *dat);
- gboolean (*from_str) (GOData *dat, char const *str);
+ char * (*serialize) (GOData const *dat, gpointer user);
+ gboolean (*unserialize) (GOData *dat, char const *str, gpointer user);
void (*emit_changed) (GOData *dat);
unsigned int (*get_n_dimensions) (GOData *data);
diff --git a/goffice/data/go-data-simple.c b/goffice/data/go-data-simple.c
index b2175b5..5d4c4d8 100644
--- a/goffice/data/go-data-simple.c
+++ b/goffice/data/go-data-simple.c
@@ -72,13 +72,13 @@ go_data_scalar_val_eq (GOData const *a, GOData const *b)
}
static char *
-go_data_scalar_val_as_str (GOData const *dat)
+go_data_scalar_val_serialize (GOData const *dat, gpointer user)
{
return g_strdup (go_data_scalar_get_str (GO_DATA_SCALAR (dat)));
}
static gboolean
-go_data_scalar_val_from_str (GOData *dat, char const *str)
+go_data_scalar_val_unserialize (GOData *dat, char const *str, gpointer user)
{
GODataScalarVal *sval = (GODataScalarVal *)dat;
double tmp;
@@ -118,14 +118,14 @@ go_data_scalar_val_class_init (GObjectClass *gobject_klass)
GODataClass *godata_klass = (GODataClass *) gobject_klass;
GODataScalarClass *scalar_klass = (GODataScalarClass *) gobject_klass;
- scalar_val_parent_klass = g_type_class_peek_parent (gobject_klass);
- gobject_klass->finalize = go_data_scalar_val_finalize;
- godata_klass->dup = go_data_scalar_val_dup;
- godata_klass->eq = go_data_scalar_val_eq;
- godata_klass->as_str = go_data_scalar_val_as_str;
- godata_klass->from_str = go_data_scalar_val_from_str;
- scalar_klass->get_value = go_data_scalar_val_get_value;
- scalar_klass->get_str = go_data_scalar_val_get_str;
+ scalar_val_parent_klass = g_type_class_peek_parent (gobject_klass);
+ gobject_klass->finalize = go_data_scalar_val_finalize;
+ godata_klass->dup = go_data_scalar_val_dup;
+ godata_klass->eq = go_data_scalar_val_eq;
+ godata_klass->serialize = go_data_scalar_val_serialize;
+ godata_klass->unserialize = go_data_scalar_val_unserialize;
+ scalar_klass->get_value = go_data_scalar_val_get_value;
+ scalar_klass->get_str = go_data_scalar_val_get_str;
}
GSF_CLASS (GODataScalarVal, go_data_scalar_val,
@@ -182,14 +182,14 @@ go_data_scalar_str_eq (GOData const *a, GOData const *b)
}
static char *
-go_data_scalar_str_as_str (GOData const *dat)
+go_data_scalar_str_serialize (GOData const *dat, gpointer user)
{
GODataScalarStr const *str = (GODataScalarStr const *)dat;
return g_strdup (str->str);
}
static gboolean
-go_data_scalar_str_from_str (GOData *dat, char const *string)
+go_data_scalar_str_unserialize (GOData *dat, char const *string, gpointer user)
{
GODataScalarStr *str = (GODataScalarStr *)dat;
@@ -225,8 +225,8 @@ go_data_scalar_str_class_init (GObjectClass *gobject_klass)
gobject_klass->finalize = go_data_scalar_str_finalize;
godata_klass->dup = go_data_scalar_str_dup;
godata_klass->eq = go_data_scalar_str_eq;
- godata_klass->as_str = go_data_scalar_str_as_str;
- godata_klass->from_str = go_data_scalar_str_from_str;
+ godata_klass->serialize = go_data_scalar_str_serialize;
+ godata_klass->unserialize = go_data_scalar_str_unserialize;
scalar_klass->get_value = go_data_scalar_str_get_value;
scalar_klass->get_str = go_data_scalar_str_get_str;
}
@@ -357,7 +357,7 @@ go_data_vector_val_get_str (GODataVector *vec, unsigned i)
}
static char *
-go_data_vector_val_as_str (GOData const *dat)
+go_data_vector_val_serialize (GOData const *dat, gpointer user)
{
GODataVectorVal *vec = GO_DATA_VECTOR_VAL (dat);
GString *str;
@@ -379,7 +379,7 @@ go_data_vector_val_as_str (GOData const *dat)
}
static gboolean
-go_data_vector_val_from_str (GOData *dat, char const *str)
+go_data_vector_val_unserialize (GOData *dat, char const *str, gpointer user)
{
GODataVectorVal *vec = GO_DATA_VECTOR_VAL (dat);
char sep, *end = (char*) str;
@@ -435,8 +435,8 @@ go_data_vector_val_class_init (GObjectClass *gobject_klass)
gobject_klass->finalize = go_data_vector_val_finalize;
godata_klass->dup = go_data_vector_val_dup;
godata_klass->eq = go_data_vector_val_eq;
- godata_klass->as_str = go_data_vector_val_as_str;
- godata_klass->from_str = go_data_vector_val_from_str;
+ godata_klass->serialize = go_data_vector_val_serialize;
+ godata_klass->unserialize = go_data_vector_val_unserialize;
vector_klass->load_len = go_data_vector_val_load_len;
vector_klass->load_values = go_data_vector_val_load_values;
vector_klass->get_value = go_data_vector_val_get_value;
@@ -527,7 +527,7 @@ go_data_vector_str_eq (GOData const *a, GOData const *b)
}
static char *
-go_data_vector_str_as_str (GOData const *dat)
+go_data_vector_str_serialize (GOData const *dat, gpointer user)
{
GODataVectorStr *vec = GO_DATA_VECTOR_STR (dat);
GString *str;
@@ -552,7 +552,7 @@ go_data_vector_str_as_str (GOData const *dat)
}
static gboolean
-go_data_vector_str_from_str (GOData *dat, char const *str)
+go_data_vector_str_unserialize (GOData *dat, char const *str, gpointer user)
{
GODataVectorStr *vec = GO_DATA_VECTOR_STR (dat);
char sep, *cur = (char*) str, *end, *val;
@@ -695,8 +695,8 @@ go_data_vector_str_class_init (GObjectClass *gobject_klass)
gobject_klass->finalize = go_data_vector_str_finalize;
godata_klass->dup = go_data_vector_str_dup;
godata_klass->eq = go_data_vector_str_eq;
- godata_klass->as_str = go_data_vector_str_as_str;
- godata_klass->from_str = go_data_vector_str_from_str;
+ godata_klass->serialize = go_data_vector_str_serialize;
+ godata_klass->unserialize = go_data_vector_str_unserialize;
vector_klass->load_len = go_data_vector_str_load_len;
vector_klass->load_values = go_data_vector_str_load_values;
vector_klass->get_value = go_data_vector_str_get_value;
@@ -879,7 +879,7 @@ go_data_matrix_val_get_str (GODataMatrix *mat, unsigned i, unsigned j)
}
static char *
-go_data_matrix_val_as_str (GOData const *dat)
+go_data_matrix_val_serialize (GOData const *dat, gpointer user)
{
GODataMatrixVal *mat = GO_DATA_MATRIX_VAL (dat);
GString *str;
@@ -912,7 +912,7 @@ go_data_matrix_val_as_str (GOData const *dat)
}
static gboolean
-go_data_matrix_val_from_str (GOData *dat, char const *str)
+go_data_matrix_val_unserialize (GOData *dat, char const *str, gpointer user)
{
GODataMatrixVal *mat = GO_DATA_MATRIX_VAL (dat);
char row_sep, col_sep, *end = (char*) str;
@@ -986,9 +986,9 @@ go_data_matrix_val_class_init (GObjectClass *gobject_klass)
gobject_klass->finalize = go_data_matrix_val_finalize;
godata_klass->dup = go_data_matrix_val_dup;
godata_klass->eq = go_data_matrix_val_eq;
- godata_klass->as_str = go_data_matrix_val_as_str;
- godata_klass->from_str = go_data_matrix_val_from_str;
- matrix_klass->load_size = go_data_matrix_val_load_size;
+ godata_klass->serialize = go_data_matrix_val_serialize;
+ godata_klass->unserialize = go_data_matrix_val_unserialize;
+ matrix_klass->load_size = go_data_matrix_val_load_size;
matrix_klass->load_values = go_data_matrix_val_load_values;
matrix_klass->get_value = go_data_matrix_val_get_value;
matrix_klass->get_str = go_data_matrix_val_get_str;
diff --git a/goffice/data/go-data.c b/goffice/data/go-data.c
index 5c84953..6363cc9 100644
--- a/goffice/data/go-data.c
+++ b/goffice/data/go-data.c
@@ -44,10 +44,11 @@ static gulong go_data_signals [LAST_SIGNAL] = { 0, };
static GOData *
go_data_dup_real (GOData const *src)
{
- char *str = go_data_as_str (src);
+ gpointer user = NULL; /* FIXME? */
+ char *str = go_data_serialize (src, user);
GOData *dst = g_object_new (G_OBJECT_TYPE (src), NULL);
if (dst != NULL)
- go_data_from_str (dst, str);
+ go_data_unserialize (dst, str, user);
g_free (str);
return dst;
@@ -155,37 +156,40 @@ go_data_preferred_fmt (GOData const *dat)
}
/**
- * go_data_as_str :
+ * go_data_serialize :
* @dat : #GOData
+ * @user : a gpointer describing the context.
*
- * NOTE : This is the _source_ not the content.
+ * NOTE : This is the _source_ not the content. (I.e., this refers to the
+ * expression, not its current value.)
*
* Returns: a string representation of the data source that the caller is
* responsible for freeing
**/
char *
-go_data_as_str (GOData const *dat)
+go_data_serialize (GOData const *dat, gpointer user)
{
GODataClass const *klass = GO_DATA_GET_CLASS (dat);
g_return_val_if_fail (klass != NULL, NULL);
- return (*klass->as_str) (dat);
+ return (*klass->serialize) (dat, user);
}
/**
- * go_data_from_str :
+ * go_data_unserialize :
* @dat : #GOData
* @str : string to parse
+ * @user : a gpointer describing the context.
*
- * De-serializes the source information returned from go_data_as_str.
+ * De-serializes the source information returned from go_data_serialize.
*
* Returns: %FALSE on error.
**/
gboolean
-go_data_from_str (GOData *dat, char const *str)
+go_data_unserialize (GOData *dat, char const *str, gpointer user)
{
GODataClass const *klass = GO_DATA_GET_CLASS (dat);
g_return_val_if_fail (klass != NULL, FALSE);
- return (*klass->from_str) (dat, str);
+ return (*klass->unserialize) (dat, str, user);
}
/**
diff --git a/goffice/data/go-data.h b/goffice/data/go-data.h
index b8c42e5..88882f3 100644
--- a/goffice/data/go-data.h
+++ b/goffice/data/go-data.h
@@ -36,8 +36,8 @@ GType go_data_get_type (void);
GOData * go_data_dup (GOData const *src);
gboolean go_data_eq (GOData const *a, GOData const *b);
GOFormat * go_data_preferred_fmt (GOData const *dat);
-char * go_data_as_str (GOData const *dat);
-gboolean go_data_from_str (GOData *dat, char const *str);
+char * go_data_serialize (GOData const *dat, gpointer user);
+gboolean go_data_unserialize (GOData *dat, char const *str, gpointer user);
void go_data_emit_changed (GOData *dat);
double * go_data_get_values (GOData *data);
diff --git a/goffice/graph/gog-object-xml.c b/goffice/graph/gog-object-xml.c
index 1ab437b..8099bca 100644
--- a/goffice/graph/gog-object-xml.c
+++ b/goffice/graph/gog-object-xml.c
@@ -177,7 +177,7 @@ gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOu
}
static void
-gog_dataset_dom_load (GogDataset *set, xmlNode *node)
+gog_dataset_dom_load (GogDataset *set, xmlNode *node, gpointer user)
{
xmlNode *ptr;
xmlChar *id, *val, *type;
@@ -200,7 +200,7 @@ gog_dataset_dom_load (GogDataset *set, xmlNode *node)
if (id != NULL && type != NULL && val != NULL) {
unsigned dim_id = strtoul (id, NULL, 0);
GOData *dat = g_object_new (g_type_from_name (type), NULL);
- if (dat != NULL && go_data_from_str (dat, val))
+ if (dat != NULL && go_data_unserialize (dat, val, user))
gog_dataset_set_dim (set, dim_id, dat, NULL);
}
@@ -212,7 +212,7 @@ gog_dataset_dom_load (GogDataset *set, xmlNode *node)
}
static void
-gog_dataset_sax_save (GogDataset const *set, GsfXMLOut *output)
+gog_dataset_sax_save (GogDataset const *set, GsfXMLOut *output, gpointer user)
{
GOData *dat;
char *tmp;
@@ -229,7 +229,7 @@ gog_dataset_sax_save (GogDataset const *set, GsfXMLOut *output)
gsf_xml_out_add_int (output, "id", i);
gsf_xml_out_add_cstr (output, "type",
G_OBJECT_TYPE_NAME (dat));
- tmp = go_data_as_str (dat);
+ tmp = go_data_serialize (dat, user);
gsf_xml_out_add_cstr (output, NULL, tmp);
g_free (tmp);
gsf_xml_out_end_element (output); /* </dimension> */
@@ -239,7 +239,7 @@ gog_dataset_sax_save (GogDataset const *set, GsfXMLOut *output)
}
void
-gog_object_write_xml_sax (GogObject const *obj, GsfXMLOut *output)
+gog_object_write_xml_sax (GogObject const *obj, GsfXMLOut *output, gpointer user)
{
guint n;
GParamSpec **props;
@@ -270,17 +270,17 @@ gog_object_write_xml_sax (GogObject const *obj, GsfXMLOut *output)
if (GO_IS_PERSIST (obj)) /* anything special for this class */
go_persist_sax_save (GO_PERSIST (obj), output);
if (GOG_IS_DATASET (obj)) /* convenience to save data */
- gog_dataset_sax_save (GOG_DATASET (obj), output);
+ gog_dataset_sax_save (GOG_DATASET (obj), output, user);
/* the children */
for (ptr = obj->children; ptr != NULL ; ptr = ptr->next)
- gog_object_write_xml_sax (ptr->data, output);
+ gog_object_write_xml_sax (ptr->data, output, user);
gsf_xml_out_end_element (output); /* </GogObject> */
}
GogObject *
-gog_object_new_from_xml (GogObject *parent, xmlNode *node)
+gog_object_new_from_xml (GogObject *parent, xmlNode *node, gpointer user)
{
xmlChar *role, *name, *val, *type_name;
xmlNode *ptr;
@@ -321,7 +321,7 @@ gog_object_new_from_xml (GogObject *parent, xmlNode *node)
if (GO_IS_PERSIST (res))
go_persist_dom_load (GO_PERSIST (res), node);
if (GOG_IS_DATASET (res)) /* convenience to save data */
- gog_dataset_dom_load (GOG_DATASET (res), node);
+ gog_dataset_dom_load (GOG_DATASET (res), node, user);
for (ptr = node->xmlChildrenNode ; ptr != NULL ; ptr = ptr->next) {
if (xmlIsBlankNode (ptr) || ptr->name == NULL)
@@ -337,7 +337,7 @@ gog_object_new_from_xml (GogObject *parent, xmlNode *node)
xmlFree (val);
xmlFree (name);
} else if (!strcmp (ptr->name, "GogObject"))
- gog_object_new_from_xml (res, ptr);
+ gog_object_new_from_xml (res, ptr, user);
}
return res;
}
@@ -350,8 +350,9 @@ typedef struct {
GOData *dimension;
unsigned dimension_id;
- GogObjectSaxHandler handler;
- gpointer user_data;
+ GogObjectSaxHandler handler;
+ gpointer user_data;
+ gpointer user_unserialize;
} GogXMLReadState;
GogObject *
@@ -413,7 +414,9 @@ gogo_dim_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *unknown)
g_return_if_fail (GOG_IS_DATASET (state->obj));
if (NULL != state->dimension) {
- if (go_data_from_str (state->dimension, xin->content->str))
+ if (go_data_unserialize (state->dimension,
+ xin->content->str,
+ state->user_unserialize))
gog_dataset_set_dim (GOG_DATASET (state->obj),
state->dimension_id, state->dimension, NULL);
else
@@ -596,6 +599,7 @@ go_sax_parser_done (GsfXMLIn *xin, GogXMLReadState *state)
void
gog_object_sax_push_parser (GsfXMLIn *xin, xmlChar const **attrs,
GogObjectSaxHandler handler,
+ gpointer user_unserialize,
gpointer user_data)
{
static GsfXMLInNode const dtd[] = {
@@ -614,6 +618,7 @@ gog_object_sax_push_parser (GsfXMLIn *xin, xmlChar const **attrs,
state = g_new0 (GogXMLReadState, 1);
state->handler = handler;
state->user_data = user_data;
+ state->user_unserialize = user_unserialize;
gsf_xml_in_push_state (xin, doc, state,
(GsfXMLInExtDtor) go_sax_parser_done, attrs);
}
diff --git a/goffice/graph/gog-object-xml.h b/goffice/graph/gog-object-xml.h
index 39f5bf2..dd299e6 100644
--- a/goffice/graph/gog-object-xml.h
+++ b/goffice/graph/gog-object-xml.h
@@ -30,15 +30,16 @@
G_BEGIN_DECLS
void gog_object_set_arg (char const *name, char const *val, GogObject *obj);
-void gog_object_write_xml_sax(GogObject const *obj, GsfXMLOut *output);
+void gog_object_write_xml_sax(GogObject const *obj, GsfXMLOut *output, gpointer user);
/* deprecated as soon as sax import works */
-GogObject *gog_object_new_from_xml (GogObject *parent, xmlNode *node);
+GogObject *gog_object_new_from_xml (GogObject *parent, xmlNode *node, gpointer user);
typedef void (*GogObjectSaxHandler)(GogObject *obj, gpointer user_data);
void gog_object_sax_push_parser (GsfXMLIn *xin, xmlChar const **attrs,
- GogObjectSaxHandler handler,
- gpointer user_data);
+ GogObjectSaxHandler handler,
+ gpointer user_unserialize,
+ gpointer user_data);
GogObject *gog_xml_read_state_get_obj (GsfXMLIn *xin);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]