tap-driver.sh: flush stdout after each test result
[babeltrace.git] / bindings / python / bt2 / bt2 / native_bt_value.i
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
27 typedef 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
38 typedef enum bt_value_type {
39 /// Null value object.
40 BT_VALUE_TYPE_NULL = 0,
41
42 /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
43 BT_VALUE_TYPE_BOOL = 1,
44
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,
50
51 /// Floating point number value object (holds a \c double raw value).
52 BT_VALUE_TYPE_REAL = 4,
53
54 /// String value object.
55 BT_VALUE_TYPE_STRING = 5,
56
57 /// Array value object.
58 BT_VALUE_TYPE_ARRAY = 6,
59
60 /// Map value object.
61 BT_VALUE_TYPE_MAP = 7,
62 } bt_value_type;
63
64 extern bt_value_type bt_value_get_type(const bt_value *object);
65
66 extern bt_value_status bt_value_copy(const bt_value *object,
67 bt_value **copy);
68
69 extern bt_bool bt_value_compare(const bt_value *object_a,
70 const bt_value *object_b);
71
72 extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
73
74 extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
75
76 extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
77
78 extern double bt_value_real_get(const bt_value *real_obj);
79
80 extern const char *bt_value_string_get(const bt_value *string_obj);
81
82 extern uint64_t bt_value_array_get_size(const bt_value *array_obj);
83
84 extern const bt_value *bt_value_array_borrow_element_by_index_const(
85 const bt_value *array_obj, uint64_t index);
86
87 extern uint64_t bt_value_map_get_size(const bt_value *map_obj);
88
89 extern const bt_value *bt_value_map_borrow_entry_value_const(
90 const bt_value *map_obj, const char *key);
91
92 typedef bt_bool (* bt_value_map_foreach_entry_const_func)(const char *key,
93 const bt_value *object, void *data);
94
95 extern 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
99 extern bt_bool bt_value_map_has_entry(const bt_value *map_obj,
100 const char *key);
101
102 extern 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
107 extern void bt_value_get_ref(const bt_value *value);
108
109 extern void bt_value_put_ref(const bt_value *value);
110
111 /* From value.h */
112
113 extern bt_value *const bt_value_null;
114
115 extern bt_value *bt_value_bool_create(void);
116
117 extern bt_value *bt_value_bool_create_init(bt_bool val);
118
119 extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
120
121 extern bt_value *bt_value_unsigned_integer_create(void);
122
123 extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
124
125 extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
126
127 extern bt_value *bt_value_signed_integer_create(void);
128
129 extern bt_value *bt_value_signed_integer_create_init(int64_t val);
130
131 extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
132
133 extern bt_value *bt_value_real_create(void);
134
135 extern bt_value *bt_value_real_create_init(double val);
136
137 extern void bt_value_real_set(bt_value *real_obj, double val);
138
139 extern bt_value *bt_value_string_create(void);
140
141 extern bt_value *bt_value_string_create_init(const char *val);
142
143 extern bt_value_status bt_value_string_set(bt_value *string_obj,
144 const char *val);
145
146 extern bt_value *bt_value_array_create(void);
147
148 extern bt_value *bt_value_array_borrow_element_by_index(
149 bt_value *array_obj, uint64_t index);
150
151 extern bt_value_status bt_value_array_append_element(
152 bt_value *array_obj,
153 bt_value *element_obj);
154
155 extern bt_value_status bt_value_array_append_bool_element(
156 bt_value *array_obj, bt_bool val);
157
158 extern bt_value_status bt_value_array_append_unsigned_integer_element(
159 bt_value *array_obj, uint64_t val);
160
161 extern bt_value_status bt_value_array_append_signed_integer_element(
162 bt_value *array_obj, int64_t val);
163
164 extern bt_value_status bt_value_array_append_real_element(
165 bt_value *array_obj, double val);
166
167 extern bt_value_status bt_value_array_append_string_element(
168 bt_value *array_obj, const char *val);
169
170 extern bt_value_status bt_value_array_append_empty_array_element(
171 bt_value *array_obj);
172
173 extern bt_value_status bt_value_array_append_empty_map_element(
174 bt_value *array_obj);
175
176 extern bt_value_status bt_value_array_set_element_by_index(
177 bt_value *array_obj, uint64_t index,
178 bt_value *element_obj);
179
180 extern bt_value *bt_value_map_create(void);
181
182 extern bt_value *bt_value_map_borrow_entry_value(
183 bt_value *map_obj, const char *key);
184
185 typedef bt_bool (* bt_value_map_foreach_entry_func)(const char *key,
186 bt_value *object, void *data);
187
188 extern bt_value_status bt_value_map_foreach_entry(
189 bt_value *map_obj,
190 bt_value_map_foreach_entry_func func, void *data);
191
192 extern bt_value_status bt_value_map_insert_entry(
193 bt_value *map_obj, const char *key,
194 bt_value *element_obj);
195
196 extern bt_value_status bt_value_map_insert_bool_entry(
197 bt_value *map_obj, const char *key, bt_bool val);
198
199 extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
200 bt_value *map_obj, const char *key, uint64_t val);
201
202 extern bt_value_status bt_value_map_insert_signed_integer_entry(
203 bt_value *map_obj, const char *key, int64_t val);
204
205 extern bt_value_status bt_value_map_insert_real_entry(
206 bt_value *map_obj, const char *key, double val);
207
208 extern bt_value_status bt_value_map_insert_string_entry(
209 bt_value *map_obj, const char *key,
210 const char *val);
211
212 extern bt_value_status bt_value_map_insert_empty_array_entry(
213 bt_value *map_obj, const char *key);
214
215 extern bt_value_status bt_value_map_insert_empty_map_entry(
216 bt_value *map_obj, const char *key);
217
218 %{
219 struct bt_value_map_get_keys_data {
220 struct bt_value *keys;
221 };
222
223 static 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
236 static 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
254 error:
255 if (data.keys) {
256 BT_VALUE_PUT_REF_AND_RESET(data.keys);
257 }
258
259 end:
260 return data.keys;
261 }
262 %}
263
264 struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj);
This page took 0.034486 seconds and 4 git commands to generate.