mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-02 05:29:20 -06:00
Implement KVP_TYPE_BOOLEAN
In terms of KVP_TYPE_STRING such that TRUE->"true" and FALSE->NULL. This provides compatibility with the existing boolean KVP in Account.c.
This commit is contained in:
parent
31cfa0a9f0
commit
32d4fff366
@ -932,6 +932,13 @@ kvp_value_new_double(double value)
|
||||
return new KvpValueImpl{value};
|
||||
}
|
||||
|
||||
KvpValue *
|
||||
kvp_value_new_boolean(gboolean value)
|
||||
{
|
||||
if (!value) return {};
|
||||
return new KvpValueImpl{g_strdup("true")};
|
||||
}
|
||||
|
||||
KvpValue *
|
||||
kvp_value_new_numeric(gnc_numeric value)
|
||||
{
|
||||
@ -1024,6 +1031,15 @@ kvp_value_get_double(const KvpValue * ovalue)
|
||||
return value->get<double>();
|
||||
}
|
||||
|
||||
bool
|
||||
kvp_value_get_boolean (const KvpValue *ovalue)
|
||||
{
|
||||
if (!ovalue) return {};
|
||||
const KvpValueImpl *value {static_cast<const KvpValueImpl*>(ovalue)};
|
||||
const char* str = value->get<char*>();
|
||||
return str && strcmp(str, "true") == 0;
|
||||
}
|
||||
|
||||
gnc_numeric
|
||||
kvp_value_get_numeric(const KvpValue * ovalue)
|
||||
{
|
||||
@ -1221,6 +1237,10 @@ gvalue_from_kvp_value (KvpValue *kval)
|
||||
g_value_init (val, G_TYPE_DOUBLE);
|
||||
g_value_set_double (val, kvp_value_get_double (kval));
|
||||
break;
|
||||
case KVP_TYPE_BOOLEAN:
|
||||
g_value_init (val, G_TYPE_BOOLEAN);
|
||||
g_value_set_boolean (val, kvp_value_get_boolean (kval));
|
||||
break;
|
||||
case KVP_TYPE_NUMERIC:
|
||||
g_value_init (val, GNC_TYPE_NUMERIC);
|
||||
num = kvp_value_get_numeric (kval);
|
||||
@ -1270,13 +1290,18 @@ KvpValue*
|
||||
kvp_value_from_gvalue (const GValue *gval)
|
||||
{
|
||||
KvpValue *val = NULL;
|
||||
GType type = G_VALUE_TYPE (gval);
|
||||
GType type;
|
||||
if (gval == NULL)
|
||||
return NULL;
|
||||
type = G_VALUE_TYPE (gval);
|
||||
g_return_val_if_fail (G_VALUE_TYPE (gval), NULL);
|
||||
|
||||
if (type == G_TYPE_INT64)
|
||||
val = kvp_value_new_gint64 (g_value_get_int64 (gval));
|
||||
else if (type == G_TYPE_DOUBLE)
|
||||
val = kvp_value_new_double (g_value_get_double (gval));
|
||||
else if (type == G_TYPE_BOOLEAN)
|
||||
val = kvp_value_new_boolean (g_value_get_boolean (gval));
|
||||
else if (type == GNC_TYPE_NUMERIC)
|
||||
val = kvp_value_new_numeric (*(gnc_numeric*)g_value_get_boxed (gval));
|
||||
else if (type == G_TYPE_STRING)
|
||||
|
@ -95,14 +95,15 @@ typedef enum
|
||||
KVP_TYPE_INVALID = -1,
|
||||
KVP_TYPE_GINT64 = 1, /**< QOF_TYPE_INT64 gint64 */
|
||||
KVP_TYPE_DOUBLE, /**< QOF_TYPE_DOUBLE gdouble */
|
||||
KVP_TYPE_BOOLEAN, /**< QOF_TYPE_BOOLEAN gboolean */
|
||||
KVP_TYPE_NUMERIC, /**< QOF_TYPE_NUMERIC */
|
||||
KVP_TYPE_STRING, /**< QOF_TYPE_STRING gchar* */
|
||||
KVP_TYPE_GUID, /**< QOF_TYPE_GUID */
|
||||
KVP_TYPE_TIMESPEC, /**< QOF_TYPE_DATE */
|
||||
KVP_TYPE_PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */
|
||||
KVP_TYPE_GLIST, /**< no QOF equivalent. */
|
||||
KVP_TYPE_FRAME /**< no QOF equivalent. */
|
||||
, KVP_TYPE_GDATE /**< no QOF equivalent. */
|
||||
KVP_TYPE_FRAME, /**< no QOF equivalent. */
|
||||
KVP_TYPE_GDATE /**< no QOF equivalent. */
|
||||
} KvpValueType;
|
||||
|
||||
/** \deprecated Deprecated backwards compat token
|
||||
|
Loading…
Reference in New Issue
Block a user