#include <babeltrace/object-internal.h>
#include <babeltrace/ref.h>
#include <babeltrace/values.h>
-#include <glib.h>
+#include <babeltrace/compat/glib.h>
#define BT_VALUE_FROM_CONCRETE(_concrete) ((struct bt_value *) (_concrete))
#define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
static
struct bt_value bt_value_null_instance = {
+ .base = {
+ .ref_count = {
+ .count = 1,
+ .release = NULL,
+ },
+ .release = NULL,
+ .parent = NULL,
+ },
.type = BT_VALUE_TYPE_NULL,
.is_frozen = true,
};
g_hash_table_iter_init(&iter, typed_map_obj->ght);
while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
- const char *key_str = g_quark_to_string((unsigned long) key);
+ const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
element_obj_copy = bt_value_copy(element_obj);
while (g_hash_table_iter_next(&iter, &key, &element_obj_a)) {
struct bt_value *element_obj_b;
- const char *key_str = g_quark_to_string((unsigned long) key);
+ const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
element_obj_b = bt_value_map_get(object_b, key_str);
}
array_obj->base = bt_value_create_base(BT_VALUE_TYPE_ARRAY);
- array_obj->garray = g_ptr_array_new_full(0,
+ array_obj->garray = bt_g_ptr_array_new_full(0,
(GDestroyNotify) bt_put);
if (!array_obj->garray) {
}
enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj,
- bool *val)
+ bool *val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_bool *typed_bool_obj = BT_VALUE_TO_BOOL(bool_obj);
}
enum bt_value_status bt_value_integer_get(const struct bt_value *integer_obj,
- int64_t *val)
+ int64_t *val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_integer *typed_integer_obj =
}
enum bt_value_status bt_value_integer_set(struct bt_value *integer_obj,
- int64_t val)
+ int64_t val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_integer *typed_integer_obj =
}
enum bt_value_status bt_value_float_get(const struct bt_value *float_obj,
- double *val)
+ double *val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_float *typed_float_obj =
}
enum bt_value_status bt_value_float_set(struct bt_value *float_obj,
- double val)
+ double val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_float *typed_float_obj =
}
enum bt_value_status bt_value_string_get(const struct bt_value *string_obj,
- const char **val)
+ const char **val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_string *typed_string_obj =
}
enum bt_value_status bt_value_string_set(struct bt_value *string_obj,
- const char *val)
+ const char *val)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_string *typed_string_obj =
}
struct bt_value *bt_value_array_get(const struct bt_value *array_obj,
- size_t index)
+ size_t index)
{
struct bt_value *ret;
struct bt_value_array *typed_array_obj =
}
enum bt_value_status bt_value_array_append(struct bt_value *array_obj,
- struct bt_value *element_obj)
+ struct bt_value *element_obj)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_array *typed_array_obj =
}
enum bt_value_status bt_value_array_append_bool(struct bt_value *array_obj,
- bool val)
+ bool val)
{
enum bt_value_status ret;
struct bt_value *bool_obj = NULL;
}
enum bt_value_status bt_value_array_append_integer(
- struct bt_value *array_obj, int64_t val)
+ struct bt_value *array_obj, int64_t val)
{
enum bt_value_status ret;
struct bt_value *integer_obj = NULL;
}
enum bt_value_status bt_value_array_append_float(struct bt_value *array_obj,
- double val)
+ double val)
{
enum bt_value_status ret;
struct bt_value *float_obj = NULL;
}
enum bt_value_status bt_value_array_append_string(struct bt_value *array_obj,
- const char *val)
+ const char *val)
{
enum bt_value_status ret;
struct bt_value *string_obj = NULL;
return ret;
}
-enum bt_value_status bt_value_array_append_array(struct bt_value *array_obj)
+enum bt_value_status bt_value_array_append_empty_array(
+ struct bt_value *array_obj)
{
enum bt_value_status ret;
struct bt_value *empty_array_obj = NULL;
return ret;
}
-enum bt_value_status bt_value_array_append_map(struct bt_value *array_obj)
+enum bt_value_status bt_value_array_append_empty_map(struct bt_value *array_obj)
{
enum bt_value_status ret;
struct bt_value *map_obj = NULL;
}
enum bt_value_status bt_value_array_set(struct bt_value *array_obj,
- size_t index, struct bt_value *element_obj)
+ size_t index, struct bt_value *element_obj)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
struct bt_value_array *typed_array_obj =
}
struct bt_value *bt_value_map_get(const struct bt_value *map_obj,
- const char *key)
+ const char *key)
{
GQuark quark;
struct bt_value *ret;
}
quark = g_quark_from_string(key);
- ret = g_hash_table_contains(typed_map_obj->ght,
+ ret = bt_g_hash_table_contains(typed_map_obj->ght,
GUINT_TO_POINTER(quark));
end:
}
enum bt_value_status bt_value_map_insert(struct bt_value *map_obj,
- const char *key, struct bt_value *element_obj)
+ const char *key, struct bt_value *element_obj)
{
GQuark quark;
enum bt_value_status ret = BT_VALUE_STATUS_OK;
}
enum bt_value_status bt_value_map_insert_bool(struct bt_value *map_obj,
- const char *key, bool val)
+ const char *key, bool val)
{
enum bt_value_status ret;
struct bt_value *bool_obj = NULL;
}
enum bt_value_status bt_value_map_insert_integer(struct bt_value *map_obj,
- const char *key, int64_t val)
+ const char *key, int64_t val)
{
enum bt_value_status ret;
struct bt_value *integer_obj = NULL;
}
enum bt_value_status bt_value_map_insert_float(struct bt_value *map_obj,
- const char *key, double val)
+ const char *key, double val)
{
enum bt_value_status ret;
struct bt_value *float_obj = NULL;
}
enum bt_value_status bt_value_map_insert_string(struct bt_value *map_obj,
- const char *key, const char *val)
+ const char *key, const char *val)
{
enum bt_value_status ret;
struct bt_value *string_obj = NULL;
return ret;
}
-enum bt_value_status bt_value_map_insert_array(struct bt_value *map_obj,
- const char *key)
+enum bt_value_status bt_value_map_insert_empty_array(struct bt_value *map_obj,
+ const char *key)
{
enum bt_value_status ret;
struct bt_value *array_obj = NULL;
return ret;
}
-enum bt_value_status bt_value_map_insert_map(struct bt_value *map_obj,
- const char *key)
+enum bt_value_status bt_value_map_insert_empty_map(struct bt_value *map_obj,
+ const char *key)
{
enum bt_value_status ret;
struct bt_value *empty_map_obj = NULL;
}
enum bt_value_status bt_value_map_foreach(const struct bt_value *map_obj,
- bt_value_map_foreach_cb cb, void *data)
+ bt_value_map_foreach_cb cb, void *data)
{
enum bt_value_status ret = BT_VALUE_STATUS_OK;
gpointer key, element_obj;
g_hash_table_iter_init(&iter, typed_map_obj->ght);
while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
- const char *key_str = g_quark_to_string((unsigned long) key);
+ const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
if (!cb(key_str, element_obj, data)) {
ret = BT_VALUE_STATUS_CANCELLED;
return ret;
}
+struct extend_map_element_data {
+ struct bt_value *extended_obj;
+ bool got_error;
+};
+
+static
+bool extend_map_element(const char *key,
+ struct bt_value *extension_obj_elem, void *data)
+{
+ bool ret = true;
+
+ struct extend_map_element_data *extend_data = data;
+
+ /* Copy object which is to replace the current one */
+ struct bt_value *extension_obj_elem_copy =
+ bt_value_copy(extension_obj_elem);
+
+ /* Replace in extended object */
+ if (bt_value_map_insert(extend_data->extended_obj, key,
+ extension_obj_elem_copy)) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ ret = false;
+ extend_data->got_error = true;
+
+end:
+ BT_PUT(extension_obj_elem_copy);
+
+ return ret;
+}
+
+struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj,
+ struct bt_value *extension_obj)
+{
+ struct bt_value *extended_obj = NULL;
+ struct extend_map_element_data extend_data = { 0 };
+
+ if (!bt_value_is_map(base_map_obj) || !bt_value_is_map(extension_obj)) {
+ goto error;
+ }
+
+ /* Create copy of base map object to start with */
+ extended_obj = bt_value_copy(base_map_obj);
+ if (!extended_obj) {
+ goto error;
+ }
+
+ /*
+ * For each key in the extension map object, replace this key
+ * in the copied map object.
+ */
+ extend_data.extended_obj = extended_obj;
+
+ if (bt_value_map_foreach(extension_obj, extend_map_element,
+ &extend_data)) {
+ goto error;
+ }
+
+ if (extend_data.got_error) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ BT_PUT(extended_obj);
+
+end:
+ return extended_obj;
+}
+
struct bt_value *bt_value_copy(const struct bt_value *object)
{
struct bt_value *copy_obj = NULL;