2 * The MIT License (MIT)
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include <babeltrace/values.h>
29 /* For uint*_t/int*_t */
32 /* Remove prefix from `bt_value_null` */
33 %rename(value_null) bt_value_null;
39 BT_VALUE_TYPE_UNKNOWN = -1,
40 BT_VALUE_TYPE_NULL = 0,
41 BT_VALUE_TYPE_BOOL = 1,
42 BT_VALUE_TYPE_INTEGER = 2,
43 BT_VALUE_TYPE_FLOAT = 3,
44 BT_VALUE_TYPE_STRING = 4,
45 BT_VALUE_TYPE_ARRAY = 5,
46 BT_VALUE_TYPE_MAP = 6,
49 enum bt_value_type bt_value_get_type(const struct bt_value *object);
51 enum bt_value_status {
52 BT_VALUE_STATUS_FROZEN = -4,
53 BT_VALUE_STATUS_CANCELLED = -3,
54 BT_VALUE_STATUS_INVAL = -22,
55 BT_VALUE_STATUS_ERROR = -1,
56 BT_VALUE_STATUS_OK = 0,
59 /* Null value object singleton */
60 struct bt_value * const bt_value_null;
62 /* Common functions */
63 enum bt_value_status bt_value_freeze(struct bt_value *object);
64 bool bt_value_is_frozen(const struct bt_value *object);
65 struct bt_value *bt_value_copy(const struct bt_value *object);
66 bool bt_value_compare(const struct bt_value *object_a,
67 const struct bt_value *object_b);
69 /* Boolean value object functions */
70 struct bt_value *bt_value_bool_create(void);
71 struct bt_value *bt_value_bool_create_init(bool val);
72 enum bt_value_status bt_value_bool_get(
73 const struct bt_value *bool_obj, bool *OUTPUT);
74 enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj,
77 /* Integer value object functions */
78 struct bt_value *bt_value_integer_create(void);
79 struct bt_value *bt_value_integer_create_init(int64_t val);
80 enum bt_value_status bt_value_integer_get(
81 const struct bt_value *integer_obj, int64_t *OUTPUT);
82 enum bt_value_status bt_value_integer_set(
83 struct bt_value *integer_obj, int64_t val);
85 /* Floating point number value object functions */
86 struct bt_value *bt_value_float_create(void);
87 struct bt_value *bt_value_float_create_init(double val);
88 enum bt_value_status bt_value_float_get(
89 const struct bt_value *float_obj, double *OUTPUT);
90 enum bt_value_status bt_value_float_set(
91 struct bt_value *float_obj, double val);
93 /* String value object functions */
94 struct bt_value *bt_value_string_create(void);
95 struct bt_value *bt_value_string_create_init(const char *val);
96 enum bt_value_status bt_value_string_set(struct bt_value *string_obj,
98 enum bt_value_status bt_value_string_get(
99 const struct bt_value *string_obj, const char **BTOUTSTR);
101 /* Array value object functions */
102 struct bt_value *bt_value_array_create(void);
103 int bt_value_array_size(const struct bt_value *array_obj);
104 struct bt_value *bt_value_array_get(const struct bt_value *array_obj,
106 enum bt_value_status bt_value_array_append(struct bt_value *array_obj,
107 struct bt_value *element_obj);
108 enum bt_value_status bt_value_array_set(struct bt_value *array_obj,
109 size_t index, struct bt_value *element_obj);
111 /* Map value object functions */
112 struct bt_value *bt_value_map_create(void);
113 int bt_value_map_size(const struct bt_value *map_obj);
114 struct bt_value *bt_value_map_get(const struct bt_value *map_obj,
116 bool bt_value_map_has_key(const struct bt_value *map_obj,
118 enum bt_value_status bt_value_map_insert(
119 struct bt_value *map_obj, const char *key,
120 struct bt_value *element_obj);
123 struct bt_value_map_get_keys_private_data {
124 struct bt_value *keys;
127 static bool bt_value_map_get_keys_private_cb(const char *key,
128 struct bt_value *object, void *data)
130 enum bt_value_status status;
131 struct bt_value_map_get_keys_private_data *priv_data = data;
133 status = bt_value_array_append_string(priv_data->keys, key);
134 if (status != BT_VALUE_STATUS_OK) {
141 static struct bt_value *bt_value_map_get_keys_private(
142 const struct bt_value *map_obj)
144 enum bt_value_status status;
145 struct bt_value_map_get_keys_private_data data;
147 data.keys = bt_value_array_create();
152 status = bt_value_map_foreach(map_obj, bt_value_map_get_keys_private_cb,
154 if (status != BT_VALUE_STATUS_OK) {
170 struct bt_value *bt_value_map_get_keys_private(const struct bt_value *map_obj);