lib: make values API const-correct
[babeltrace.git] / include / babeltrace / values-const.h
CommitLineData
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
37extern "C" {
38#endif
39
40struct bt_value;
41
42extern enum bt_value_type bt_value_get_type(const struct bt_value *object);
43
44static inline
45bt_bool bt_value_is_null(const struct bt_value *object)
46{
47 return bt_value_get_type(object) == BT_VALUE_TYPE_NULL;
48}
49
50static inline
51bt_bool bt_value_is_bool(const struct bt_value *object)
52{
53 return bt_value_get_type(object) == BT_VALUE_TYPE_BOOL;
54}
55
56static inline
57bt_bool bt_value_is_integer(const struct bt_value *object)
58{
59 return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER;
60}
61
62static inline
63bt_bool bt_value_is_real(const struct bt_value *object)
64{
65 return bt_value_get_type(object) == BT_VALUE_TYPE_REAL;
66}
67
68static inline
69bt_bool bt_value_is_string(const struct bt_value *object)
70{
71 return bt_value_get_type(object) == BT_VALUE_TYPE_STRING;
72}
73
74static inline
75bt_bool bt_value_is_array(const struct bt_value *object)
76{
77 return bt_value_get_type(object) == BT_VALUE_TYPE_ARRAY;
78}
79
80static inline
81bt_bool bt_value_is_map(const struct bt_value *object)
82{
83 return bt_value_get_type(object) == BT_VALUE_TYPE_MAP;
84}
85
86extern enum bt_value_status bt_value_copy(struct bt_value **copy,
87 const struct bt_value *object);
88
89extern bt_bool bt_value_compare(const struct bt_value *object_a,
90 const struct bt_value *object_b);
91
92extern bt_bool bt_value_bool_get(const struct bt_value *bool_obj);
93
94extern int64_t bt_value_integer_get(const struct bt_value *integer_obj);
95
96extern double bt_value_real_get(const struct bt_value *real_obj);
97
98extern const char *bt_value_string_get(const struct bt_value *string_obj);
99
100extern uint64_t bt_value_array_get_size(const struct bt_value *array_obj);
101
102static inline
103bt_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
108extern const struct bt_value *bt_value_array_borrow_element_by_index_const(
109 const struct bt_value *array_obj, uint64_t index);
110
111extern uint64_t bt_value_map_get_size(const struct bt_value *map_obj);
112
113static inline
114bt_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
119extern const struct bt_value *bt_value_map_borrow_entry_value_const(
120 const struct bt_value *map_obj, const char *key);
121
122typedef bt_bool (* bt_value_map_foreach_entry_const_cb)(const char *key,
123 const struct bt_value *object, void *data);
124
125extern 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
129extern bt_bool bt_value_map_has_entry(const struct bt_value *map_obj,
130 const char *key);
131
132extern 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 */
This page took 0.027284 seconds and 4 git commands to generate.