Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/expr/types.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 16 сент. 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_EXPR_TYPES_H_
23 #define LSP_PLUG_IN_EXPR_TYPES_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/common/types.h>
27 #include <lsp-plug.in/common/status.h>
28 #include <lsp-plug.in/runtime/LSPString.h>
29
30 namespace lsp
31 {
32 namespace expr
33 {
34 enum value_type_t
35 {
36 VT_UNDEF, // Value is undefined
37 VT_NULL, // Value is defined but is NULL
38
39 VT_INT, // Value is of integer type
40 VT_FLOAT, // Value is of float type
41 VT_STRING, // Value is of string type
42 VT_BOOL // Value is of boolean type
43 };
44
45 typedef struct value_t
46 {
47 value_type_t type;
48 union
49 {
50 ssize_t v_int;
51 double v_float;
52 bool v_bool;
53 LSPString *v_str;
54 };
55 } value_t;
56
57 /**
58 * User-defined function
59 *
60 * @param context additional user context passed to function
61 * @param result destination value to store result, should be initialized
62 * @param num_args number of arguments passed to function
63 * @param args list of arguments passed to function (may be NULL if num_args is 0)
64 * @return status of operation
65 */
66 typedef status_t (*function_t)(void *context, value_t *result, size_t num_args, const value_t *args);
67
68 /**
69 * Initialize value with VT_UNDEF type
70 * @param dst destination value
71 */
72 void init_value(value_t *dst);
73
74 /**
75 * Init value as NULL
76 * @param dst target to set
77 */
78 void init_value_null(value_t *dst);
79
80 /**
81 * Init value as UNDEF
82 * @param dst target to set
83 */
84 void init_value_undef(value_t *dst);
85
86 /**
87 * Init value as integer
88 * @param dst target to set
89 * @param value integer value to set
90 */
91 void init_value_int(value_t *dst, ssize_t value);
92
93 /**
94 * Init value as floating point
95 * @param dst target to set
96 * @param value floating-point value to set
97 */
98 void init_value_float(value_t *dst, double value);
99
100 /**
101 * Init value as boolean
102 * @param dst target to set
103 * @param value boolean value to set
104 */
105 void init_value_bool(value_t *dst, bool value);
106
107 /**
108 * Init value as string
109 * @param dst target to set
110 * @param value string value to set
111 */
112 status_t init_value_string(value_t *dst, const LSPString *value);
113
114 /**
115 * Init value as string
116 * @param dst target to set
117 * @param value UTF-8 string to set
118 */
119 status_t init_value_string(value_t *dst, const char *value);
120
121 /**
122 * Init value as string
123 * @param dst target to set
124 * @param value native string to set
125 * @param charset native charset name
126 */
127 status_t init_value_string(value_t *dst, const char *value, const char *charset);
128
129 /**
130 * Initialize value with another value by copying contents
131 * @param dst destination value
132 * @param src source value to take data from
133 * @return status of operation
134 */
135 status_t init_value(value_t *dst, const value_t *src);
136
137 /**
138 * Initialize value with move. Moves contents of source value to destination value
139 * and resets source value to undef
140 * @param dst destination value to perform copy
141 * @param src source value to take data from
142 */
143 void init_value_move(value_t *dst, value_t *src);
144
145 /**
146 * Copy value. Frees previously used value if it was set
147 * @param dst destination value to perform copy
148 * @param src source value to take data from
149 * @return status of operation
150 */
151 status_t copy_value(value_t *dst, const value_t *src);
152
153 /**
154 * Move value. Moves contents of source value to destination value
155 * and resets source value to undef
156 * @param dst destination value to perform copy
157 * @param src source value to take data from
158 */
159 void move_value(value_t *dst, value_t *src);
160
161 /**
162 * Swap value. Swaps contents of source value and destination value
163 * @param dst destination value to perform copy
164 * @param src source value to take data from
165 */
166 void swap_value(value_t *dst, value_t *src);
167
168 /**
169 * Set value to NULL
170 * @param dst target to set
171 */
172 void set_value_null(value_t *dst);
173
174 /**
175 * Set value to UNDEF
176 * @param dst target to set
177 */
178 void set_value_undef(value_t *dst);
179
180 /**
181 * Set value to integer
182 * @param dst target to set
183 * @param value integer value to set
184 */
185 void set_value_int(value_t *dst, ssize_t value);
186
187 /**
188 * Set value to floating point
189 * @param dst target to set
190 * @param value floating-point value to set
191 */
192 void set_value_float(value_t *dst, double value);
193
194 /**
195 * Set value to boolean
196 * @param dst target to set
197 * @param value boolean value to set
198 */
199 void set_value_bool(value_t *dst, bool value);
200
201 /**
202 * Set value to string
203 * @param dst target to set
204 * @param value string value to set
205 */
206 status_t set_value_string(value_t *dst, const LSPString *value);
207
208 /**
209 * Set value to string
210 * @param dst target to set
211 * @param value UTF-8 string to set
212 */
213 status_t set_value_string(value_t *dst, const char *value);
214
215 /**
216 * Set value to string
217 * @param dst target to set
218 * @param value native string to set
219 * @param charset character set to use
220 */
221 status_t set_value_string(value_t *dst, const char *value, const char *charset);
222
223
224 /**
225 * Destroy value and all internal contents associated with it
226 * The value remains valid and available for further operations but set to UNDEF
227 * @param value value to destroy
228 */
229 void destroy_value(value_t *value);
230
231 /**
232 * Ensure that value is integer and read it
233 * @param dst pointer to store value
234 * @param v value to read
235 * @return status STATUS_BAD_TYPE error code on type mismatch
236 */
237 status_t fetch_int(ssize_t *dst, const value_t *v);
238
239 /**
240 * Ensure that value is floating-point and read it
241 * @param dst pointer to store value
242 * @param v value to read
243 * @return status STATUS_BAD_TYPE error code on type mismatch
244 */
245 status_t fetch_float(float *dst, const value_t *v);
246
247 /**
248 * Ensure that value is floating-point and read it
249 * @param dst pointer to store value
250 * @param v value to read
251 * @return status STATUS_BAD_TYPE error code on type mismatch
252 */
253 status_t fetch_float(double *dst, const value_t *v);
254
255 /**
256 * Ensure that value is boolean and read it
257 * @param dst pointer to store value
258 * @param v value to read
259 * @return status STATUS_BAD_TYPE error code on type mismatch
260 */
261 status_t fetch_bool(bool *dst, const value_t *v);
262
263 /**
264 * Ensure that value is string and read it
265 * @param dst pointer to store value
266 * @param v value to read
267 * @return status STATUS_BAD_TYPE error code on type mismatch
268 */
269 status_t fetch_string(LSPString *dst, const value_t *v);
270
271 /**
272 * Try to cast value to int and fetch it
273 * @param dst pointer to store value
274 * @param v value to read
275 * @return status of operation
276 */
277 status_t fetch_as_int(ssize_t *dst, const value_t *v);
278
279 /**
280 * Try to cast value to floating-pont value and fetch it
281 * @param dst pointer to store value
282 * @param v value to read
283 * @return status of operation
284 */
285 status_t fetch_as_float(float *dst, const value_t *v);
286
287 /**
288 * Try to cast value to floating-pont value and fetch it
289 * @param dst pointer to store value
290 * @param v value to read
291 * @return status of operation
292 */
293 status_t fetch_as_float(double *dst, const value_t *v);
294
295 /**
296 * Try to cast value to boolean value and fetch it
297 * @param dst pointer to store value
298 * @param v value to read
299 * @return status of operation
300 */
301 status_t fetch_as_bool(bool *dst, const value_t *v);
302
303 /**
304 * Try to cast value to string and fetch it
305 * @param dst pointer to store value
306 * @param v value to read
307 * @return status of operation
308 */
309 status_t fetch_as_string(LSPString *dst, const value_t *v);
310
311 status_t cast_value(value_t *v, value_type_t type);
312 status_t cast_value(value_t *dst, const value_t *v, value_type_t type);
313
314 status_t cast_int(value_t *v);
315 status_t cast_float(value_t *v);
316 status_t cast_bool(value_t *v);
317 status_t cast_string(value_t *v);
318 status_t cast_string_ext(value_t *v);
319 status_t cast_numeric(value_t *v);
320 status_t cast_non_string(value_t *v);
321
322 status_t cast_int(value_t *dst, const value_t *v);
323 status_t cast_float(value_t *dst, const value_t *v);
324 status_t cast_bool(value_t *dst, const value_t *v);
325 status_t cast_string(value_t *dst, const value_t *v);
326 status_t cast_string_ext(value_t *dst, const value_t *v);
327 status_t cast_numeric(value_t *dst, const value_t *v);
328 status_t cast_non_string(value_t *dst, const value_t *v);
329
330 } /* namespace expr */
331 } /* namespace lsp */
332
333 #endif /* LSP_PLUG_IN_EXPR_TYPES_H_ */