#define BABELTRACE_VALUES_H
/*
- * Babeltrace - Value objects
- *
* Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015-2016 Philippe Proulx <pproulx@efficios.com>
+ * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
/* For bt_bool */
#include <babeltrace/types.h>
+/* For enum bt_value_status, enum bt_value_type */
+#include <babeltrace/values-const.h>
+
#ifdef __cplusplus
extern "C" {
#endif
-/**
-@brief Status codes.
-*/
-enum bt_value_status {
- /// Operation canceled.
- BT_VALUE_STATUS_CANCELED = 125,
-
- /// Cannot allocate memory.
- BT_VALUE_STATUS_NOMEM = -12,
-
- /// Okay, no error.
- BT_VALUE_STATUS_OK = 0,
-};
-
struct bt_value;
-struct bt_private_value;
extern struct bt_value *bt_value_null;
-enum bt_value_type {
- /// Null value object.
- BT_VALUE_TYPE_NULL = 0,
+extern struct bt_value *bt_value_bool_create(void);
- /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
- BT_VALUE_TYPE_BOOL = 1,
+extern struct bt_value *bt_value_bool_create_init(bt_bool val);
- /// Integer value object (holds a signed 64-bit integer raw value).
- BT_VALUE_TYPE_INTEGER = 2,
+extern void bt_value_bool_set(struct bt_value *bool_obj, bt_bool val);
- /// Floating point number value object (holds a \c double raw value).
- BT_VALUE_TYPE_REAL = 3,
+extern struct bt_value *bt_value_integer_create(void);
- /// String value object.
- BT_VALUE_TYPE_STRING = 4,
+extern struct bt_value *bt_value_integer_create_init(
+ int64_t val);
- /// Array value object.
- BT_VALUE_TYPE_ARRAY = 5,
+extern void bt_value_integer_set(struct bt_value *integer_obj, int64_t val);
- /// Map value object.
- BT_VALUE_TYPE_MAP = 6,
-};
+extern struct bt_value *bt_value_real_create(void);
-extern enum bt_value_type bt_value_get_type(const struct bt_value *object);
+extern struct bt_value *bt_value_real_create_init(double val);
-static inline
-bt_bool bt_value_is_null(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_NULL;
-}
+extern void bt_value_real_set(struct bt_value *real_obj, double val);
-static inline
-bt_bool bt_value_is_bool(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_BOOL;
-}
+extern struct bt_value *bt_value_string_create(void);
-static inline
-bt_bool bt_value_is_integer(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER;
-}
+extern struct bt_value *bt_value_string_create_init(const char *val);
-static inline
-bt_bool bt_value_is_real(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_REAL;
-}
+extern enum bt_value_status bt_value_string_set(struct bt_value *string_obj,
+ const char *val);
-static inline
-bt_bool bt_value_is_string(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_STRING;
-}
+extern struct bt_value *bt_value_array_create(void);
-static inline
-bt_bool bt_value_is_array(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_ARRAY;
-}
+extern struct bt_value *bt_value_array_borrow_element_by_index(
+ struct bt_value *array_obj, uint64_t index);
-static inline
-bt_bool bt_value_is_map(const struct bt_value *object)
-{
- return bt_value_get_type(object) == BT_VALUE_TYPE_MAP;
-}
+extern enum bt_value_status bt_value_array_append_element(
+ struct bt_value *array_obj,
+ struct bt_value *element_obj);
-extern enum bt_value_status bt_value_copy(struct bt_private_value **copy,
- const struct bt_value *object);
+extern enum bt_value_status bt_value_array_append_bool_element(
+ struct bt_value *array_obj, bt_bool val);
-extern bt_bool bt_value_compare(const struct bt_value *object_a,
- const struct bt_value *object_b);
+extern enum bt_value_status bt_value_array_append_integer_element(
+ struct bt_value *array_obj, int64_t val);
-extern bt_bool bt_value_bool_get(const struct bt_value *bool_obj);
+extern enum bt_value_status bt_value_array_append_real_element(
+ struct bt_value *array_obj, double val);
-extern int64_t bt_value_integer_get(const struct bt_value *integer_obj);
+extern enum bt_value_status bt_value_array_append_string_element(
+ struct bt_value *array_obj, const char *val);
-extern double bt_value_real_get(const struct bt_value *real_obj);
+extern enum bt_value_status bt_value_array_append_empty_array_element(
+ struct bt_value *array_obj);
-extern const char *bt_value_string_get(const struct bt_value *string_obj);
+extern enum bt_value_status bt_value_array_append_empty_map_element(
+ struct bt_value *array_obj);
-extern uint64_t bt_value_array_get_size(const struct bt_value *array_obj);
+extern enum bt_value_status bt_value_array_set_element_by_index(
+ struct bt_value *array_obj, uint64_t index,
+ struct bt_value *element_obj);
-static inline
-bt_bool bt_value_array_is_empty(const struct bt_value *array_obj)
-{
- return bt_value_array_get_size(array_obj) == 0;
-}
+extern struct bt_value *bt_value_map_create(void);
-extern struct bt_value *bt_value_array_borrow_element_by_index(
- const struct bt_value *array_obj, uint64_t index);
+extern struct bt_value *bt_value_map_borrow_entry_value(
+ struct bt_value *map_obj, const char *key);
-extern uint64_t bt_value_map_get_size(const struct bt_value *map_obj);
+typedef bt_bool (* bt_value_map_foreach_entry_func)(const char *key,
+ struct bt_value *object, void *data);
-static inline
-bt_bool bt_value_map_is_empty(const struct bt_value *map_obj)
-{
- return bt_value_map_get_size(map_obj) == 0;
-}
+extern enum bt_value_status bt_value_map_foreach_entry(
+ struct bt_value *map_obj,
+ bt_value_map_foreach_entry_func func, void *data);
-extern struct bt_value *bt_value_map_borrow_entry_value(
- const struct bt_value *map_obj, const char *key);
+extern enum bt_value_status bt_value_map_insert_entry(
+ struct bt_value *map_obj, const char *key,
+ struct bt_value *element_obj);
-typedef bt_bool (* bt_value_map_foreach_entry_cb)(const char *key,
- struct bt_value *object, void *data);
+extern enum bt_value_status bt_value_map_insert_bool_entry(
+ struct bt_value *map_obj, const char *key, bt_bool val);
-extern enum bt_value_status bt_value_map_foreach_entry(
- const struct bt_value *map_obj,
- bt_value_map_foreach_entry_cb cb, void *data);
+extern enum bt_value_status bt_value_map_insert_integer_entry(
+ struct bt_value *map_obj, const char *key, int64_t val);
+
+extern enum bt_value_status bt_value_map_insert_real_entry(
+ struct bt_value *map_obj, const char *key, double val);
+
+extern enum bt_value_status bt_value_map_insert_string_entry(
+ struct bt_value *map_obj, const char *key,
+ const char *val);
-extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj,
- const char *key);
+extern enum bt_value_status bt_value_map_insert_empty_array_entry(
+ struct bt_value *map_obj, const char *key);
-extern enum bt_value_status bt_value_map_extend(
- struct bt_private_value **extended_map_obj,
- const struct bt_value *base_map_obj,
- const struct bt_value *extension_map_obj);
+extern enum bt_value_status bt_value_map_insert_empty_map_entry(
+ struct bt_value *map_obj, const char *key);
#ifdef __cplusplus
}