Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/expr/Parameters.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: 19 февр. 2020 г.
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_PARAMETERS_H_
23 #define LSP_PLUG_IN_EXPR_PARAMETERS_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/lltl/parray.h>
27 #include <lsp-plug.in/expr/Resolver.h>
28
29 namespace lsp
30 {
31 namespace expr
32 {
33 /**
34 * Implements list of optionally named parameters which then can be used for string formatting.
35 * Parameters may have duplicate names. From set of named parameters with the same name the parameter
36 * with the least index will be visible by the name.
37 */
38 class Parameters: public Resolver
39 {
40 protected:
41 typedef struct param_t
42 {
43 value_t value;
44 ssize_t len;
45 lsp_wchar_t name[];
46 } param_t;
47
48 protected:
49 lltl::parray<param_t> vParams;
50
51 protected:
52 param_t *lookup_by_name(const LSPString *name);
53 param_t *lookup_by_name(const LSPString *name, size_t *idx);
54 static param_t *allocate();
55 static param_t *allocate(const lsp_wchar_t *name, ssize_t len);
56 static param_t *clone(const param_t *src);
57 static void destroy(param_t *p);
58 inline static param_t *allocate(const LSPString *name) { return allocate(name->characters(), name->length()); };
59
60 static void destroy_params(lltl::parray<param_t> &params);
61
62 status_t drop_value(size_t index, value_type_t type, param_t **out);
63 status_t drop_value(const char *name, value_type_t type, param_t **out);
64 status_t drop_value(const LSPString *name, value_type_t type, param_t **out);
65 status_t add_move(const LSPString *name, value_t *value);
66 status_t add_move(const char *name, value_t *value);
67 status_t add_move(value_t *value);
68
69 protected:
70 /**
71 * This callback is called when the collection becomes modified.
72 * Method can be overridden to trigger different events like parent
73 * collection update.
74 */
75 virtual void modified();
76
77 public:
78 explicit Parameters();
79 Parameters(const Parameters &) = delete;
80 Parameters(Parameters &&) = delete;
81 virtual ~Parameters();
82
83 Parameters & operator = (const Parameters &) = delete;
84 Parameters & operator = (Parameters &&) = delete;
85
86 public:
87 virtual status_t resolve(value_t *value, const char *name, size_t num_indexes = 0, const ssize_t *indexes = NULL);
88
89 virtual status_t resolve(value_t *value, const LSPString *name, size_t num_indexes = 0, const ssize_t *indexes = NULL);
90
91 public:
92 inline size_t size() const { return vParams.size(); }
93 void swap(Parameters *src);
94 void clear();
95 Parameters *clone() const;
96
97 // Adding: add parameter to the end of list.
98 status_t add_int(const char *name, ssize_t value);
99 status_t add_float(const char *name, double value);
100 status_t add_bool(const char *name, bool value);
101 status_t add_cstring(const char *name, const char *value);
102 status_t add_string(const char *name, const LSPString *value);
103 status_t add_null(const char *name);
104 status_t add_undef(const char *name);
105 status_t add(const char *name, const value_t *value);
106
107 status_t add_int(const LSPString *name, ssize_t value);
108 status_t add_float(const LSPString *name, double value);
109 status_t add_bool(const LSPString *name, bool value);
110 status_t add_cstring(const LSPString *name, const char *value);
111 status_t add_string(const LSPString *name, const LSPString *value);
112 status_t add_null(const LSPString *name);
113 status_t add_undef(const LSPString *name);
114 status_t add(const LSPString *name, const value_t *value);
115
116 status_t add_int(ssize_t value);
117 status_t add_float(double value);
118 status_t add_bool(bool value);
119 status_t add_cstring(const char *value);
120 status_t add_string(const LSPString *value);
121 status_t add_null();
122 status_t add_undef();
123 status_t add(const value_t *value);
124
125 status_t add(const Parameters *p, ssize_t first = 0, ssize_t last = -1);
126
127 // Inserting
128 status_t insert_int(size_t index, const char *name, ssize_t value);
129 status_t insert_float(size_t index, const char *name, double value);
130 status_t insert_bool(size_t index, const char *name, bool value);
131 status_t insert_string(size_t index, const char *name, const char *value);
132 status_t insert_string(size_t index, const char *name, const LSPString *value);
133 status_t insert_null(size_t index, const char *name);
134 status_t insert_undef(size_t index, const char *name);
135 status_t insert(size_t index, const char *name, const value_t *value);
136
137 status_t insert_int(size_t index, const LSPString *name, ssize_t value);
138 status_t insert_float(size_t index, const LSPString *name, double value);
139 status_t insert_bool(size_t index, const LSPString *name, bool value);
140 status_t insert_string(size_t index, const LSPString *name, const char *value);
141 status_t insert_string(size_t index, const LSPString *name, const LSPString *value);
142 status_t insert_null(size_t index, const LSPString *name);
143 status_t insert_undef(size_t index, const LSPString *name);
144 status_t insert(size_t index, const LSPString *name, const value_t *value);
145
146 status_t insert_int(size_t index, ssize_t value);
147 status_t insert_float(size_t index, double value);
148 status_t insert_bool(size_t index, bool value);
149 status_t insert_cstring(size_t index, const char *value);
150 status_t insert_string(size_t index, const LSPString *value);
151 status_t insert_null(size_t index);
152 status_t insert_undef(size_t index);
153 status_t insert(size_t index, const value_t *value);
154
155 status_t insert(size_t index, const Parameters *p, ssize_t first = 0, ssize_t last = -1);
156
157 // Getting
158 status_t get_int(size_t index, ssize_t *value) const;
159 status_t get_float(size_t index, double *value) const;
160 status_t get_bool(size_t index, bool *value) const;
161 status_t get_string(size_t index, LSPString *value) const;
162 status_t get_null(size_t index) const;
163 status_t get_undef(size_t index) const;
164 status_t get(size_t index, value_t *value) const;
165
166 status_t get_int(const char *name, ssize_t *value) const;
167 status_t get_float(const char *name, double *value) const;
168 status_t get_bool(const char *name, bool *value) const;
169 status_t get_string(const char *name, LSPString *value) const;
170 status_t get_null(const char *name) const;
171 status_t get_undef(const char *name) const;
172 status_t get(const char *name, value_t *value) const;
173
174 status_t get_int(const LSPString *name, ssize_t *value) const;
175 status_t get_float(const LSPString *name, double *value) const;
176 status_t get_bool(const LSPString *name, bool *value) const;
177 status_t get_string(const LSPString *name, LSPString *value) const;
178 status_t get_null(const LSPString *name) const;
179 status_t get_undef(const LSPString *name) const;
180 status_t get(const LSPString *name, value_t *value) const;
181
182 // Getting with cast
183 status_t as_int(size_t index, ssize_t *value) const;
184 status_t as_float(size_t index, double *value) const;
185 status_t as_bool(size_t index, bool *value) const;
186 status_t as_string(size_t index, LSPString *value) const;
187 status_t as_null(size_t index) const;
188 status_t as_undef(size_t index) const;
189 status_t as_value(size_t index, value_t *value, value_type_t type) const;
190
191 status_t as_int(const char *name, ssize_t *value) const;
192 status_t as_float(const char *name, double *value) const;
193 status_t as_bool(const char *name, bool *value) const;
194 status_t as_string(const char *name, LSPString *value) const;
195 status_t as_null(const char *name) const;
196 status_t as_undef(const char *name) const;
197 status_t as_value(const char *name, value_t *value, value_type_t type) const;
198
199 status_t as_int(const LSPString *name, ssize_t *value) const;
200 status_t as_float(const LSPString *name, double *value) const;
201 status_t as_bool(const LSPString *name, bool *value) const;
202 status_t as_string(const LSPString *name, LSPString *value) const;
203 status_t as_null(const LSPString *name) const;
204 status_t as_undef(const LSPString *name) const;
205 status_t as_value(const LSPString *name, value_t *value, value_type_t type) const;
206
207 // Setting
208 status_t set_int(const char *name, ssize_t value);
209 status_t set_float(const char *name, double value);
210 status_t set_bool(const char *name, bool value);
211 status_t set_cstring(const char *name, const char *value);
212 status_t set_string(const char *name, const LSPString *value);
213 status_t set_null(const char *name);
214 status_t set_undef(const char *name);
215 status_t set(const char *name, const value_t *value);
216
217 status_t set_int(const LSPString *name, ssize_t value);
218 status_t set_float(const LSPString *name, double value);
219 status_t set_bool(const LSPString *name, bool value);
220 status_t set_cstring(const LSPString *name, const char *value);
221 status_t set_string(const LSPString *name, const LSPString *value);
222 status_t set_null(const LSPString *name);
223 status_t set_undef(const LSPString *name);
224 status_t set(const LSPString *name, const value_t *value);
225
226 status_t set_int(size_t index, ssize_t value);
227 status_t set_float(size_t index, double value);
228 status_t set_bool(size_t index, bool value);
229 status_t set_cstring(size_t index, const char *value);
230 status_t set_string(size_t index, const LSPString *value);
231 status_t set_null(size_t index);
232 status_t set_undef(size_t index);
233 status_t set(size_t index, const value_t *value);
234
235 status_t set(const Parameters *p, ssize_t first = 0, ssize_t last = -1);
236
237 // Removing
238 status_t remove_int(size_t index, ssize_t *value = NULL);
239 status_t remove_float(size_t index, double *value = NULL);
240 status_t remove_bool(size_t index, bool *value = NULL);
241 status_t remove_string(size_t index, LSPString *value = NULL);
242 status_t remove_null(size_t index);
243 status_t remove_undef(size_t index);
244 status_t remove(size_t index, value_t *value = NULL);
245 status_t remove_value(size_t index, value_type_t type, value_t *value);
246
247 status_t remove_int(const char *name, ssize_t *value = NULL);
248 status_t remove_float(const char *name, double *value = NULL);
249 status_t remove_bool(const char *name, bool *value = NULL);
250 status_t remove_string(const char *name, LSPString *value = NULL);
251 status_t remove_null(const char *name = NULL);
252 status_t remove_undef(const char *name = NULL);
253 status_t remove(const char *name, value_t *value = NULL);
254 status_t remove_value(const char *name, value_type_t type, value_t *value = NULL);
255
256 status_t remove_int(const LSPString *name, ssize_t *value = NULL);
257 status_t remove_float(const LSPString *name, double *value = NULL);
258 status_t remove_bool(const LSPString *name, bool *value = NULL);
259 status_t remove_string(const LSPString *name, LSPString *value = NULL);
260 status_t remove_null(const LSPString *name = NULL);
261 status_t remove_undef(const LSPString *name = NULL);
262 status_t remove(const LSPString *name, value_t *value = NULL);
263 status_t remove_value(const LSPString *name, value_type_t type, value_t *value = NULL);
264
265 status_t remove(ssize_t first, ssize_t last);
266
267 // Obtaining type of parameter (negative result on error)
268 ssize_t get_type(size_t index) const;
269 ssize_t get_type(const char *name) const;
270 ssize_t get_type(const LSPString *name) const;
271
272 // Obtaining name of parameter
273 status_t get_name(size_t index, LSPString *name) const;
274 ssize_t get_index(const LSPString *name) const;
275 ssize_t get_index(const char *name) const;
276
277 // Checking for contents
278 inline bool contains(size_t index) const { return index < vParams.size(); }
279 inline bool contains(const char *name) const { return get_index(name) >= 0; }
280 inline bool contains(const LSPString *name) const { return get_index(name) >= 0; }
281 };
282
283 } /* namespace expr */
284 } /* namespace lsp */
285
286 #endif /* LSP_PLUG_IN_EXPR_PARAMETERS_H_ */