Commit | Line | Data |
---|---|---|
05e21286 PP |
1 | #ifndef BABELTRACE_VALUES_CONST_H |
2 | #define BABELTRACE_VALUES_CONST_H | |
3 | ||
4 | /* | |
5 | * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation | |
6 | * Copyright (c) 2015-2016 Philippe Proulx <pproulx@efficios.com> | |
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 | ||
27 | #include <stdint.h> | |
28 | #include <stddef.h> | |
29 | ||
30 | /* For bt_bool */ | |
31 | #include <babeltrace/types.h> | |
32 | ||
33 | /* For enum bt_value_status, enum bt_value_type */ | |
34 | #include <babeltrace/values.h> | |
35 | ||
36 | #ifdef __cplusplus | |
37 | extern "C" { | |
38 | #endif | |
39 | ||
40 | struct bt_value; | |
41 | ||
42 | extern enum bt_value_type bt_value_get_type(const struct bt_value *object); | |
43 | ||
44 | static inline | |
45 | bt_bool bt_value_is_null(const struct bt_value *object) | |
46 | { | |
47 | return bt_value_get_type(object) == BT_VALUE_TYPE_NULL; | |
48 | } | |
49 | ||
50 | static inline | |
51 | bt_bool bt_value_is_bool(const struct bt_value *object) | |
52 | { | |
53 | return bt_value_get_type(object) == BT_VALUE_TYPE_BOOL; | |
54 | } | |
55 | ||
56 | static inline | |
57 | bt_bool bt_value_is_integer(const struct bt_value *object) | |
58 | { | |
59 | return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER; | |
60 | } | |
61 | ||
62 | static inline | |
63 | bt_bool bt_value_is_real(const struct bt_value *object) | |
64 | { | |
65 | return bt_value_get_type(object) == BT_VALUE_TYPE_REAL; | |
66 | } | |
67 | ||
68 | static inline | |
69 | bt_bool bt_value_is_string(const struct bt_value *object) | |
70 | { | |
71 | return bt_value_get_type(object) == BT_VALUE_TYPE_STRING; | |
72 | } | |
73 | ||
74 | static inline | |
75 | bt_bool bt_value_is_array(const struct bt_value *object) | |
76 | { | |
77 | return bt_value_get_type(object) == BT_VALUE_TYPE_ARRAY; | |
78 | } | |
79 | ||
80 | static inline | |
81 | bt_bool bt_value_is_map(const struct bt_value *object) | |
82 | { | |
83 | return bt_value_get_type(object) == BT_VALUE_TYPE_MAP; | |
84 | } | |
85 | ||
86 | extern enum bt_value_status bt_value_copy(struct bt_value **copy, | |
87 | const struct bt_value *object); | |
88 | ||
89 | extern bt_bool bt_value_compare(const struct bt_value *object_a, | |
90 | const struct bt_value *object_b); | |
91 | ||
92 | extern bt_bool bt_value_bool_get(const struct bt_value *bool_obj); | |
93 | ||
94 | extern int64_t bt_value_integer_get(const struct bt_value *integer_obj); | |
95 | ||
96 | extern double bt_value_real_get(const struct bt_value *real_obj); | |
97 | ||
98 | extern const char *bt_value_string_get(const struct bt_value *string_obj); | |
99 | ||
100 | extern uint64_t bt_value_array_get_size(const struct bt_value *array_obj); | |
101 | ||
102 | static inline | |
103 | bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) | |
104 | { | |
105 | return bt_value_array_get_size(array_obj) == 0; | |
106 | } | |
107 | ||
108 | extern const struct bt_value *bt_value_array_borrow_element_by_index_const( | |
109 | const struct bt_value *array_obj, uint64_t index); | |
110 | ||
111 | extern uint64_t bt_value_map_get_size(const struct bt_value *map_obj); | |
112 | ||
113 | static inline | |
114 | bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) | |
115 | { | |
116 | return bt_value_map_get_size(map_obj) == 0; | |
117 | } | |
118 | ||
119 | extern const struct bt_value *bt_value_map_borrow_entry_value_const( | |
120 | const struct bt_value *map_obj, const char *key); | |
121 | ||
122 | typedef bt_bool (* bt_value_map_foreach_entry_const_cb)(const char *key, | |
123 | const struct bt_value *object, void *data); | |
124 | ||
125 | extern enum bt_value_status bt_value_map_foreach_entry_const( | |
126 | const struct bt_value *map_obj, | |
127 | bt_value_map_foreach_entry_const_cb cb, void *data); | |
128 | ||
129 | extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj, | |
130 | const char *key); | |
131 | ||
132 | extern enum bt_value_status bt_value_map_extend( | |
133 | struct bt_value **extended_map_obj, | |
134 | const struct bt_value *base_map_obj, | |
135 | const struct bt_value *extension_map_obj); | |
136 | ||
137 | #ifdef __cplusplus | |
138 | } | |
139 | #endif | |
140 | ||
141 | #endif /* BABELTRACE_VALUES_CONST_H */ |