2001-08-17 17:49:17 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-08-17 11:55:35 -05:00
|
|
|
#include <kvp_frame.h>
|
2002-01-09 15:44:25 -06:00
|
|
|
#include <g-wrap-wct.h>
|
2001-08-17 11:55:35 -05:00
|
|
|
#include <libguile.h>
|
|
|
|
#include <engine-helpers.h>
|
|
|
|
|
2001-08-17 17:49:17 -05:00
|
|
|
#include "kvp-scm.h"
|
|
|
|
|
2001-08-17 11:55:35 -05:00
|
|
|
int
|
|
|
|
gnc_kvp_value_ptr_p(SCM arg)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-11-05 18:49:46 -06:00
|
|
|
/* NOTE: There are some problems with this approach. Currently,
|
|
|
|
* guids are stored simply as strings in scheme, so some
|
|
|
|
* strings could be mistaken for guids, although that is
|
|
|
|
* unlikely. The general problem is distinguishing kvp
|
|
|
|
* types based only on the scheme type. */
|
2001-08-17 11:55:35 -05:00
|
|
|
kvp_value*
|
|
|
|
gnc_scm_to_kvp_value_ptr(SCM val)
|
|
|
|
{
|
2001-11-05 18:49:46 -06:00
|
|
|
if(gh_exact_p (val) && gnc_gh_gint64_p(val))
|
2001-08-17 11:55:35 -05:00
|
|
|
{
|
|
|
|
return kvp_value_new_gint64(gnc_scm_to_gint64(val));
|
|
|
|
}
|
|
|
|
else if(gh_number_p(val))
|
|
|
|
{
|
|
|
|
return kvp_value_new_double(gh_scm2double(val));
|
|
|
|
}
|
|
|
|
else if(gnc_numeric_p(val))
|
|
|
|
{
|
|
|
|
return kvp_value_new_gnc_numeric(gnc_scm_to_numeric(val));
|
|
|
|
}
|
|
|
|
else if(gnc_guid_p(val))
|
|
|
|
{
|
|
|
|
GUID tmpguid = gnc_scm2guid(val);
|
|
|
|
return kvp_value_new_guid(&tmpguid);
|
|
|
|
}
|
2001-11-21 03:49:02 -06:00
|
|
|
else if(gnc_timepair_p(val))
|
|
|
|
{
|
|
|
|
Timespec ts = gnc_timepair2timespec(val);
|
|
|
|
return kvp_value_new_timespec(ts);
|
|
|
|
}
|
2001-08-17 11:55:35 -05:00
|
|
|
else if(gh_string_p(val))
|
|
|
|
{
|
|
|
|
char *newstr;
|
|
|
|
kvp_value *ret;
|
|
|
|
newstr = gh_scm2newstr(val, NULL);
|
|
|
|
ret = kvp_value_new_string(newstr);
|
2001-11-15 18:40:23 -06:00
|
|
|
free(newstr);
|
2001-08-17 11:55:35 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* FIXME: add binary handler here when it's figured out */
|
2001-11-05 18:49:46 -06:00
|
|
|
/* FIXME: add list handler here */
|
2001-08-17 11:55:35 -05:00
|
|
|
/* FIXME: add frame handler here when it's figured out */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gnc_kvp_value_ptr_to_scm(kvp_value* val)
|
|
|
|
{
|
|
|
|
switch(kvp_value_get_type(val))
|
|
|
|
{
|
|
|
|
case KVP_TYPE_GINT64:
|
|
|
|
return gnc_gint64_to_scm(kvp_value_get_gint64(val));
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_DOUBLE:
|
|
|
|
return gh_double2scm(kvp_value_get_double(val));
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_NUMERIC:
|
|
|
|
return gnc_numeric_to_scm(kvp_value_get_numeric(val));
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_STRING:
|
|
|
|
return gh_str02scm(kvp_value_get_string(val));
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_GUID:
|
|
|
|
{
|
|
|
|
GUID *tempguid = kvp_value_get_guid(val);
|
|
|
|
return gnc_guid2scm(*tempguid);
|
|
|
|
}
|
|
|
|
break;
|
2001-11-21 03:49:02 -06:00
|
|
|
case KVP_TYPE_TIMESPEC:
|
|
|
|
return gnc_timespec2timepair(kvp_value_get_timespec(val));
|
|
|
|
break;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
/* FIXME: handle types below */
|
2001-08-17 11:55:35 -05:00
|
|
|
case KVP_TYPE_BINARY:
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_GLIST:
|
|
|
|
break;
|
|
|
|
case KVP_TYPE_FRAME:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
}
|
2002-07-06 16:50:14 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
gnc_kvp_frame_delete_at_path (kvp_frame *frame, GSList *key_path)
|
|
|
|
{
|
|
|
|
kvp_value *val;
|
|
|
|
|
|
|
|
val = kvp_frame_get_slot_path_gslist (frame, key_path);
|
|
|
|
if (!val) return;
|
|
|
|
if (kvp_value_get_type (val) == KVP_TYPE_FRAME) {
|
|
|
|
frame = kvp_value_get_frame (val);
|
|
|
|
kvp_frame_delete (frame);
|
|
|
|
}
|
|
|
|
}
|