/*
- * values.c: value objects
+ * Values.c: value objects
*
* Babeltrace Library
*
#include <string.h>
#include <assert.h>
#include <string.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/compiler.h>
+#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))
#define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
struct bt_value {
+ struct bt_object base;
enum bt_value_type type;
- struct bt_ref ref_count;
bool is_frozen;
};
};
static
-void bt_value_destroy(struct bt_ref *ref_count);
+void bt_value_destroy(struct bt_object *obj);
static
void bt_value_string_destroy(struct bt_value *object)
struct bt_value *element_obj = bt_value_array_get(array_obj, i);
if (!element_obj) {
- BT_VALUE_PUT(copy_obj);
+ BT_PUT(copy_obj);
goto end;
}
element_obj_copy = bt_value_copy(element_obj);
- BT_VALUE_PUT(element_obj);
+ BT_PUT(element_obj);
if (!element_obj_copy) {
- BT_VALUE_PUT(copy_obj);
+ BT_PUT(copy_obj);
goto end;
}
ret = bt_value_array_append(copy_obj, element_obj_copy);
- BT_VALUE_PUT(element_obj_copy);
+ BT_PUT(element_obj_copy);
if (ret) {
- BT_VALUE_PUT(copy_obj);
+ BT_PUT(copy_obj);
goto end;
}
}
element_obj_copy = bt_value_copy(element_obj);
if (!element_obj_copy) {
- BT_VALUE_PUT(copy_obj);
+ BT_PUT(copy_obj);
goto end;
}
ret = bt_value_map_insert(copy_obj, key_str, element_obj_copy);
- BT_VALUE_PUT(element_obj_copy);
+ BT_PUT(element_obj_copy);
if (ret) {
- BT_VALUE_PUT(copy_obj);
+ BT_PUT(copy_obj);
goto end;
}
}
element_obj_b = bt_value_array_get(object_b, i);
if (!bt_value_compare(element_obj_a, element_obj_b)) {
- BT_VALUE_PUT(element_obj_a);
- BT_VALUE_PUT(element_obj_b);
+ BT_PUT(element_obj_a);
+ BT_PUT(element_obj_b);
ret = false;
goto end;
}
- BT_VALUE_PUT(element_obj_a);
- BT_VALUE_PUT(element_obj_b);
+ BT_PUT(element_obj_a);
+ BT_PUT(element_obj_b);
}
end:
element_obj_b = bt_value_map_get(object_b, key_str);
if (!bt_value_compare(element_obj_a, element_obj_b)) {
- BT_VALUE_PUT(element_obj_b);
+ BT_PUT(element_obj_b);
ret = false;
goto end;
}
- BT_VALUE_PUT(element_obj_b);
+ BT_PUT(element_obj_b);
}
end:
};
static
-void bt_value_destroy(struct bt_ref *ref_count)
+void bt_value_destroy(struct bt_object *obj)
{
- struct bt_value *object;
+ struct bt_value *value;
- object = container_of(ref_count, struct bt_value, ref_count);
- assert(object->type != BT_VALUE_TYPE_UNKNOWN);
+ value = container_of(obj, struct bt_value, base);
+ assert(value->type != BT_VALUE_TYPE_UNKNOWN);
- if (bt_value_is_null(object)) {
+ if (bt_value_is_null(value)) {
return;
}
- if (destroy_funcs[object->type]) {
- destroy_funcs[object->type](object);
+ if (destroy_funcs[value->type]) {
+ destroy_funcs[value->type](value);
}
- g_free(object);
-}
-
-void bt_value_get(struct bt_value *object)
-{
- if (object && !bt_value_is_null(object)) {
- bt_ref_get(&object->ref_count);
- }
-
- return;
-}
-
-void bt_value_put(struct bt_value *object)
-{
- if (object && !bt_value_is_null(object)) {
- bt_ref_put(&object->ref_count);
- }
+ g_free(value);
}
enum bt_value_status bt_value_freeze(struct bt_value *object)
base.type = type;
base.is_frozen = false;
- bt_ref_init(&base.ref_count, bt_value_destroy);
+ bt_object_init(&base, bt_value_destroy);
return base;
}
}
array_obj->base = bt_value_create_base(BT_VALUE_TYPE_ARRAY);
- array_obj->garray = g_ptr_array_new_full(0,
- (GDestroyNotify) bt_value_put);
+ array_obj->garray = babeltrace_g_ptr_array_new_full(0,
+ (GDestroyNotify) bt_put);
if (!array_obj->garray) {
g_free(array_obj);
map_obj->base = bt_value_create_base(BT_VALUE_TYPE_MAP);
map_obj->ght = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- NULL, (GDestroyNotify) bt_value_put);
+ NULL, (GDestroyNotify) bt_put);
if (!map_obj->ght) {
g_free(map_obj);
}
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 =
}
ret = g_ptr_array_index(typed_array_obj->garray, index);
- bt_value_get(ret);
+ bt_get(ret);
end:
return ret;
}
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 =
}
g_ptr_array_add(typed_array_obj->garray, element_obj);
- bt_value_get(element_obj);
+ bt_get(element_obj);
end:
return ret;
}
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;
bool_obj = bt_value_bool_create_init(val);
ret = bt_value_array_append(array_obj, bool_obj);
- bt_value_put(bool_obj);
+ bt_put(bool_obj);
return ret;
}
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;
integer_obj = bt_value_integer_create_init(val);
ret = bt_value_array_append(array_obj, integer_obj);
- bt_value_put(integer_obj);
+ bt_put(integer_obj);
return ret;
}
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;
float_obj = bt_value_float_create_init(val);
ret = bt_value_array_append(array_obj, float_obj);
- bt_value_put(float_obj);
+ bt_put(float_obj);
return ret;
}
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;
string_obj = bt_value_string_create_init(val);
ret = bt_value_array_append(array_obj, string_obj);
- bt_value_put(string_obj);
+ bt_put(string_obj);
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;
empty_array_obj = bt_value_array_create();
ret = bt_value_array_append(array_obj, empty_array_obj);
- bt_value_put(empty_array_obj);
+ bt_put(empty_array_obj);
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;
map_obj = bt_value_map_create();
ret = bt_value_array_append(array_obj, map_obj);
- bt_value_put(map_obj);
+ bt_put(map_obj);
return ret;
}
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 =
goto end;
}
- bt_value_put(g_ptr_array_index(typed_array_obj->garray, index));
+ bt_put(g_ptr_array_index(typed_array_obj->garray, index));
g_ptr_array_index(typed_array_obj->garray, index) = element_obj;
- bt_value_get(element_obj);
+ bt_get(element_obj);
end:
return ret;
}
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;
ret = g_hash_table_lookup(typed_map_obj->ght, GUINT_TO_POINTER(quark));
if (ret) {
- bt_value_get(ret);
+ bt_get(ret);
}
end:
}
quark = g_quark_from_string(key);
- ret = g_hash_table_contains(typed_map_obj->ght,
+ ret = babeltrace_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;
quark = g_quark_from_string(key);
g_hash_table_insert(typed_map_obj->ght,
GUINT_TO_POINTER(quark), element_obj);
- bt_value_get(element_obj);
+ bt_get(element_obj);
end:
return ret;
}
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;
bool_obj = bt_value_bool_create_init(val);
ret = bt_value_map_insert(map_obj, key, bool_obj);
- bt_value_put(bool_obj);
+ bt_put(bool_obj);
return ret;
}
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;
integer_obj = bt_value_integer_create_init(val);
ret = bt_value_map_insert(map_obj, key, integer_obj);
- bt_value_put(integer_obj);
+ bt_put(integer_obj);
return ret;
}
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;
float_obj = bt_value_float_create_init(val);
ret = bt_value_map_insert(map_obj, key, float_obj);
- bt_value_put(float_obj);
+ bt_put(float_obj);
return ret;
}
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;
string_obj = bt_value_string_create_init(val);
ret = bt_value_map_insert(map_obj, key, string_obj);
- bt_value_put(string_obj);
+ bt_put(string_obj);
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;
array_obj = bt_value_array_create();
ret = bt_value_map_insert(map_obj, key, array_obj);
- bt_value_put(array_obj);
+ bt_put(array_obj);
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;
empty_map_obj = bt_value_map_create();
ret = bt_value_map_insert(map_obj, key, empty_map_obj);
- bt_value_put(empty_map_obj);
+ bt_put(empty_map_obj);
return ret;
}
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;