mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Derek Atkins's patch implementing kvp timespecs in C & scheme.
Implement kvp timespecs in xml. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5942 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a501c56fe7
commit
6f28287eac
@ -252,6 +252,8 @@ add_kvp_value_node(xmlNodePtr node, gchar *tag, kvp_value* val)
|
||||
|
||||
if (kvp_type == KVP_TYPE_STRING)
|
||||
val_node = xmlNewTextChild(node, NULL, tag, kvp_value_get_string(val));
|
||||
else if (kvp_type == KVP_TYPE_TIMESPEC)
|
||||
val_node = NULL;
|
||||
else
|
||||
val_node = xmlNewTextChild(node, NULL, tag, NULL);
|
||||
|
||||
@ -278,6 +280,15 @@ add_kvp_value_node(xmlNodePtr node, gchar *tag, kvp_value* val)
|
||||
add_text_to_node(val_node,"guid",
|
||||
guid_to_string(kvp_value_get_guid(val)));
|
||||
break;
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
{
|
||||
Timespec ts = kvp_value_get_timespec (val);
|
||||
|
||||
val_node = timespec_to_dom_tree (tag, &ts);
|
||||
xmlSetProp (val_node, "type", "timespec");
|
||||
xmlAddChild (node, val_node);
|
||||
}
|
||||
break;
|
||||
case KVP_TYPE_BINARY:
|
||||
{
|
||||
guint64 size;
|
||||
|
@ -186,6 +186,21 @@ dom_tree_to_guid_kvp_value(xmlNodePtr node)
|
||||
return ret;
|
||||
}
|
||||
|
||||
kvp_value*
|
||||
dom_tree_to_timespec_kvp_value (xmlNodePtr node)
|
||||
{
|
||||
Timespec * ts;
|
||||
kvp_value * ret = NULL;
|
||||
|
||||
ts = dom_tree_to_timespec (node);
|
||||
if (ts)
|
||||
ret = kvp_value_new_timespec (*ts);
|
||||
|
||||
g_free (ts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
string_to_binary(const gchar *str, void **v, guint64 *data_len)
|
||||
{
|
||||
@ -306,6 +321,7 @@ struct kvp_val_converter val_converters[] = {
|
||||
{ "numeric", dom_tree_to_numeric_kvp_value },
|
||||
{ "string", dom_tree_to_string_kvp_value },
|
||||
{ "guid", dom_tree_to_guid_kvp_value },
|
||||
{ "timespec", dom_tree_to_timespec_kvp_value },
|
||||
{ "binary", dom_tree_to_binary_kvp_value },
|
||||
{ "list", dom_tree_to_list_kvp_value },
|
||||
{ "frame", dom_tree_to_frame_kvp_value },
|
||||
|
@ -60,6 +60,7 @@ kvp_value* dom_tree_to_double_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_numeric_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_string_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_guid_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_timespec_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_binary_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_list_kvp_value(xmlNodePtr node);
|
||||
kvp_value* dom_tree_to_frame_kvp_value(xmlNodePtr node);
|
||||
|
@ -42,16 +42,19 @@ test_kvp_copy_compare(int run,
|
||||
|
||||
test_frame2 = kvp_frame_copy(test_frame1);
|
||||
|
||||
do_test_args(test_frame2 != NULL, "kvp_frame_copy", __FILE__, __LINE__, "run=%d", run);
|
||||
do_test_args(test_frame2 != NULL, "kvp_frame_copy",
|
||||
__FILE__, __LINE__, "run=%d", run);
|
||||
|
||||
if(kvp_frame_compare(test_frame1, test_frame2) == 0)
|
||||
{
|
||||
success_args("kvp_frame_copy->kvp_frame_compare", __FILE__, __LINE__, "run=%d",run);
|
||||
success_args("kvp_frame_copy->kvp_frame_compare",
|
||||
__FILE__, __LINE__, "run=%d",run);
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *tmp;
|
||||
failure_args("kvp_frame_copy->kvp_frame_compare", __FILE__, __LINE__, "run=%d", run);
|
||||
failure_args("kvp_frame_copy->kvp_frame_compare",
|
||||
__FILE__, __LINE__, "run=%d", run);
|
||||
tmp = kvp_frame_to_string(test_frame1);
|
||||
printf("Frame1 is %s\n", tmp);
|
||||
g_free(tmp);
|
||||
@ -75,12 +78,14 @@ test_kvp_copy_get_slot(int run,
|
||||
test_val2 = kvp_frame_get_slot(test_frame2, test_key);
|
||||
if(kvp_value_compare(test_val1, test_val2) == 0)
|
||||
{
|
||||
success_args("kvp_frame_copy->kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run);
|
||||
success_args("kvp_frame_copy->kvp_frame_get_slot",
|
||||
__FILE__, __LINE__, "run=%d", run);
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *tmp;
|
||||
failure_args("kvp_frame_copy->kvp_frame_get_slot", __FILE__, __LINE__, "run=%d", run);
|
||||
failure_args("kvp_frame_copy->kvp_frame_get_slot",
|
||||
__FILE__, __LINE__, "run=%d", run);
|
||||
tmp = kvp_frame_to_string(test_frame1);
|
||||
printf("Frame1 is %s\n", tmp);
|
||||
g_free(tmp);
|
||||
|
@ -717,6 +717,7 @@ guile_main (int argc, char **argv)
|
||||
/* The random double generator is making values
|
||||
* that postgres doesn't like. */
|
||||
kvp_exclude_type (KVP_TYPE_DOUBLE);
|
||||
kvp_exclude_type (KVP_TYPE_TIMESPEC);
|
||||
|
||||
set_max_kvp_depth (3);
|
||||
set_max_kvp_frame_elements (3);
|
||||
|
@ -575,6 +575,10 @@ gnc_kvp_value2scm (kvp_value *value)
|
||||
scm = gnc_guid2scm (*kvp_value_get_guid (value));
|
||||
break;
|
||||
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
scm = gnc_timespec2timepair (kvp_value_get_timespec (value));
|
||||
break;
|
||||
|
||||
case KVP_TYPE_BINARY:
|
||||
scm = SCM_BOOL_F;
|
||||
break;
|
||||
@ -689,6 +693,12 @@ gnc_scm2kvp_value (SCM value_scm)
|
||||
break;
|
||||
}
|
||||
|
||||
case KVP_TYPE_TIMESPEC: {
|
||||
Timespec ts = gnc_timepair2timespec (val_scm);
|
||||
value = kvp_value_new_timespec(ts);
|
||||
break;
|
||||
}
|
||||
|
||||
case KVP_TYPE_BINARY:
|
||||
return NULL;
|
||||
break;
|
||||
|
@ -488,6 +488,7 @@
|
||||
(gw:enum-add-value! wt "KVP_TYPE_NUMERIC" 'kvp-type-numeric)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_STRING" 'kvp-type-string)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_GUID" 'kvp-type-guid)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_TIMESPEC" 'kvp-type-timespec)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_BINARY" 'kvp-type-binary)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_GLIST" 'kvp-type-glist)
|
||||
(gw:enum-add-value! wt "KVP_TYPE_FRAME" 'kvp-type-frame)
|
||||
|
@ -38,6 +38,11 @@ gnc_scm_to_kvp_value_ptr(SCM val)
|
||||
GUID tmpguid = gnc_scm2guid(val);
|
||||
return kvp_value_new_guid(&tmpguid);
|
||||
}
|
||||
else if(gnc_timepair_p(val))
|
||||
{
|
||||
Timespec ts = gnc_timepair2timespec(val);
|
||||
return kvp_value_new_timespec(ts);
|
||||
}
|
||||
else if(gh_string_p(val))
|
||||
{
|
||||
char *newstr;
|
||||
@ -76,6 +81,9 @@ gnc_kvp_value_ptr_to_scm(kvp_value* val)
|
||||
return gnc_guid2scm(*tempguid);
|
||||
}
|
||||
break;
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
return gnc_timespec2timepair(kvp_value_get_timespec(val));
|
||||
break;
|
||||
|
||||
/* FIXME: handle types below */
|
||||
case KVP_TYPE_BINARY:
|
||||
|
@ -57,6 +57,7 @@ struct _kvp_value {
|
||||
gnc_numeric numeric;
|
||||
gchar *str;
|
||||
GUID *guid;
|
||||
Timespec timespec;
|
||||
kvp_value_binary_data binary;
|
||||
GList *list;
|
||||
kvp_frame *frame;
|
||||
@ -622,6 +623,14 @@ kvp_value_new_guid(const GUID * value) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
kvp_value *
|
||||
kvp_value_new_timespec(Timespec value) {
|
||||
kvp_value * retval = g_new0(kvp_value, 1);
|
||||
retval->type = KVP_TYPE_TIMESPEC;
|
||||
retval->value.timespec = value;
|
||||
return retval;
|
||||
}
|
||||
|
||||
kvp_value *
|
||||
kvp_value_new_binary(const void * value, guint64 datasize) {
|
||||
kvp_value * retval = g_new0(kvp_value, 1);
|
||||
@ -756,6 +765,16 @@ kvp_value_get_guid(const kvp_value * value) {
|
||||
}
|
||||
}
|
||||
|
||||
Timespec
|
||||
kvp_value_get_timespec(const kvp_value * value) {
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!value) return ts;
|
||||
if (value->type == KVP_TYPE_TIMESPEC)
|
||||
return value->value.timespec;
|
||||
else
|
||||
return ts;
|
||||
}
|
||||
|
||||
void *
|
||||
kvp_value_get_binary(const kvp_value * value, guint64 * size_return) {
|
||||
if (!value)
|
||||
@ -822,6 +841,9 @@ kvp_value_copy(const kvp_value * value) {
|
||||
case KVP_TYPE_GUID:
|
||||
return kvp_value_new_guid(value->value.guid);
|
||||
break;
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
return kvp_value_new_timespec(value->value.timespec);
|
||||
break;
|
||||
case KVP_TYPE_BINARY:
|
||||
return kvp_value_new_binary(value->value.binary.data,
|
||||
value->value.binary.datasize);
|
||||
@ -887,6 +909,9 @@ kvp_value_compare(const kvp_value * kva, const kvp_value * kvb) {
|
||||
case KVP_TYPE_GUID:
|
||||
return guid_compare(kva->value.guid, kvb->value.guid);
|
||||
break;
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
return timespec_cmp(&(kva->value.timespec), &(kvb->value.timespec));
|
||||
break;
|
||||
case KVP_TYPE_BINARY:
|
||||
/* I don't know that this is a good compare. Ab is bigger than Acef.
|
||||
But I'm not sure that actually matters here. */
|
||||
@ -1037,6 +1062,14 @@ kvp_value_to_string(const kvp_value *val)
|
||||
return tmp2;
|
||||
break;
|
||||
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
tmp1 = g_new0 (char, 40);
|
||||
gnc_timespec_to_iso8601_buff (kvp_value_get_timespec (val), tmp1);
|
||||
tmp2 = g_strdup_printf("KVP_VALUE_TIMESPEC(%s)", tmp1);
|
||||
g_free(tmp1);
|
||||
return tmp2;
|
||||
break;
|
||||
|
||||
case KVP_TYPE_BINARY:
|
||||
{
|
||||
guint64 len;
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include "gnc-numeric.h"
|
||||
#include "guid.h"
|
||||
|
||||
#include "date.h"
|
||||
|
||||
/* a kvp_frame is a set of associations between character strings
|
||||
* (keys) and kvp_value structures. A kvp_value is a union with
|
||||
@ -48,6 +48,7 @@ typedef enum {
|
||||
KVP_TYPE_NUMERIC,
|
||||
KVP_TYPE_STRING,
|
||||
KVP_TYPE_GUID,
|
||||
KVP_TYPE_TIMESPEC,
|
||||
KVP_TYPE_BINARY,
|
||||
KVP_TYPE_GLIST,
|
||||
KVP_TYPE_FRAME
|
||||
@ -152,6 +153,7 @@ kvp_value * kvp_value_new_double(double value);
|
||||
kvp_value * kvp_value_new_gnc_numeric(gnc_numeric value);
|
||||
kvp_value * kvp_value_new_string(const char * value);
|
||||
kvp_value * kvp_value_new_guid(const GUID * guid);
|
||||
kvp_value * kvp_value_new_timespec(Timespec timespec);
|
||||
kvp_value * kvp_value_new_binary(const void * data, guint64 datasize);
|
||||
kvp_value * kvp_value_new_glist(const GList * value);
|
||||
kvp_value * kvp_value_new_frame(const kvp_frame * value);
|
||||
@ -173,6 +175,7 @@ void * kvp_value_get_binary(const kvp_value * value,
|
||||
guint64 * size_return);
|
||||
GList * kvp_value_get_glist(const kvp_value * value);
|
||||
kvp_frame * kvp_value_get_frame(const kvp_value * value);
|
||||
Timespec kvp_value_get_timespec(const kvp_value * value);
|
||||
|
||||
gchar* kvp_value_to_string(const kvp_value *val);
|
||||
|
||||
|
@ -447,6 +447,13 @@ get_random_kvp_value_depth (int type, gint depth)
|
||||
}
|
||||
break;
|
||||
|
||||
case KVP_TYPE_TIMESPEC:
|
||||
{
|
||||
Timespec *ts = get_random_timespec();
|
||||
return kvp_value_new_timespec (*ts);
|
||||
}
|
||||
break;
|
||||
|
||||
case KVP_TYPE_BINARY:
|
||||
{
|
||||
bin_data *tmp_data;
|
||||
|
Loading…
Reference in New Issue
Block a user