Commit | Line | Data |
---|---|---|
1ca80abd PP |
1 | #ifndef BABELTRACE_VALUES_H |
2 | #define BABELTRACE_VALUES_H | |
dac5c838 PP |
3 | |
4 | /* | |
de079588 | 5 | * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation |
05e21286 | 6 | * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com> |
dac5c838 PP |
7 | * |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
dac5c838 | 27 | #include <stdint.h> |
dac5c838 | 28 | #include <stddef.h> |
9d408fca PP |
29 | |
30 | /* For bt_bool */ | |
c55a9f58 | 31 | #include <babeltrace/types.h> |
dac5c838 PP |
32 | |
33 | #ifdef __cplusplus | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
dac5c838 | 37 | enum bt_value_status { |
f6ccaed9 | 38 | /// Operation canceled. |
601b0d3c | 39 | BT_VALUE_STATUS_CANCELED = 125, |
dac5c838 | 40 | |
601b0d3c PP |
41 | /// Cannot allocate memory. |
42 | BT_VALUE_STATUS_NOMEM = -12, | |
dac5c838 | 43 | |
de079588 | 44 | /// Okay, no error. |
601b0d3c | 45 | BT_VALUE_STATUS_OK = 0, |
dac5c838 PP |
46 | }; |
47 | ||
de079588 | 48 | enum bt_value_type { |
de079588 PP |
49 | /// Null value object. |
50 | BT_VALUE_TYPE_NULL = 0, | |
51 | ||
c55a9f58 | 52 | /// Boolean value object (holds #BT_TRUE or #BT_FALSE). |
de079588 PP |
53 | BT_VALUE_TYPE_BOOL = 1, |
54 | ||
55 | /// Integer value object (holds a signed 64-bit integer raw value). | |
56 | BT_VALUE_TYPE_INTEGER = 2, | |
57 | ||
58 | /// Floating point number value object (holds a \c double raw value). | |
a373bf69 | 59 | BT_VALUE_TYPE_REAL = 3, |
de079588 PP |
60 | |
61 | /// String value object. | |
62 | BT_VALUE_TYPE_STRING = 4, | |
63 | ||
64 | /// Array value object. | |
65 | BT_VALUE_TYPE_ARRAY = 5, | |
66 | ||
67 | /// Map value object. | |
68 | BT_VALUE_TYPE_MAP = 6, | |
69 | }; | |
dac5c838 | 70 | |
05e21286 | 71 | struct bt_value; |
dac5c838 | 72 | |
05e21286 | 73 | extern struct bt_value *bt_value_null; |
dac5c838 | 74 | |
05e21286 | 75 | extern struct bt_value *bt_value_bool_create(void); |
dac5c838 | 76 | |
05e21286 | 77 | extern struct bt_value *bt_value_bool_create_init(bt_bool val); |
dac5c838 | 78 | |
05e21286 | 79 | extern void bt_value_bool_set(struct bt_value *bool_obj, bt_bool val); |
dac5c838 | 80 | |
05e21286 | 81 | extern struct bt_value *bt_value_integer_create(void); |
dac5c838 | 82 | |
05e21286 PP |
83 | extern struct bt_value *bt_value_integer_create_init( |
84 | int64_t val); | |
dac5c838 | 85 | |
05e21286 | 86 | extern void bt_value_integer_set(struct bt_value *integer_obj, int64_t val); |
de079588 | 87 | |
05e21286 | 88 | extern struct bt_value *bt_value_real_create(void); |
de079588 | 89 | |
05e21286 | 90 | extern struct bt_value *bt_value_real_create_init(double val); |
dac5c838 | 91 | |
05e21286 | 92 | extern void bt_value_real_set(struct bt_value *real_obj, double val); |
dac5c838 | 93 | |
05e21286 | 94 | extern struct bt_value *bt_value_string_create(void); |
dac5c838 | 95 | |
05e21286 | 96 | extern struct bt_value *bt_value_string_create_init(const char *val); |
dac5c838 | 97 | |
05e21286 PP |
98 | extern enum bt_value_status bt_value_string_set(struct bt_value *string_obj, |
99 | const char *val); | |
de079588 | 100 | |
05e21286 | 101 | extern struct bt_value *bt_value_array_create(void); |
dac5c838 | 102 | |
07208d85 | 103 | extern struct bt_value *bt_value_array_borrow_element_by_index( |
05e21286 | 104 | struct bt_value *array_obj, uint64_t index); |
dac5c838 | 105 | |
05e21286 PP |
106 | extern enum bt_value_status bt_value_array_append_element( |
107 | struct bt_value *array_obj, | |
108 | struct bt_value *element_obj); | |
dac5c838 | 109 | |
05e21286 PP |
110 | extern enum bt_value_status bt_value_array_append_bool_element( |
111 | struct bt_value *array_obj, bt_bool val); | |
112 | ||
113 | extern enum bt_value_status bt_value_array_append_integer_element( | |
114 | struct bt_value *array_obj, int64_t val); | |
115 | ||
116 | extern enum bt_value_status bt_value_array_append_real_element( | |
117 | struct bt_value *array_obj, double val); | |
118 | ||
119 | extern enum bt_value_status bt_value_array_append_string_element( | |
120 | struct bt_value *array_obj, const char *val); | |
121 | ||
122 | extern enum bt_value_status bt_value_array_append_empty_array_element( | |
123 | struct bt_value *array_obj); | |
124 | ||
125 | extern enum bt_value_status bt_value_array_append_empty_map_element( | |
126 | struct bt_value *array_obj); | |
127 | ||
128 | extern enum bt_value_status bt_value_array_set_element_by_index( | |
129 | struct bt_value *array_obj, uint64_t index, | |
130 | struct bt_value *element_obj); | |
131 | ||
132 | extern struct bt_value *bt_value_map_create(void); | |
dac5c838 | 133 | |
07208d85 | 134 | extern struct bt_value *bt_value_map_borrow_entry_value( |
05e21286 | 135 | struct bt_value *map_obj, const char *key); |
dac5c838 | 136 | |
07208d85 | 137 | typedef bt_bool (* bt_value_map_foreach_entry_cb)(const char *key, |
05e21286 | 138 | struct bt_value *object, void *data); |
de079588 | 139 | |
07208d85 | 140 | extern enum bt_value_status bt_value_map_foreach_entry( |
05e21286 | 141 | struct bt_value *map_obj, |
07208d85 | 142 | bt_value_map_foreach_entry_cb cb, void *data); |
dac5c838 | 143 | |
05e21286 PP |
144 | extern enum bt_value_status bt_value_map_insert_entry( |
145 | struct bt_value *map_obj, const char *key, | |
146 | struct bt_value *element_obj); | |
147 | ||
148 | extern enum bt_value_status bt_value_map_insert_bool_entry( | |
149 | struct bt_value *map_obj, const char *key, bt_bool val); | |
150 | ||
151 | extern enum bt_value_status bt_value_map_insert_integer_entry( | |
152 | struct bt_value *map_obj, const char *key, int64_t val); | |
153 | ||
154 | extern enum bt_value_status bt_value_map_insert_real_entry( | |
155 | struct bt_value *map_obj, const char *key, double val); | |
156 | ||
157 | extern enum bt_value_status bt_value_map_insert_string_entry( | |
158 | struct bt_value *map_obj, const char *key, | |
159 | const char *val); | |
160 | ||
161 | extern enum bt_value_status bt_value_map_insert_empty_array_entry( | |
162 | struct bt_value *map_obj, const char *key); | |
dac5c838 | 163 | |
05e21286 PP |
164 | extern enum bt_value_status bt_value_map_insert_empty_map_entry( |
165 | struct bt_value *map_obj, const char *key); | |
770750d3 | 166 | |
dac5c838 PP |
167 | #ifdef __cplusplus |
168 | } | |
169 | #endif | |
170 | ||
1ca80abd | 171 | #endif /* BABELTRACE_VALUES_H */ |