Build Python bindings with distutils for consistent installs
[babeltrace.git] / bindings / python / bt2 / bt2 / native_btvalues.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 /* Remove prefix from `bt_value_null` */
26 %rename(value_null) bt_value_null;
27
28 /* Type and status */
29 struct bt_value;
30
31 enum bt_value_type {
32 BT_VALUE_TYPE_UNKNOWN = -1,
33 BT_VALUE_TYPE_NULL = 0,
34 BT_VALUE_TYPE_BOOL = 1,
35 BT_VALUE_TYPE_INTEGER = 2,
36 BT_VALUE_TYPE_FLOAT = 3,
37 BT_VALUE_TYPE_STRING = 4,
38 BT_VALUE_TYPE_ARRAY = 5,
39 BT_VALUE_TYPE_MAP = 6,
40 };
41
42 enum bt_value_type bt_value_get_type(const struct bt_value *object);
43
44 enum bt_value_status {
45 BT_VALUE_STATUS_FROZEN = -4,
46 BT_VALUE_STATUS_CANCELLED = -3,
47 BT_VALUE_STATUS_INVAL = -22,
48 BT_VALUE_STATUS_ERROR = -1,
49 BT_VALUE_STATUS_OK = 0,
50 };
51
52 /* Null value object singleton */
53 struct bt_value * const bt_value_null;
54
55 /* Common functions */
56 enum bt_value_status bt_value_freeze(struct bt_value *object);
57 int bt_value_is_frozen(const struct bt_value *object);
58 struct bt_value *bt_value_copy(const struct bt_value *object);
59 int bt_value_compare(const struct bt_value *object_a,
60 const struct bt_value *object_b);
61
62 /* Boolean value object functions */
63 struct bt_value *bt_value_bool_create(void);
64 struct bt_value *bt_value_bool_create_init(int val);
65 enum bt_value_status bt_value_bool_get(
66 const struct bt_value *bool_obj, int *OUTPUT);
67 enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj,
68 int val);
69
70 /* Integer value object functions */
71 struct bt_value *bt_value_integer_create(void);
72 struct bt_value *bt_value_integer_create_init(int64_t val);
73 enum bt_value_status bt_value_integer_get(
74 const struct bt_value *integer_obj, int64_t *OUTPUT);
75 enum bt_value_status bt_value_integer_set(
76 struct bt_value *integer_obj, int64_t val);
77
78 /* Floating point number value object functions */
79 struct bt_value *bt_value_float_create(void);
80 struct bt_value *bt_value_float_create_init(double val);
81 enum bt_value_status bt_value_float_get(
82 const struct bt_value *float_obj, double *OUTPUT);
83 enum bt_value_status bt_value_float_set(
84 struct bt_value *float_obj, double val);
85
86 /* String value object functions */
87 struct bt_value *bt_value_string_create(void);
88 struct bt_value *bt_value_string_create_init(const char *val);
89 enum bt_value_status bt_value_string_set(struct bt_value *string_obj,
90 const char *val);
91 enum bt_value_status bt_value_string_get(
92 const struct bt_value *string_obj, const char **BTOUTSTR);
93
94 /* Array value object functions */
95 struct bt_value *bt_value_array_create(void);
96 int bt_value_array_size(const struct bt_value *array_obj);
97 struct bt_value *bt_value_array_get(const struct bt_value *array_obj,
98 size_t index);
99 enum bt_value_status bt_value_array_append(struct bt_value *array_obj,
100 struct bt_value *element_obj);
101 enum bt_value_status bt_value_array_set(struct bt_value *array_obj,
102 size_t index, struct bt_value *element_obj);
103
104 /* Map value object functions */
105 struct bt_value *bt_value_map_create(void);
106 int bt_value_map_size(const struct bt_value *map_obj);
107 struct bt_value *bt_value_map_get(const struct bt_value *map_obj,
108 const char *key);
109 int bt_value_map_has_key(const struct bt_value *map_obj,
110 const char *key);
111 enum bt_value_status bt_value_map_insert(
112 struct bt_value *map_obj, const char *key,
113 struct bt_value *element_obj);
114 struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj,
115 struct bt_value *extension_map_obj);
116
117 %{
118 struct bt_value_map_get_keys_private_data {
119 struct bt_value *keys;
120 };
121
122 static int bt_value_map_get_keys_private_cb(const char *key,
123 struct bt_value *object, void *data)
124 {
125 enum bt_value_status status;
126 struct bt_value_map_get_keys_private_data *priv_data = data;
127
128 status = bt_value_array_append_string(priv_data->keys, key);
129 if (status != BT_VALUE_STATUS_OK) {
130 return BT_FALSE;
131 }
132
133 return BT_TRUE;
134 }
135
136 static struct bt_value *bt_value_map_get_keys_private(
137 const struct bt_value *map_obj)
138 {
139 enum bt_value_status status;
140 struct bt_value_map_get_keys_private_data data;
141
142 data.keys = bt_value_array_create();
143 if (!data.keys) {
144 return NULL;
145 }
146
147 status = bt_value_map_foreach(map_obj, bt_value_map_get_keys_private_cb,
148 &data);
149 if (status != BT_VALUE_STATUS_OK) {
150 goto error;
151 }
152
153 goto end;
154
155 error:
156 if (data.keys) {
157 BT_PUT(data.keys);
158 }
159
160 end:
161 return data.keys;
162 }
163 %}
164
165 struct bt_value *bt_value_map_get_keys_private(const struct bt_value *map_obj);
This page took 0.033001 seconds and 4 git commands to generate.