/** * json_node_set_value: * @node: a #JsonNode initialized to %JSON_NODE_VALUE * @value: the #GValue to set * * Sets @value inside @node. The passed #GValue is copied into the #JsonNode. * * It is an error to call this on an immutable node. */ void json_node_set_value (JsonNode *node, const GValue *value) { g_return_if_fail (JSON_NODE_IS_VALID (node)); g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE); g_return_if_fail (G_VALUE_TYPE (value) != G_TYPE_INVALID); g_return_if_fail (!node->immutable); if (node->data.value == NULL) node->data.value = json_value_alloc (); switch (G_VALUE_TYPE (value)) { /* auto-promote machine integers to 64 bit integers */ case G_TYPE_INT64: case G_TYPE_INT: json_value_init (node->data.value, JSON_VALUE_INT); if (G_VALUE_TYPE (value) == G_TYPE_INT64) json_value_set_int (node->data.value, g_value_get_int64 (value)); else json_value_set_int (node->data.value, g_value_get_int (value)); break; case G_TYPE_BOOLEAN: json_value_init (node->data.value, JSON_VALUE_BOOLEAN); json_value_set_boolean (node->data.value, g_value_get_boolean (value)); break; /* auto-promote single-precision floats to double precision floats */ case G_TYPE_DOUBLE: case G_TYPE_FLOAT: json_value_init (node->data.value, JSON_VALUE_DOUBLE); if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE) json_value_set_double (node->data.value, g_value_get_double (value)); else json_value_set_double (node->data.value, g_value_get_float (value)); break; case G_TYPE_STRING: json_value_init (node->data.value, JSON_VALUE_STRING); json_value_set_string (node->data.value, g_value_get_string (value)); break; default: g_message ("Invalid value of type '%s'", g_type_name (G_VALUE_TYPE (value))); return; } }
/** * json_node_set_double: * @node: a #JsonNode of type %JSON_NODE_VALUE * @value: a double value * * Sets @value as the double content of the @node, replacing any existing * content. */ void json_node_set_double (JsonNode *node, gdouble value) { g_return_if_fail (node != NULL); g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE); if (node->data.value == NULL) node->data.value = json_value_init (json_value_alloc (), JSON_VALUE_DOUBLE); else json_value_init (node->data.value, JSON_VALUE_DOUBLE); json_value_set_double (node->data.value, value); }
/** * json_node_set_boolean: * @node: a #JsonNode of type %JSON_NODE_VALUE * @value: a boolean value * * Sets @value as the boolean content of the @node, replacing any existing * content. */ void json_node_set_boolean (JsonNode *node, gboolean value) { g_return_if_fail (node != NULL); g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE); if (node->data.value == NULL) node->data.value = json_value_init (json_value_alloc (), JSON_VALUE_BOOLEAN); else json_value_init (node->data.value, JSON_VALUE_BOOLEAN); json_value_set_boolean (node->data.value, value); }
/** * json_node_set_string: * @node: a #JsonNode initialized to %JSON_NODE_VALUE * @value: a string value * * Sets @value as the string content of the @node, replacing any existing * content. */ void json_node_set_string (JsonNode *node, const gchar *value) { g_return_if_fail (node != NULL); g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE); if (node->data.value == NULL) node->data.value = json_value_init (json_value_alloc (), JSON_VALUE_STRING); else json_value_init (node->data.value, JSON_VALUE_STRING); json_value_set_string (node->data.value, value); }
/** * json_node_set_int: * @node: a #JsonNode of type %JSON_NODE_VALUE * @value: an integer value * * Sets @value as the integer content of the @node, replacing any existing * content. * * It is an error to call this on an immutable node. */ void json_node_set_int (JsonNode *node, gint64 value) { g_return_if_fail (JSON_NODE_IS_VALID (node)); g_return_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE); g_return_if_fail (!node->immutable); if (node->data.value == NULL) node->data.value = json_value_init (json_value_alloc (), JSON_VALUE_INT); else json_value_init (node->data.value, JSON_VALUE_INT); json_value_set_int (node->data.value, value); }