Commit | Line | Data |
---|---|---|
1ca80abd PP |
1 | #ifndef BABELTRACE_VALUES_H |
2 | #define BABELTRACE_VALUES_H | |
dac5c838 PP |
3 | |
4 | /* | |
de079588 PP |
5 | * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation |
6 | * Copyright (c) 2015-2016 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 | /** |
de079588 PP |
38 | @brief Status codes. |
39 | */ | |
dac5c838 | 40 | enum bt_value_status { |
f6ccaed9 | 41 | /// Operation canceled. |
601b0d3c | 42 | BT_VALUE_STATUS_CANCELED = 125, |
dac5c838 | 43 | |
601b0d3c PP |
44 | /// Cannot allocate memory. |
45 | BT_VALUE_STATUS_NOMEM = -12, | |
dac5c838 | 46 | |
de079588 | 47 | /// Okay, no error. |
601b0d3c | 48 | BT_VALUE_STATUS_OK = 0, |
dac5c838 PP |
49 | }; |
50 | ||
dac5c838 | 51 | struct bt_value; |
da91b29a | 52 | struct bt_private_value; |
dac5c838 | 53 | |
dac5c838 PP |
54 | extern struct bt_value *bt_value_null; |
55 | ||
de079588 | 56 | enum bt_value_type { |
de079588 PP |
57 | /// Null value object. |
58 | BT_VALUE_TYPE_NULL = 0, | |
59 | ||
c55a9f58 | 60 | /// Boolean value object (holds #BT_TRUE or #BT_FALSE). |
de079588 PP |
61 | BT_VALUE_TYPE_BOOL = 1, |
62 | ||
63 | /// Integer value object (holds a signed 64-bit integer raw value). | |
64 | BT_VALUE_TYPE_INTEGER = 2, | |
65 | ||
66 | /// Floating point number value object (holds a \c double raw value). | |
a373bf69 | 67 | BT_VALUE_TYPE_REAL = 3, |
de079588 PP |
68 | |
69 | /// String value object. | |
70 | BT_VALUE_TYPE_STRING = 4, | |
71 | ||
72 | /// Array value object. | |
73 | BT_VALUE_TYPE_ARRAY = 5, | |
74 | ||
75 | /// Map value object. | |
76 | BT_VALUE_TYPE_MAP = 6, | |
77 | }; | |
dac5c838 | 78 | |
dac5c838 PP |
79 | extern enum bt_value_type bt_value_get_type(const struct bt_value *object); |
80 | ||
dac5c838 | 81 | static inline |
c55a9f58 | 82 | bt_bool bt_value_is_null(const struct bt_value *object) |
dac5c838 PP |
83 | { |
84 | return bt_value_get_type(object) == BT_VALUE_TYPE_NULL; | |
85 | } | |
86 | ||
dac5c838 | 87 | static inline |
c55a9f58 | 88 | bt_bool bt_value_is_bool(const struct bt_value *object) |
dac5c838 PP |
89 | { |
90 | return bt_value_get_type(object) == BT_VALUE_TYPE_BOOL; | |
91 | } | |
92 | ||
dac5c838 | 93 | static inline |
c55a9f58 | 94 | bt_bool bt_value_is_integer(const struct bt_value *object) |
dac5c838 PP |
95 | { |
96 | return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER; | |
97 | } | |
98 | ||
dac5c838 | 99 | static inline |
a373bf69 | 100 | bt_bool bt_value_is_real(const struct bt_value *object) |
dac5c838 | 101 | { |
a373bf69 | 102 | return bt_value_get_type(object) == BT_VALUE_TYPE_REAL; |
dac5c838 PP |
103 | } |
104 | ||
dac5c838 | 105 | static inline |
c55a9f58 | 106 | bt_bool bt_value_is_string(const struct bt_value *object) |
dac5c838 PP |
107 | { |
108 | return bt_value_get_type(object) == BT_VALUE_TYPE_STRING; | |
109 | } | |
110 | ||
dac5c838 | 111 | static inline |
c55a9f58 | 112 | bt_bool bt_value_is_array(const struct bt_value *object) |
dac5c838 PP |
113 | { |
114 | return bt_value_get_type(object) == BT_VALUE_TYPE_ARRAY; | |
115 | } | |
116 | ||
dac5c838 | 117 | static inline |
c55a9f58 | 118 | bt_bool bt_value_is_map(const struct bt_value *object) |
dac5c838 PP |
119 | { |
120 | return bt_value_get_type(object) == BT_VALUE_TYPE_MAP; | |
121 | } | |
122 | ||
601b0d3c PP |
123 | extern enum bt_value_status bt_value_copy(struct bt_private_value **copy, |
124 | const struct bt_value *object); | |
de079588 | 125 | |
c55a9f58 | 126 | extern bt_bool bt_value_compare(const struct bt_value *object_a, |
de079588 PP |
127 | const struct bt_value *object_b); |
128 | ||
601b0d3c | 129 | extern bt_bool bt_value_bool_get(const struct bt_value *bool_obj); |
dac5c838 | 130 | |
601b0d3c | 131 | extern int64_t bt_value_integer_get(const struct bt_value *integer_obj); |
dac5c838 | 132 | |
601b0d3c | 133 | extern double bt_value_real_get(const struct bt_value *real_obj); |
dac5c838 | 134 | |
601b0d3c | 135 | extern const char *bt_value_string_get(const struct bt_value *string_obj); |
dac5c838 | 136 | |
601b0d3c | 137 | extern uint64_t bt_value_array_get_size(const struct bt_value *array_obj); |
de079588 | 138 | |
601b0d3c PP |
139 | static inline |
140 | bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) | |
141 | { | |
142 | return bt_value_array_get_size(array_obj) == 0; | |
143 | } | |
dac5c838 | 144 | |
07208d85 PP |
145 | extern struct bt_value *bt_value_array_borrow_element_by_index( |
146 | const struct bt_value *array_obj, uint64_t index); | |
dac5c838 | 147 | |
601b0d3c | 148 | extern uint64_t bt_value_map_get_size(const struct bt_value *map_obj); |
dac5c838 | 149 | |
601b0d3c PP |
150 | static inline |
151 | bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) | |
152 | { | |
153 | return bt_value_map_get_size(map_obj) == 0; | |
154 | } | |
dac5c838 | 155 | |
07208d85 PP |
156 | extern struct bt_value *bt_value_map_borrow_entry_value( |
157 | const struct bt_value *map_obj, const char *key); | |
dac5c838 | 158 | |
07208d85 | 159 | typedef bt_bool (* bt_value_map_foreach_entry_cb)(const char *key, |
de079588 PP |
160 | struct bt_value *object, void *data); |
161 | ||
07208d85 PP |
162 | extern enum bt_value_status bt_value_map_foreach_entry( |
163 | const struct bt_value *map_obj, | |
164 | bt_value_map_foreach_entry_cb cb, void *data); | |
dac5c838 | 165 | |
07208d85 | 166 | extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj, |
364747d6 | 167 | const char *key); |
dac5c838 | 168 | |
601b0d3c PP |
169 | extern enum bt_value_status bt_value_map_extend( |
170 | struct bt_private_value **extended_map_obj, | |
70991d9f PP |
171 | const struct bt_value *base_map_obj, |
172 | const struct bt_value *extension_map_obj); | |
770750d3 | 173 | |
dac5c838 PP |
174 | #ifdef __cplusplus |
175 | } | |
176 | #endif | |
177 | ||
1ca80abd | 178 | #endif /* BABELTRACE_VALUES_H */ |