tap-driver.sh: flush stdout after each test result
[babeltrace.git] / bindings / python / bt2 / bt2 / native_bt_value.i
CommitLineData
6945df9a
SM
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
24
25/* From value-const.h */
26
27typedef enum bt_value_status {
28 /// Operation canceled.
29 BT_VALUE_STATUS_CANCELED = 125,
30
31 /// Cannot allocate memory.
32 BT_VALUE_STATUS_NOMEM = -12,
33
34 /// Okay, no error.
35 BT_VALUE_STATUS_OK = 0,
36} bt_value_status;
37
38typedef enum bt_value_type {
39 /// Null value object.
fdd3a2da 40 BT_VALUE_TYPE_NULL = 0,
6945df9a
SM
41
42 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
fdd3a2da 43 BT_VALUE_TYPE_BOOL = 1,
6945df9a 44
fdd3a2da
PP
45 /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
46 BT_VALUE_TYPE_UNSIGNED_INTEGER = 2,
47
48 /// Signed integer value object (holds a signed 64-bit integer raw value).
49 BT_VALUE_TYPE_SIGNED_INTEGER = 3,
6945df9a
SM
50
51 /// Floating point number value object (holds a \c double raw value).
fdd3a2da 52 BT_VALUE_TYPE_REAL = 4,
6945df9a
SM
53
54 /// String value object.
fdd3a2da 55 BT_VALUE_TYPE_STRING = 5,
6945df9a
SM
56
57 /// Array value object.
fdd3a2da 58 BT_VALUE_TYPE_ARRAY = 6,
6945df9a
SM
59
60 /// Map value object.
fdd3a2da 61 BT_VALUE_TYPE_MAP = 7,
6945df9a
SM
62} bt_value_type;
63
64extern bt_value_type bt_value_get_type(const bt_value *object);
65
6945df9a 66extern bt_value_status bt_value_copy(const bt_value *object,
fdd3a2da 67 bt_value **copy);
6945df9a
SM
68
69extern bt_bool bt_value_compare(const bt_value *object_a,
70 const bt_value *object_b);
71
72extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
73
fdd3a2da
PP
74extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
75
76extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
6945df9a
SM
77
78extern double bt_value_real_get(const bt_value *real_obj);
79
80extern const char *bt_value_string_get(const bt_value *string_obj);
81
82extern uint64_t bt_value_array_get_size(const bt_value *array_obj);
83
6945df9a
SM
84extern const bt_value *bt_value_array_borrow_element_by_index_const(
85 const bt_value *array_obj, uint64_t index);
86
87extern uint64_t bt_value_map_get_size(const bt_value *map_obj);
88
6945df9a
SM
89extern const bt_value *bt_value_map_borrow_entry_value_const(
90 const bt_value *map_obj, const char *key);
91
92typedef bt_bool (* bt_value_map_foreach_entry_const_func)(const char *key,
93 const bt_value *object, void *data);
94
95extern bt_value_status bt_value_map_foreach_entry_const(
96 const bt_value *map_obj,
97 bt_value_map_foreach_entry_const_func func, void *data);
98
99extern bt_bool bt_value_map_has_entry(const bt_value *map_obj,
100 const char *key);
101
102extern bt_value_status bt_value_map_extend(
103 const bt_value *base_map_obj,
104 const bt_value *extension_map_obj,
105 bt_value **extended_map_obj);
106
107extern void bt_value_get_ref(const bt_value *value);
108
109extern void bt_value_put_ref(const bt_value *value);
110
111/* From value.h */
112
113extern bt_value *const bt_value_null;
114
115extern bt_value *bt_value_bool_create(void);
116
117extern bt_value *bt_value_bool_create_init(bt_bool val);
118
119extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
120
fdd3a2da
PP
121extern bt_value *bt_value_unsigned_integer_create(void);
122
123extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
6945df9a 124
fdd3a2da 125extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
6945df9a 126
fdd3a2da
PP
127extern bt_value *bt_value_signed_integer_create(void);
128
129extern bt_value *bt_value_signed_integer_create_init(int64_t val);
130
131extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
6945df9a
SM
132
133extern bt_value *bt_value_real_create(void);
134
135extern bt_value *bt_value_real_create_init(double val);
136
137extern void bt_value_real_set(bt_value *real_obj, double val);
138
139extern bt_value *bt_value_string_create(void);
140
141extern bt_value *bt_value_string_create_init(const char *val);
142
143extern bt_value_status bt_value_string_set(bt_value *string_obj,
144 const char *val);
145
146extern bt_value *bt_value_array_create(void);
147
148extern bt_value *bt_value_array_borrow_element_by_index(
149 bt_value *array_obj, uint64_t index);
150
151extern bt_value_status bt_value_array_append_element(
152 bt_value *array_obj,
153 bt_value *element_obj);
154
155extern bt_value_status bt_value_array_append_bool_element(
156 bt_value *array_obj, bt_bool val);
157
fdd3a2da
PP
158extern bt_value_status bt_value_array_append_unsigned_integer_element(
159 bt_value *array_obj, uint64_t val);
160
161extern bt_value_status bt_value_array_append_signed_integer_element(
6945df9a
SM
162 bt_value *array_obj, int64_t val);
163
164extern bt_value_status bt_value_array_append_real_element(
165 bt_value *array_obj, double val);
166
167extern bt_value_status bt_value_array_append_string_element(
168 bt_value *array_obj, const char *val);
169
170extern bt_value_status bt_value_array_append_empty_array_element(
171 bt_value *array_obj);
172
173extern bt_value_status bt_value_array_append_empty_map_element(
174 bt_value *array_obj);
175
176extern bt_value_status bt_value_array_set_element_by_index(
177 bt_value *array_obj, uint64_t index,
178 bt_value *element_obj);
179
180extern bt_value *bt_value_map_create(void);
181
182extern bt_value *bt_value_map_borrow_entry_value(
183 bt_value *map_obj, const char *key);
184
185typedef bt_bool (* bt_value_map_foreach_entry_func)(const char *key,
186 bt_value *object, void *data);
187
188extern bt_value_status bt_value_map_foreach_entry(
189 bt_value *map_obj,
190 bt_value_map_foreach_entry_func func, void *data);
191
192extern bt_value_status bt_value_map_insert_entry(
193 bt_value *map_obj, const char *key,
194 bt_value *element_obj);
195
196extern bt_value_status bt_value_map_insert_bool_entry(
197 bt_value *map_obj, const char *key, bt_bool val);
198
fdd3a2da
PP
199extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
200 bt_value *map_obj, const char *key, uint64_t val);
201
202extern bt_value_status bt_value_map_insert_signed_integer_entry(
6945df9a
SM
203 bt_value *map_obj, const char *key, int64_t val);
204
205extern bt_value_status bt_value_map_insert_real_entry(
206 bt_value *map_obj, const char *key, double val);
207
208extern bt_value_status bt_value_map_insert_string_entry(
209 bt_value *map_obj, const char *key,
210 const char *val);
211
212extern bt_value_status bt_value_map_insert_empty_array_entry(
213 bt_value *map_obj, const char *key);
214
215extern bt_value_status bt_value_map_insert_empty_map_entry(
216 bt_value *map_obj, const char *key);
217
218%{
219struct bt_value_map_get_keys_data {
220 struct bt_value *keys;
221};
222
223static int bt_value_map_get_keys_cb(const char *key, const struct bt_value *object, void *data)
224{
225 enum bt_value_status status;
226 struct bt_value_map_get_keys_data *priv_data = data;
227
228 status = bt_value_array_append_string_element(priv_data->keys, key);
229 if (status != BT_VALUE_STATUS_OK) {
230 return BT_FALSE;
231 }
232
233 return BT_TRUE;
234}
235
236static struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj)
237{
238 enum bt_value_status status;
239 struct bt_value_map_get_keys_data data;
240
241 data.keys = bt_value_array_create();
242 if (!data.keys) {
243 return NULL;
244 }
245
246 status = bt_value_map_foreach_entry_const(map_obj, bt_value_map_get_keys_cb,
247 &data);
248 if (status != BT_VALUE_STATUS_OK) {
249 goto error;
250 }
251
252 goto end;
253
254error:
255 if (data.keys) {
256 BT_VALUE_PUT_REF_AND_RESET(data.keys);
257 }
258
259end:
260 return data.keys;
261}
262%}
263
264struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj);
This page took 0.035691 seconds and 4 git commands to generate.