Commit 6557463b authored by Richard Hughes's avatar Richard Hughes

trivial: add to_sting and from_string methods to DkpStatsObj

parent 28f542de
......@@ -77,3 +77,44 @@ dkp_stats_obj_create (gdouble value, gdouble state)
return obj;
}
/**
* dkp_stats_obj_from_string:
**/
DkpStatsObj *
dkp_stats_obj_from_string (const gchar *text)
{
DkpStatsObj *obj = NULL;
gchar **parts = NULL;
guint length;
if (text == NULL)
goto out;
/* split by tab */
parts = g_strsplit (text, "\t", 0);
length = g_strv_length (parts);
if (length != 2) {
egg_warning ("invalid string: '%s'", text);
goto out;
}
/* parse and create */
obj = dkp_stats_obj_new ();
obj->value = atoi (parts[0]);
obj->accuracy = atof (parts[1]);
out:
g_strfreev (parts);
return obj;
}
/**
* dkp_stats_obj_to_string:
**/
gchar *
dkp_stats_obj_to_string (const DkpStatsObj *obj)
{
if (obj == NULL)
return NULL;
return g_strdup_printf ("%.2f\t%.2f", obj->value, obj->accuracy);
}
......@@ -37,6 +37,8 @@ gboolean dkp_stats_obj_free (DkpStatsObj *obj);
DkpStatsObj *dkp_stats_obj_copy (const DkpStatsObj *cobj);
DkpStatsObj *dkp_stats_obj_create (gdouble value,
gdouble state);
DkpStatsObj *dkp_stats_obj_from_string (const gchar *text);
gchar *dkp_stats_obj_to_string (const DkpStatsObj *obj);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment