Debian Codegraph @

modules/lsp-runtime-lib/src/main/expr/Parameters.cpp

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 #include <lsp-plug.in/expr/Parameters.h>
23 #include <lsp-plug.in/common/alloc.h>
24
25 namespace lsp
26 {
27 namespace expr
28 {
29
30 Parameters::Parameters()
31 {
32 }
33
34 Parameters::~Parameters()
35 {
36 destroy_params(vParams);
37 }
38
39 void Parameters::modified()
40 {
41 }
42
43 Parameters *Parameters::clone() const
44 {
45 Parameters *res = new Parameters();
46 if (res == NULL)
47 return NULL;
48 status_t status = res->set(this);
49 if (status == STATUS_OK)
50 return res;
51 delete res;
52 return NULL;
53 }
54
55 void Parameters::swap(Parameters *src)
56 {
57 if (src == this)
58 return;
59
60 vParams.swap(&src->vParams);
61 src->modified();
62 this->modified();
63 }
64
65 void Parameters::clear()
66 {
67 destroy_params(vParams);
68 modified();
69 }
70
71 status_t Parameters::resolve(value_t *value, const char *name, size_t num_indexes, const ssize_t *indexes)
72 {
73 if (name == NULL)
74 return STATUS_BAD_ARGUMENTS;
75
76 LSPString key;
77 if (!key.set_utf8(name))
78 return STATUS_NO_MEM;
79
80 return resolve(value, &key, num_indexes, indexes);
81 }
82
83 Parameters::param_t *Parameters::lookup_by_name(const LSPString *name)
84 {
85 for (size_t i=0, n=vParams.size(); i<n; ++i)
86 {
87 param_t *p = vParams.uget(i);
88 if ((p != NULL) && (p->len >= 0) && (name->equals(p->name, p->len)))
89 return p;
90 }
91 return NULL;
92 }
93
94 ssize_t Parameters::get_index(const LSPString *name) const
95 {
96 for (size_t i=0, n=vParams.size(); i<n; ++i)
97 {
98 const param_t *p = vParams.uget(i);
99 if ((p != NULL) && (p->len >= 0) && (name->equals(p->name, p->len)))
100 return i;
101 }
102 return -STATUS_NOT_FOUND;
103 }
104
105 ssize_t Parameters::get_index(const char *name) const
106 {
107 LSPString tmp;
108 if (!tmp.set_utf8(name))
109 return STATUS_NO_MEM;
110 return get_index(&tmp);
111 }
112
113 status_t Parameters::get_name(size_t index, LSPString *name) const
114 {
115 const param_t *p = vParams.get(index);
116 if (p == NULL)
117 return STATUS_INVALID_VALUE;
118 else if (p->len < 0)
119 return STATUS_NULL;
120
121 return (name->set(p->name, p->len)) ? STATUS_OK : STATUS_NO_MEM;
122 }
123
124 ssize_t Parameters::get_type(size_t index) const
125 {
126 const param_t *p = vParams.get(index);
127 return (p != NULL) ? p->value.type : -STATUS_INVALID_VALUE;
128 }
129
130 ssize_t Parameters::get_type(const char *name) const
131 {
132 LSPString tmp;
133 if (!tmp.set_utf8(name))
134 return STATUS_NO_MEM;
135 return get_type(&tmp);
136 }
137
138 ssize_t Parameters::get_type(const LSPString *name) const
139 {
140 param_t *p = const_cast<Parameters *>(this)->lookup_by_name(name);
141 return (p != NULL) ? p->value.type : -STATUS_NOT_FOUND;
142 }
143
144 Parameters::param_t *Parameters::lookup_by_name(const LSPString *name, size_t *idx)
145 {
146 for (size_t i=0, n=vParams.size(); i<n; ++i)
147 {
148 param_t *p = vParams.uget(i);
149 if ((p != NULL) && (p->len >= 0) && (name->equals(p->name, p->len)))
150 {
151 *idx = i;
152 return p;
153 }
154 }
155 return NULL;
156 }
157
158 status_t Parameters::resolve(value_t *value, const LSPString *name, size_t num_indexes, const ssize_t *indexes)
159 {
160 // Need to form indexes?
161 LSPString tmp;
162 const LSPString *search;
163
164 if (num_indexes > 0)
165 {
166 if (!tmp.set(name))
167 return STATUS_NO_MEM;
168 for (size_t i=0; i<num_indexes; ++i)
169 {
170 if (!tmp.fmt_append_ascii("_%ld", long(indexes[i])))
171 return STATUS_NO_MEM;
172 }
173 search = &tmp;
174 }
175 else
176 search = name;
177
178 // Lookup the list
179 param_t *p = lookup_by_name(search);
180 if (p == NULL)
181 return STATUS_NOT_FOUND;
182
183 if (value != NULL)
184 return copy_value(value, &p->value);
185
186 return STATUS_OK;
187 }
188
189 void Parameters::destroy_params(lltl::parray<param_t> &params)
190 {
191 for (size_t i=0; i<params.size(); ++i)
192 destroy(params.uget(i));
193 params.flush();
194 }
195
196 void Parameters::destroy(param_t *p)
197 {
198 if (p == NULL)
199 return;
200 destroy_value(&p->value);
201 ::free(p);
202 }
203
204 Parameters::param_t *Parameters::allocate()
205 {
206 param_t *p = reinterpret_cast<param_t *>(::malloc(align_size(sizeof(param_t), DEFAULT_ALIGN)));
207 if (p != NULL)
208 {
209 init_value(&p->value);
210 p->len = -1;
211 }
212 return p;
213 }
214
215 Parameters::param_t *Parameters::allocate(const lsp_wchar_t *name, ssize_t len)
216 {
217 size_t to_alloc = sizeof(param_t) + len * sizeof(lsp_wchar_t);
218
219 param_t *p = reinterpret_cast<param_t *>(::malloc(align_size(to_alloc, DEFAULT_ALIGN)));
220 if (p != NULL)
221 {
222 init_value(&p->value);
223 p->len = len;
224 ::memcpy(p->name, name, len * sizeof(lsp_wchar_t));
225 }
226 return p;
227 }
228
229 Parameters::param_t *Parameters::clone(const param_t *src)
230 {
231 size_t len = (src->len < 0) ? 0 : src->len;
232 size_t to_alloc = sizeof(param_t) + len * sizeof(lsp_wchar_t);
233
234 param_t *p = reinterpret_cast<param_t *>(::malloc(align_size(to_alloc, DEFAULT_ALIGN)));
235 if (p != NULL)
236 {
237 init_value(&p->value, &src->value);
238 p->len = src->len;
239 ::memcpy(p->name, src->name, len * sizeof(lsp_wchar_t));
240 }
241
242 return p;
243 }
244
245 status_t Parameters::set(const Parameters *p, ssize_t first, ssize_t last)
246 {
247 const lltl::parray<param_t> &vp = p->vParams;
248
249 // Check ranges
250 if (first < 0)
251 return STATUS_UNDERFLOW;
252 if (last < 0)
253 {
254 last = vp.size();
255 if (first > last)
256 return STATUS_OVERFLOW;
257 }
258 else
259 {
260 if (last > ssize_t(vp.size()))
261 return STATUS_OVERFLOW;
262 if (first > last)
263 return STATUS_INVALID_VALUE;
264 }
265
266 // Perform a copy
267 lltl::parray<param_t> slice;
268 for ( ; first < last; ++first)
269 {
270 param_t *p = clone(vp.uget(first));
271 if ((p == NULL) || (!slice.add(p)))
272 {
273 destroy_params(slice);
274 return STATUS_NO_MEM;
275 }
276 }
277
278 // Swap parameters and destroy old data
279 vParams.swap(&slice);
280 destroy_params(slice);
281 modified();
282 return STATUS_OK;
283 }
284
285 status_t Parameters::insert(size_t index, const Parameters *p, ssize_t first, ssize_t last)
286 {
287 if ((first < 0) || (first > last) || (last > ssize_t(p->vParams.size())))
288 return STATUS_INVALID_VALUE;
289 if (index > vParams.size())
290 return STATUS_OVERFLOW;
291
292 // Perform a copy
293 lltl::parray<param_t> slice;
294 param_t **vp = vParams.array();
295 if (!slice.add_n(index, &vp[0]))
296 return STATUS_NO_MEM;
297
298 // Clone parameters and append to the current tail
299 for (ssize_t i=first; i < last; ++i)
300 {
301 param_t *cp = clone(p->vParams.uget(i));
302 if ((cp == NULL) || (!slice.add(cp)))
303 {
304 // Destroy cloned parameters
305 size_t count = slice.size() - index;
306 for (size_t j=0; j<count; ++j)
307 destroy(slice.uget(j));
308 return STATUS_NO_MEM;
309 }
310 }
311
312 // Append parameters
313 if (!slice.add_n(vParams.size() - index, &vp[index]))
314 {
315 // Destroy cloned parameters
316 size_t count = slice.size() - index;
317 for (size_t j=0; j<count; ++j)
318 destroy(slice.uget(j));
319 return STATUS_NO_MEM;
320 }
321
322 // Clean temporary parameters, swap parameters and destroy old data
323 vParams.swap(&slice);
324 modified();
325 return STATUS_OK;
326 }
327
328 status_t Parameters::add(const Parameters *p, ssize_t first, ssize_t last)
329 {
330 if ((first < 0) || (first > last) || (last > ssize_t(p->vParams.size())))
331 return STATUS_INVALID_VALUE;
332
333 // Clone parameters and append to the tail
334 for (ssize_t i=first; i < last; ++i)
335 {
336 param_t *cp = clone(p->vParams.uget(i));
337 if ((cp == NULL) || (!vParams.add(cp)))
338 {
339 // Destroy cloned parameters
340 size_t count = vParams.size() - first;
341 for (size_t j=0; j<count; ++j)
342 destroy(vParams.uget(j));
343 vParams.remove_n(first, count);
344 return STATUS_NO_MEM;
345 }
346 }
347
348 modified();
349 return STATUS_OK;
350 }
351
352 status_t Parameters::add(const LSPString *name, const value_t *value)
353 {
354 if (name == NULL)
355 return add(value);
356
357 param_t *p = allocate(name);
358 if (p == NULL)
359 return STATUS_NO_MEM;
360
361 status_t res = init_value(&p->value, value);
362 if (res == STATUS_OK)
363 {
364 if (vParams.add(p))
365 {
366 modified();
367 return STATUS_OK;
368 }
369 res = STATUS_NO_MEM;
370 }
371
372 destroy(p);
373 return res;
374 }
375
376 status_t Parameters::add_move(const LSPString *name, value_t *value)
377 {
378 if (name == NULL)
379 return add(value);
380
381 param_t *p = allocate(name);
382 if (p == NULL)
383 return STATUS_NO_MEM;
384
385 init_value_move(&p->value, value);
386 if (vParams.add(p))
387 {
388 modified();
389 return STATUS_OK;
390 }
391
392 destroy(p);
393 return STATUS_NO_MEM;
394 }
395
396 status_t Parameters::add(const char *name, const value_t *value)
397 {
398 if (name == NULL)
399 return add(value);
400
401 LSPString tmp;
402 if (!tmp.set_utf8(name))
403 return STATUS_NO_MEM;
404 return add(&tmp, value);
405 }
406
407 status_t Parameters::add_move(const char *name, value_t *value)
408 {
409 if (name == NULL)
410 return add(value);
411
412 LSPString tmp;
413 if (!tmp.set_utf8(name))
414 return STATUS_NO_MEM;
415 return add_move(&tmp, value);
416 }
417
418 status_t Parameters::add(const value_t *value)
419 {
420 param_t *p = allocate();
421 if (p == NULL)
422 return STATUS_NO_MEM;
423
424 status_t res = init_value(&p->value, value);
425 if (res == STATUS_OK)
426 {
427 if (vParams.add(p))
428 {
429 modified();
430 return STATUS_OK;
431 }
432 res = STATUS_NO_MEM;
433 }
434
435 destroy(p);
436 return res;
437 }
438
439 status_t Parameters::add_move(value_t *value)
440 {
441 param_t *p = allocate();
442 if (p == NULL)
443 return STATUS_NO_MEM;
444
445 init_value_move(&p->value, value);
446 if (vParams.add(p))
447 {
448 modified();
449 return STATUS_OK;
450 }
451
452 destroy(p);
453 return STATUS_NO_MEM;
454 }
455
456 status_t Parameters::add_int(const char *name, ssize_t value)
457 {
458 value_t v;
459 v.type = VT_INT;
460 v.v_int = value;
461 return add(name, &v);
462 }
463
464 status_t Parameters::add_float(const char *name, double value)
465 {
466 value_t v;
467 v.type = VT_FLOAT;
468 v.v_float = value;
469 return add(name, &v);
470 }
471
472 status_t Parameters::add_bool(const char *name, bool value)
473 {
474 value_t v;
475 v.type = VT_BOOL;
476 v.v_bool = value;
477 return add(name, &v);
478 }
479
480 status_t Parameters::add_cstring(const char *name, const char *value)
481 {
482 if (value == NULL)
483 return add_null(name);
484
485 value_t v;
486 status_t res = init_value_string(&v, value);
487 if (res == STATUS_OK)
488 res = add_move(name, &v);
489 lsp_finally { destroy_value(&v); };
490
491 return res;
492 }
493
494 status_t Parameters::add_string(const char *name, const LSPString *value)
495 {
496 if (value == NULL)
497 return add_null(name);
498
499 value_t v;
500 v.type = VT_STRING;
501 v.v_str = const_cast<LSPString *>(value);
502 return add(name, &v);
503 }
504
505 status_t Parameters::add_null(const char *name)
506 {
507 value_t v;
508 v.type = VT_NULL;
509 v.v_str = NULL;
510 return add(name, &v);
511 }
512
513 status_t Parameters::add_undef(const char *name)
514 {
515 value_t v;
516 v.type = VT_UNDEF;
517 v.v_str = NULL;
518 return add(name, &v);
519 }
520
521 status_t Parameters::add_int(const LSPString *name, ssize_t value)
522 {
523 value_t v;
524 v.type = VT_INT;
525 v.v_int = value;
526 return add(name, &v);
527 }
528
529 status_t Parameters::add_float(const LSPString *name, double value)
530 {
531 value_t v;
532 v.type = VT_FLOAT;
533 v.v_float = value;
534 return add(name, &v);
535 }
536
537 status_t Parameters::add_bool(const LSPString *name, bool value)
538 {
539 value_t v;
540 v.type = VT_BOOL;
541 v.v_bool = value;
542 return add(name, &v);
543 }
544
545 status_t Parameters::add_cstring(const LSPString *name, const char *value)
546 {
547 if (value == NULL)
548 return add_null(name);
549
550 LSPString s;
551 if (!s.set_utf8(value))
552 return STATUS_NO_MEM;
553
554 value_t v;
555 v.type = VT_STRING;
556 v.v_str = &s;
557 return add(name, &v);
558 }
559
560 status_t Parameters::add_string(const LSPString *name, const LSPString *value)
561 {
562 if (value == NULL)
563 return add_null(name);
564
565 value_t v;
566 v.type = VT_STRING;
567 v.v_str = const_cast<LSPString *>(value);
568 return add(name, &v);
569 }
570
571 status_t Parameters::add_null(const LSPString *name)
572 {
573 value_t v;
574 v.type = VT_NULL;
575 v.v_str = NULL;
576 return add(name, &v);
577 }
578
579 status_t Parameters::add_undef(const LSPString *name)
580 {
581 value_t v;
582 v.type = VT_UNDEF;
583 v.v_str = NULL;
584 return add(name, &v);
585 }
586
587 status_t Parameters::add_int(ssize_t value)
588 {
589 value_t v;
590 v.type = VT_INT;
591 v.v_int = value;
592 return add(&v);
593 }
594
595 status_t Parameters::add_float(double value)
596 {
597 value_t v;
598 v.type = VT_FLOAT;
599 v.v_float = value;
600 return add(&v);
601 }
602
603 status_t Parameters::add_bool(bool value)
604 {
605 value_t v;
606 v.type = VT_BOOL;
607 v.v_bool = value;
608 return add(&v);
609 }
610
611 status_t Parameters::add_cstring(const char *value)
612 {
613 if (value == NULL)
614 return add_null();
615
616 LSPString s;
617 if (!s.set_utf8(value))
618 return STATUS_NO_MEM;
619
620 value_t v;
621 v.type = VT_STRING;
622 v.v_str = &s;
623 return add(&v);
624 }
625
626 status_t Parameters::add_string(const LSPString *value)
627 {
628 if (value == NULL)
629 return add_null();
630
631 value_t v;
632 v.type = VT_STRING;
633 v.v_str = const_cast<LSPString *>(value);
634 return add(&v);
635 }
636
637 status_t Parameters::add_null()
638 {
639 value_t v;
640 v.type = VT_NULL;
641 v.v_str = NULL;
642 return add(&v);
643 }
644
645 status_t Parameters::add_undef()
646 {
647 value_t v;
648 v.type = VT_UNDEF;
649 v.v_str = NULL;
650 return add(&v);
651 }
652
653 status_t Parameters::insert(size_t index, const char *name, const value_t *value)
654 {
655 if (name == NULL)
656 return insert(index, value);
657
658 LSPString tmp;
659 if (!tmp.set_utf8(name))
660 return STATUS_NO_MEM;
661 return insert(index, &tmp, value);
662 }
663
664 status_t Parameters::insert(size_t index, const LSPString *name, const value_t *value)
665 {
666 if (name == NULL)
667 return insert(index, value);
668 else if (index > vParams.size())
669 return STATUS_INVALID_VALUE;
670
671 param_t *p = allocate(name);
672 if (p == NULL)
673 return STATUS_NO_MEM;
674
675 status_t res = init_value(&p->value, value);
676 if (res == STATUS_OK)
677 {
678 if (vParams.insert(index, p))
679 {
680 modified();
681 return STATUS_OK;
682 }
683 res = STATUS_NO_MEM;
684 }
685
686 destroy(p);
687 return res;
688 }
689
690 status_t Parameters::insert(size_t index, const value_t *value)
691 {
692 if (index > vParams.size())
693 return STATUS_INVALID_VALUE;
694
695 param_t *p = allocate();
696 if (p == NULL)
697 return STATUS_NO_MEM;
698
699 status_t res = init_value(&p->value, value);
700 if (res == STATUS_OK)
701 {
702 if (vParams.insert(index, p))
703 {
704 modified();
705 return STATUS_OK;
706 }
707 res = STATUS_NO_MEM;
708 }
709
710 destroy(p);
711 return res;
712 }
713
714 status_t Parameters::insert_int(size_t index, const char *name, ssize_t value)
715 {
716 value_t v;
717 v.type = VT_INT;
718 v.v_int = value;
719 return insert(index, name, &v);
720 }
721
722 status_t Parameters::insert_float(size_t index, const char *name, double value)
723 {
724 value_t v;
725 v.type = VT_FLOAT;
726 v.v_float = value;
727 return insert(index, name, &v);
728 }
729
730 status_t Parameters::insert_bool(size_t index, const char *name, bool value)
731 {
732 value_t v;
733 v.type = VT_BOOL;
734 v.v_bool = value;
735 return insert(index, name, &v);
736 }
737
738 status_t Parameters::insert_string(size_t index, const char *name, const char *value)
739 {
740 if (value == NULL)
741 return insert_null(index, name);
742
743 LSPString s;
744 if (!s.set_utf8(value))
745 return STATUS_NO_MEM;
746
747 value_t v;
748 v.type = VT_STRING;
749 v.v_str = &s;
750 return insert(index, name, &v);
751 }
752
753 status_t Parameters::insert_string(size_t index, const char *name, const LSPString *value)
754 {
755 if (value == NULL)
756 return insert_null(index, name);
757
758 value_t v;
759 v.type = VT_STRING;
760 v.v_str = const_cast<LSPString *>(value);
761 return insert(index, name, &v);
762 }
763
764 status_t Parameters::insert_null(size_t index, const char *name)
765 {
766 value_t v;
767 v.type = VT_NULL;
768 v.v_str = NULL;
769 return insert(index, name, &v);
770 }
771
772 status_t Parameters::insert_undef(size_t index, const char *name)
773 {
774 value_t v;
775 v.type = VT_UNDEF;
776 v.v_str = NULL;
777 return insert(index, name, &v);
778 }
779
780 status_t Parameters::insert_int(size_t index, const LSPString *name, ssize_t value)
781 {
782 value_t v;
783 v.type = VT_INT;
784 v.v_int = value;
785 return insert(index, name, &v);
786 }
787
788 status_t Parameters::insert_float(size_t index, const LSPString *name, double value)
789 {
790 value_t v;
791 v.type = VT_FLOAT;
792 v.v_float = value;
793 return insert(index, name, &v);
794 }
795
796 status_t Parameters::insert_bool(size_t index, const LSPString *name, bool value)
797 {
798 value_t v;
799 v.type = VT_BOOL;
800 v.v_bool = value;
801 return insert(index, name, &v);
802 }
803
804 status_t Parameters::insert_string(size_t index, const LSPString *name, const char *value)
805 {
806 if (value == NULL)
807 return insert_null(index, name);
808
809 LSPString s;
810 if (!s.set_utf8(value))
811 return STATUS_NO_MEM;
812
813 value_t v;
814 v.type = VT_STRING;
815 v.v_str = &s;
816 return insert(index, name, &v);
817 }
818
819 status_t Parameters::insert_string(size_t index, const LSPString *name, const LSPString *value)
820 {
821 if (value == NULL)
822 return insert_null(index, name);
823
824 value_t v;
825 v.type = VT_STRING;
826 v.v_str = const_cast<LSPString *>(value);
827 return insert(index, name, &v);
828 }
829
830 status_t Parameters::insert_null(size_t index, const LSPString *name)
831 {
832 value_t v;
833 v.type = VT_NULL;
834 v.v_str = NULL;
835 return insert(index, name, &v);
836 }
837
838 status_t Parameters::insert_undef(size_t index, const LSPString *name)
839 {
840 value_t v;
841 v.type = VT_UNDEF;
842 v.v_str = NULL;
843 return insert(index, name, &v);
844 }
845
846 status_t Parameters::insert_int(size_t index, ssize_t value)
847 {
848 value_t v;
849 v.type = VT_INT;
850 v.v_int = value;
851 return insert(index, &v);
852 }
853
854 status_t Parameters::insert_float(size_t index, double value)
855 {
856 value_t v;
857 v.type = VT_FLOAT;
858 v.v_float = value;
859 return insert(index, &v);
860 }
861
862 status_t Parameters::insert_bool(size_t index, bool value)
863 {
864 value_t v;
865 v.type = VT_BOOL;
866 v.v_bool = value;
867 return insert(index, &v);
868 }
869
870 status_t Parameters::insert_cstring(size_t index, const char *value)
871 {
872 if (value == NULL)
873 return insert_null(index);
874
875 LSPString s;
876 if (!s.set_utf8(value))
877 return STATUS_NO_MEM;
878
879 value_t v;
880 v.type = VT_STRING;
881 v.v_str = &s;
882 return insert(index, &v);
883 }
884
885 status_t Parameters::insert_string(size_t index, const LSPString *value)
886 {
887 if (value == NULL)
888 return insert_null(index);
889
890 value_t v;
891 v.type = VT_STRING;
892 v.v_str = const_cast<LSPString *>(value);
893 return insert(index, &v);
894 }
895
896 status_t Parameters::insert_null(size_t index)
897 {
898 value_t v;
899 v.type = VT_NULL;
900 v.v_str = NULL;
901 return insert(index, &v);
902 }
903
904 status_t Parameters::insert_undef(size_t index)
905 {
906 value_t v;
907 v.type = VT_UNDEF;
908 v.v_str = NULL;
909 return insert(index, &v);
910 }
911
912 status_t Parameters::get(size_t index, value_t *value) const
913 {
914 const param_t *v = vParams.get(index);
915 if (v == NULL)
916 return STATUS_INVALID_VALUE;
917 return (value != NULL) ? copy_value(value, &v->value) : STATUS_OK;
918 }
919
920 status_t Parameters::get(const char *name, value_t *value) const
921 {
922 LSPString tmp;
923 if (!tmp.set_utf8(name))
924 return STATUS_NO_MEM;
925
926 return get(&tmp, value);
927 }
928
929 status_t Parameters::get(const LSPString *name, value_t *value) const
930 {
931 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
932 if (v == NULL)
933 return STATUS_NOT_FOUND;
934 return (value != NULL) ? copy_value(value, &v->value) : STATUS_OK;
935 }
936
937 status_t Parameters::get_int(size_t index, ssize_t *value) const
938 {
939 const param_t *v = vParams.get(index);
940 if (v == NULL)
941 return STATUS_INVALID_VALUE;
942 else if (v->value.type != VT_INT)
943 return STATUS_BAD_TYPE;
944 else if (value != NULL)
945 *value = v->value.v_int;
946 return STATUS_OK;
947 }
948
949 status_t Parameters::get_float(size_t index, double *value) const
950 {
951 const param_t *v = vParams.get(index);
952 if (v == NULL)
953 return STATUS_INVALID_VALUE;
954 else if (v->value.type != VT_FLOAT)
955 return STATUS_BAD_TYPE;
956 else if (value != NULL)
957 *value = v->value.v_float;
958 return STATUS_OK;
959 }
960
961 status_t Parameters::get_bool(size_t index, bool *value) const
962 {
963 const param_t *v = vParams.get(index);
964 if (v == NULL)
965 return STATUS_INVALID_VALUE;
966 else if (v->value.type != VT_BOOL)
967 return STATUS_BAD_TYPE;
968 else if (value != NULL)
969 *value = v->value.v_bool;
970 return STATUS_OK;
971 }
972
973 status_t Parameters::get_string(size_t index, LSPString *value) const
974 {
975 const param_t *v = vParams.get(index);
976 if (v == NULL)
977 return STATUS_INVALID_VALUE;
978 else if (v->value.type != VT_STRING)
979 return STATUS_BAD_TYPE;
980 else if (value != NULL)
981 {
982 if (!value->set(v->value.v_str))
983 return STATUS_NO_MEM;
984 }
985 return STATUS_OK;
986 }
987
988 status_t Parameters::get_null(size_t index) const
989 {
990 const param_t *v = vParams.get(index);
991 if (v == NULL)
992 return STATUS_INVALID_VALUE;
993 else if (v->value.type != VT_NULL)
994 return STATUS_BAD_TYPE;
995 return STATUS_OK;
996 }
997
998 status_t Parameters::get_undef(size_t index) const
999 {
1000 const param_t *v = vParams.get(index);
1001 if (v == NULL)
1002 return STATUS_INVALID_VALUE;
1003 else if (v->value.type != VT_UNDEF)
1004 return STATUS_BAD_TYPE;
1005 return STATUS_OK;
1006 }
1007
1008 status_t Parameters::get_int(const char *name, ssize_t *value) const
1009 {
1010 if (name == NULL)
1011 return STATUS_INVALID_VALUE;
1012 LSPString tmp;
1013 if (!tmp.set_utf8(name))
1014 return STATUS_NO_MEM;
1015
1016 return get_int(&tmp, value);
1017 }
1018
1019 status_t Parameters::get_float(const char *name, double *value) const
1020 {
1021 if (name == NULL)
1022 return STATUS_INVALID_VALUE;
1023 LSPString tmp;
1024 if (!tmp.set_utf8(name))
1025 return STATUS_NO_MEM;
1026
1027 return get_float(&tmp, value);
1028 }
1029
1030 status_t Parameters::get_bool(const char *name, bool *value) const
1031 {
1032 if (name == NULL)
1033 return STATUS_INVALID_VALUE;
1034 LSPString tmp;
1035 if (!tmp.set_utf8(name))
1036 return STATUS_NO_MEM;
1037
1038 return get_bool(&tmp, value);
1039 }
1040
1041 status_t Parameters::get_string(const char *name, LSPString *value) const
1042 {
1043 if (name == NULL)
1044 return STATUS_INVALID_VALUE;
1045 LSPString tmp;
1046 if (!tmp.set_utf8(name))
1047 return STATUS_NO_MEM;
1048
1049 return get_string(&tmp, value);
1050 }
1051
1052 status_t Parameters::get_null(const char *name) const
1053 {
1054 if (name == NULL)
1055 return STATUS_INVALID_VALUE;
1056 LSPString tmp;
1057 if (!tmp.set_utf8(name))
1058 return STATUS_NO_MEM;
1059
1060 return get_null(&tmp);
1061 }
1062
1063 status_t Parameters::get_undef(const char *name) const
1064 {
1065 if (name == NULL)
1066 return STATUS_INVALID_VALUE;
1067 LSPString tmp;
1068 if (!tmp.set_utf8(name))
1069 return STATUS_NO_MEM;
1070
1071 return get_undef(&tmp);
1072 }
1073
1074 status_t Parameters::get_int(const LSPString *name, ssize_t *value) const
1075 {
1076 if (name == NULL)
1077 return STATUS_INVALID_VALUE;
1078 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1079 if (v == NULL)
1080 return STATUS_NOT_FOUND;
1081 else if (v->value.type != VT_INT)
1082 return STATUS_BAD_TYPE;
1083 else if (value != NULL)
1084 *value = v->value.v_int;
1085
1086 return STATUS_OK;
1087 }
1088
1089 status_t Parameters::get_float(const LSPString *name, double *value) const
1090 {
1091 if (name == NULL)
1092 return STATUS_INVALID_VALUE;
1093 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1094 if (v == NULL)
1095 return STATUS_NOT_FOUND;
1096 else if (v->value.type != VT_FLOAT)
1097 return STATUS_BAD_TYPE;
1098 else if (value != NULL)
1099 *value = v->value.v_float;
1100
1101 return STATUS_OK;
1102 }
1103
1104 status_t Parameters::get_bool(const LSPString *name, bool *value) const
1105 {
1106 if (name == NULL)
1107 return STATUS_INVALID_VALUE;
1108 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1109 if (v == NULL)
1110 return STATUS_NOT_FOUND;
1111 else if (v->value.type != VT_BOOL)
1112 return STATUS_BAD_TYPE;
1113 else if (value != NULL)
1114 *value = v->value.v_bool;
1115
1116 return STATUS_OK;
1117 }
1118
1119 status_t Parameters::get_string(const LSPString *name, LSPString *value) const
1120 {
1121 if (name == NULL)
1122 return STATUS_INVALID_VALUE;
1123 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1124 if (v == NULL)
1125 return STATUS_NOT_FOUND;
1126 else if (v->value.type != VT_STRING)
1127 return STATUS_BAD_TYPE;
1128 else if (value != NULL)
1129 {
1130 if (!value->set(v->value.v_str))
1131 return STATUS_NO_MEM;
1132 }
1133
1134 return STATUS_OK;
1135 }
1136
1137 status_t Parameters::get_null(const LSPString *name) const
1138 {
1139 if (name == NULL)
1140 return STATUS_INVALID_VALUE;
1141 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1142 if (v == NULL)
1143 return STATUS_NOT_FOUND;
1144 else if (v->value.type != VT_NULL)
1145 return STATUS_BAD_TYPE;
1146
1147 return STATUS_OK;
1148 }
1149
1150 status_t Parameters::get_undef(const LSPString *name) const
1151 {
1152 if (name == NULL)
1153 return STATUS_INVALID_VALUE;
1154 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1155 if (v == NULL)
1156 return STATUS_NOT_FOUND;
1157 else if (v->value.type != VT_UNDEF)
1158 return STATUS_BAD_TYPE;
1159
1160 return STATUS_OK;
1161 }
1162
1163 status_t Parameters::as_value(size_t index, value_t *value, value_type_t type) const
1164 {
1165 const param_t *v = const_cast<Parameters *>(this)->vParams.get(index);
1166 if (v == NULL)
1167 return STATUS_INVALID_VALUE;
1168
1169 value_t tmp;
1170 status_t res = init_value(&tmp, &v->value);
1171 if (res == STATUS_OK)
1172 {
1173 if ((res = cast_value(&tmp, type)) == STATUS_OK)
1174 res = (tmp.type == type) ? copy_value(value, &tmp) : STATUS_BAD_TYPE;
1175 }
1176
1177 destroy_value(&tmp);
1178 return res;
1179 }
1180
1181 status_t Parameters::as_value(const LSPString *name, value_t *value, value_type_t type) const
1182 {
1183 if (name == NULL)
1184 return STATUS_INVALID_VALUE;
1185
1186 param_t *v = const_cast<Parameters *>(this)->lookup_by_name(name);
1187 if (v == NULL)
1188 return STATUS_NOT_FOUND;
1189
1190 value_t tmp;
1191 status_t res = init_value(&tmp, &v->value);
1192 if (res == STATUS_OK)
1193 {
1194 if ((res = cast_value(&tmp, type)) == STATUS_OK)
1195 res = (tmp.type == type) ? copy_value(value, &tmp) : STATUS_BAD_TYPE;
1196 }
1197
1198 destroy_value(&tmp);
1199 return res;
1200 }
1201
1202 status_t Parameters::as_value(const char *name, value_t *value, value_type_t type) const
1203 {
1204 if (name == NULL)
1205 return STATUS_INVALID_VALUE;
1206
1207 LSPString tmp;
1208 if (!tmp.set_utf8(name))
1209 return STATUS_NO_MEM;
1210
1211 return as_value(&tmp, value, type);
1212 }
1213
1214 status_t Parameters::as_int(size_t index, ssize_t *value) const
1215 {
1216 value_t v;
1217 init_value(&v);
1218 status_t res = as_value(index, &v, VT_INT);
1219 if (res == STATUS_OK)
1220 *value = v.v_int;
1221 destroy_value(&v);
1222 return res;
1223 }
1224
1225 status_t Parameters::as_float(size_t index, double *value) const
1226 {
1227 value_t v;
1228 init_value(&v);
1229 status_t res = as_value(index, &v, VT_FLOAT);
1230 if (res == STATUS_OK)
1231 *value = v.v_float;
1232 destroy_value(&v);
1233 return res;
1234 }
1235
1236 status_t Parameters::as_bool(size_t index, bool *value) const
1237 {
1238 value_t v;
1239 init_value(&v);
1240 status_t res = as_value(index, &v, VT_BOOL);
1241 if (res == STATUS_OK)
1242 *value = v.v_bool;
1243 destroy_value(&v);
1244 return res;
1245 }
1246
1247 status_t Parameters::as_string(size_t index, LSPString *value) const
1248 {
1249 value_t v;
1250 init_value(&v);
1251 status_t res = as_value(index, &v, VT_STRING);
1252 if (res == STATUS_OK)
1253 res = (value->set(v.v_str)) ? STATUS_OK : STATUS_NO_MEM;
1254 destroy_value(&v);
1255 return res;
1256 }
1257
1258 status_t Parameters::as_null(size_t index) const
1259 {
1260 value_t v;
1261 init_value(&v);
1262 status_t res = as_value(index, &v, VT_NULL);
1263 destroy_value(&v);
1264 return res;
1265 }
1266
1267 status_t Parameters::as_undef(size_t index) const
1268 {
1269 value_t v;
1270 init_value(&v);
1271 status_t res = as_value(index, &v, VT_UNDEF);
1272 destroy_value(&v);
1273 return res;
1274 }
1275
1276 status_t Parameters::as_int(const char *name, ssize_t *value) const
1277 {
1278 value_t v;
1279 init_value(&v);
1280 status_t res = as_value(name, &v, VT_INT);
1281 if (res == STATUS_OK)
1282 *value = v.v_int;
1283 destroy_value(&v);
1284 return res;
1285 }
1286
1287 status_t Parameters::as_float(const char *name, double *value) const
1288 {
1289 value_t v;
1290 init_value(&v);
1291 status_t res = as_value(name, &v, VT_FLOAT);
1292 if (res == STATUS_OK)
1293 *value = v.v_float;
1294 destroy_value(&v);
1295 return res;
1296 }
1297
1298 status_t Parameters::as_bool(const char *name, bool *value) const
1299 {
1300 value_t v;
1301 init_value(&v);
1302 status_t res = as_value(name, &v, VT_BOOL);
1303 if (res == STATUS_OK)
1304 *value = v.v_bool;
1305 destroy_value(&v);
1306 return res;
1307 }
1308
1309 status_t Parameters::as_string(const char *name, LSPString *value) const
1310 {
1311 value_t v;
1312 init_value(&v);
1313 status_t res = as_value(name, &v, VT_STRING);
1314 if (res == STATUS_OK)
1315 res = (value->set(v.v_str)) ? STATUS_OK : STATUS_NO_MEM;
1316 destroy_value(&v);
1317 return res;
1318 }
1319
1320 status_t Parameters::as_null(const char *name) const
1321 {
1322 value_t v;
1323 init_value(&v);
1324 status_t res = as_value(name, &v, VT_NULL);
1325 destroy_value(&v);
1326 return res;
1327 }
1328
1329 status_t Parameters::as_undef(const char *name) const
1330 {
1331 value_t v;
1332 init_value(&v);
1333 status_t res = as_value(name, &v, VT_UNDEF);
1334 destroy_value(&v);
1335 return res;
1336 }
1337
1338 status_t Parameters::as_int(const LSPString *name, ssize_t *value) const
1339 {
1340 value_t v;
1341 init_value(&v);
1342 status_t res = as_value(name, &v, VT_INT);
1343 if (res == STATUS_OK)
1344 *value = v.v_int;
1345 destroy_value(&v);
1346 return res;
1347 }
1348
1349 status_t Parameters::as_float(const LSPString *name, double *value) const
1350 {
1351 value_t v;
1352 init_value(&v);
1353 status_t res = as_value(name, &v, VT_FLOAT);
1354 if (res == STATUS_OK)
1355 *value = v.v_float;
1356 destroy_value(&v);
1357 return res;
1358 }
1359
1360 status_t Parameters::as_bool(const LSPString *name, bool *value) const
1361 {
1362 value_t v;
1363 init_value(&v);
1364 status_t res = as_value(name, &v, VT_BOOL);
1365 if (res == STATUS_OK)
1366 *value = v.v_bool;
1367 destroy_value(&v);
1368 return res;
1369 }
1370
1371 status_t Parameters::as_string(const LSPString *name, LSPString *value) const
1372 {
1373 value_t v;
1374 init_value(&v);
1375 status_t res = as_value(name, &v, VT_STRING);
1376 if (res == STATUS_OK)
1377 res = (value->set(v.v_str)) ? STATUS_OK : STATUS_NO_MEM;
1378 destroy_value(&v);
1379 return res;
1380 }
1381
1382 status_t Parameters::as_null(const LSPString *name) const
1383 {
1384 value_t v;
1385 init_value(&v);
1386 status_t res = as_value(name, &v, VT_NULL);
1387 destroy_value(&v);
1388 return res;
1389 }
1390
1391 status_t Parameters::as_undef(const LSPString *name) const
1392 {
1393 value_t v;
1394 init_value(&v);
1395 status_t res = as_value(name, &v, VT_UNDEF);
1396 destroy_value(&v);
1397 return res;
1398 }
1399
1400 status_t Parameters::set(const char *name, const value_t *value)
1401 {
1402 if (name == NULL)
1403 return STATUS_INVALID_VALUE;
1404
1405 LSPString tmp;
1406 if (!tmp.set_utf8(name))
1407 return STATUS_NO_MEM;
1408
1409 return set(&tmp, value);
1410 }
1411
1412 status_t Parameters::set(const LSPString *name, const value_t *value)
1413 {
1414 param_t *v = lookup_by_name(name);
1415 if (v == NULL)
1416 return add(name, value);
1417
1418 status_t res = copy_value(&v->value, value);
1419 if (res == STATUS_OK)
1420 modified();
1421 return res;
1422 }
1423
1424 status_t Parameters::set(size_t index, const value_t *value)
1425 {
1426 param_t *v = vParams.get(index);
1427 if (v == NULL)
1428 return STATUS_INVALID_VALUE;
1429
1430 status_t res = copy_value(&v->value, value);
1431 if (res == STATUS_OK)
1432 modified();
1433 return res;
1434 }
1435
1436 status_t Parameters::set_int(const char *name, ssize_t value)
1437 {
1438 value_t v;
1439 v.type = VT_INT;
1440 v.v_int = value;
1441 return set(name, &v);
1442 }
1443
1444 status_t Parameters::set_float(const char *name, double value)
1445 {
1446 value_t v;
1447 v.type = VT_FLOAT;
1448 v.v_float = value;
1449 return set(name, &v);
1450 }
1451
1452 status_t Parameters::set_bool(const char *name, bool value)
1453 {
1454 value_t v;
1455 v.type = VT_BOOL;
1456 v.v_bool = value;
1457 return set(name, &v);
1458 }
1459
1460 status_t Parameters::set_cstring(const char *name, const char *value)
1461 {
1462 if (value == NULL)
1463 return set_null(name);
1464
1465 LSPString tmp;
1466 if (!tmp.set_utf8(value))
1467 return STATUS_NO_MEM;
1468
1469 value_t v;
1470 v.type = VT_STRING;
1471 v.v_str = &tmp;
1472 return set(name, &v);
1473 }
1474
1475 status_t Parameters::set_string(const char *name, const LSPString *value)
1476 {
1477 value_t v;
1478 v.type = VT_STRING;
1479 v.v_str = const_cast<LSPString *>(value);
1480 return set(name, &v);
1481 }
1482
1483 status_t Parameters::set_null(const char *name)
1484 {
1485 value_t v;
1486 v.type = VT_NULL;
1487 v.v_str = NULL;
1488 return set(name, &v);
1489 }
1490
1491 status_t Parameters::set_undef(const char *name)
1492 {
1493 value_t v;
1494 v.type = VT_UNDEF;
1495 v.v_str = NULL;
1496 return set(name, &v);
1497 }
1498
1499 status_t Parameters::set_int(const LSPString *name, ssize_t value)
1500 {
1501 value_t v;
1502 v.type = VT_INT;
1503 v.v_int = value;
1504 return set(name, &v);
1505 }
1506
1507 status_t Parameters::set_float(const LSPString *name, double value)
1508 {
1509 value_t v;
1510 v.type = VT_FLOAT;
1511 v.v_float = value;
1512 return set(name, &v);
1513 }
1514
1515 status_t Parameters::set_bool(const LSPString *name, bool value)
1516 {
1517 value_t v;
1518 v.type = VT_BOOL;
1519 v.v_bool = value;
1520 return set(name, &v);
1521 }
1522
1523 status_t Parameters::set_cstring(const LSPString *name, const char *value)
1524 {
1525 if (value == NULL)
1526 return set_null(name);
1527
1528 LSPString tmp;
1529 if (!tmp.set_utf8(value))
1530 return STATUS_NO_MEM;
1531
1532 value_t v;
1533 v.type = VT_STRING;
1534 v.v_str = &tmp;
1535 return set(name, &v);
1536 }
1537
1538 status_t Parameters::set_string(const LSPString *name, const LSPString *value)
1539 {
1540 value_t v;
1541 v.type = VT_STRING;
1542 v.v_str = const_cast<LSPString *>(value);
1543 return set(name, &v);
1544 }
1545
1546 status_t Parameters::set_null(const LSPString *name)
1547 {
1548 value_t v;
1549 v.type = VT_NULL;
1550 v.v_str = NULL;
1551 return set(name, &v);
1552 }
1553
1554 status_t Parameters::set_undef(const LSPString *name)
1555 {
1556 value_t v;
1557 v.type = VT_UNDEF;
1558 v.v_str = NULL;
1559 return set(name, &v);
1560 }
1561
1562 status_t Parameters::set_int(size_t index, ssize_t value)
1563 {
1564 value_t v;
1565 v.type = VT_INT;
1566 v.v_int = value;
1567 return set(index, &v);
1568 }
1569
1570 status_t Parameters::set_float(size_t index, double value)
1571 {
1572 value_t v;
1573 v.type = VT_FLOAT;
1574 v.v_float = value;
1575 return set(index, &v);
1576 }
1577
1578 status_t Parameters::set_bool(size_t index, bool value)
1579 {
1580 value_t v;
1581 v.type = VT_BOOL;
1582 v.v_bool = value;
1583 return set(index, &v);
1584 }
1585
1586 status_t Parameters::set_cstring(size_t index, const char *value)
1587 {
1588 if (value == NULL)
1589 return set_null(index);
1590
1591 LSPString tmp;
1592 if (!tmp.set_utf8(value))
1593 return STATUS_NO_MEM;
1594
1595 value_t v;
1596 v.type = VT_STRING;
1597 v.v_str = &tmp;
1598 return set(index, &v);
1599 }
1600
1601 status_t Parameters::set_string(size_t index, const LSPString *value)
1602 {
1603 value_t v;
1604 v.type = VT_STRING;
1605 v.v_str = const_cast<LSPString *>(value);
1606 return set(index, &v);
1607 }
1608
1609 status_t Parameters::set_null(size_t index)
1610 {
1611 value_t v;
1612 v.type = VT_NULL;
1613 v.v_str = NULL;
1614 return set(index, &v);
1615 }
1616
1617 status_t Parameters::set_undef(size_t index)
1618 {
1619 value_t v;
1620 v.type = VT_UNDEF;
1621 v.v_str = NULL;
1622 return set(index, &v);
1623 }
1624
1625 status_t Parameters::remove(size_t index, value_t *value)
1626 {
1627 param_t *v = vParams.get(index);
1628 if (v == NULL)
1629 return STATUS_INVALID_VALUE;
1630 if (value != NULL)
1631 {
1632 status_t res = copy_value(value, &v->value);
1633 if (res != STATUS_OK)
1634 return res;
1635 }
1636
1637 vParams.remove(index);
1638 destroy(v);
1639 modified();
1640 return STATUS_OK;
1641 }
1642
1643 status_t Parameters::remove_value(size_t index, value_type_t type, value_t *value)
1644 {
1645 param_t *v = vParams.get(index);
1646 if (v == NULL)
1647 return STATUS_INVALID_VALUE;
1648 else if (v->value.type != type)
1649 return STATUS_BAD_TYPE;
1650 if (value != NULL)
1651 {
1652 status_t res = copy_value(value, &v->value);
1653 if (res != STATUS_OK)
1654 return res;
1655 }
1656
1657 vParams.remove(index);
1658 destroy(v);
1659 modified();
1660 return STATUS_OK;
1661 }
1662
1663 status_t Parameters::remove(const char *name, value_t *value)
1664 {
1665 if (name == NULL)
1666 return STATUS_INVALID_VALUE;
1667
1668 LSPString tmp;
1669 if (!tmp.set_utf8(name))
1670 return STATUS_NO_MEM;
1671
1672 return remove(&tmp, value);
1673 }
1674
1675 status_t Parameters::remove_value(const char *name, value_type_t type, value_t *value)
1676 {
1677 if (name == NULL)
1678 return STATUS_INVALID_VALUE;
1679
1680 LSPString tmp;
1681 if (!tmp.set_utf8(name))
1682 return STATUS_NO_MEM;
1683
1684 return remove_value(&tmp, type, value);
1685 }
1686
1687 status_t Parameters::remove(const LSPString *name, value_t *value)
1688 {
1689 if (name == NULL)
1690 return STATUS_INVALID_VALUE;
1691
1692 size_t index;
1693 param_t *v = lookup_by_name(name, &index);
1694 if (v == NULL)
1695 return STATUS_NOT_FOUND;
1696 if (value != NULL)
1697 {
1698 status_t res = copy_value(value, &v->value);
1699 if (res != STATUS_OK)
1700 return res;
1701 }
1702
1703 vParams.remove(index);
1704 destroy(v);
1705 modified();
1706 return STATUS_OK;
1707 }
1708
1709 status_t Parameters::remove_value(const LSPString *name, value_type_t type, value_t *value)
1710 {
1711 if (name == NULL)
1712 return STATUS_INVALID_VALUE;
1713
1714 size_t index;
1715 param_t *v = lookup_by_name(name, &index);
1716 if (v == NULL)
1717 return STATUS_NOT_FOUND;
1718 else if (v->value.type != type)
1719 return STATUS_BAD_TYPE;
1720 if (value != NULL)
1721 {
1722 status_t res = copy_value(value, &v->value);
1723 if (res != STATUS_OK)
1724 return res;
1725 }
1726
1727 vParams.remove(index);
1728 destroy(v);
1729 modified();
1730 return STATUS_OK;
1731 }
1732
1733 status_t Parameters::remove(ssize_t first, ssize_t last)
1734 {
1735 if ((first < 0) || (last > ssize_t(vParams.size())))
1736 return STATUS_INVALID_VALUE;
1737
1738 ssize_t count = last - first;
1739 if (count < 0)
1740 return STATUS_INVALID_VALUE;
1741
1742 for (ssize_t i=first; i<last; ++i)
1743 destroy(vParams.uget(i));
1744
1745 bool success = vParams.remove_n(first, count);
1746 if (success)
1747 modified();
1748 return (success) ? STATUS_OK : STATUS_CORRUPTED;
1749 }
1750
1751 status_t Parameters::drop_value(size_t index, value_type_t type, param_t **out)
1752 {
1753 param_t *v = vParams.get(index);
1754 if (v == NULL)
1755 return STATUS_INVALID_VALUE;
1756 else if (v->value.type != type)
1757 return STATUS_BAD_TYPE;
1758
1759 vParams.remove(index);
1760 *out = v;
1761 modified();
1762 return STATUS_OK;
1763 }
1764
1765 status_t Parameters::drop_value(const char *name, value_type_t type, param_t **out)
1766 {
1767 if (name == NULL)
1768 return STATUS_INVALID_VALUE;
1769
1770 LSPString tmp;
1771 if (!tmp.set_utf8(name))
1772 return STATUS_NO_MEM;
1773
1774 return drop_value(&tmp, type, out);
1775 }
1776
1777 status_t Parameters::drop_value(const LSPString *name, value_type_t type, param_t **out)
1778 {
1779 size_t index;
1780 param_t *v = lookup_by_name(name, &index);
1781 if (v == NULL)
1782 return STATUS_NOT_FOUND;
1783 else if (v->value.type != type)
1784 return STATUS_BAD_TYPE;
1785
1786 vParams.remove(index);
1787 *out = v;
1788 modified();
1789 return STATUS_OK;
1790 }
1791
1792 status_t Parameters::remove_int(size_t index, ssize_t *value)
1793 {
1794 param_t *pv;
1795 status_t res = drop_value(index, VT_INT, &pv);
1796 if (res != STATUS_OK)
1797 return res;
1798 if (value != NULL)
1799 *value = pv->value.v_int;
1800 destroy(pv);
1801 return STATUS_OK;
1802 }
1803
1804 status_t Parameters::remove_float(size_t index, double *value)
1805 {
1806 param_t *pv;
1807 status_t res = drop_value(index, VT_FLOAT, &pv);
1808 if (res != STATUS_OK)
1809 return res;
1810 if (value != NULL)
1811 *value = pv->value.v_float;
1812 destroy(pv);
1813 return STATUS_OK;
1814 }
1815
1816 status_t Parameters::remove_bool(size_t index, bool *value)
1817 {
1818 param_t *pv;
1819 status_t res = drop_value(index, VT_BOOL, &pv);
1820 if (res != STATUS_OK)
1821 return res;
1822 if (value != NULL)
1823 *value = pv->value.v_bool;
1824 destroy(pv);
1825 return STATUS_OK;
1826 }
1827
1828 status_t Parameters::remove_string(size_t index, LSPString *value)
1829 {
1830 param_t *pv;
1831 status_t res = drop_value(index, VT_STRING, &pv);
1832 if (res != STATUS_OK)
1833 return res;
1834 if (value != NULL)
1835 value->swap(pv->value.v_str);
1836 destroy(pv);
1837 return STATUS_OK;
1838 }
1839
1840 status_t Parameters::remove_null(size_t index)
1841 {
1842 param_t *pv;
1843 status_t res = drop_value(index, VT_NULL, &pv);
1844 if (res != STATUS_OK)
1845 return res;
1846 destroy(pv);
1847 return STATUS_OK;
1848 }
1849
1850 status_t Parameters::remove_undef(size_t index)
1851 {
1852 param_t *pv;
1853 status_t res = drop_value(index, VT_UNDEF, &pv);
1854 if (res != STATUS_OK)
1855 return res;
1856 destroy(pv);
1857 return STATUS_OK;
1858 }
1859
1860
1861
1862 status_t Parameters::remove_int(const char *name, ssize_t *value)
1863 {
1864 param_t *pv;
1865 status_t res = drop_value(name, VT_INT, &pv);
1866 if (res != STATUS_OK)
1867 return res;
1868 if (value != NULL)
1869 *value = pv->value.v_int;
1870 destroy(pv);
1871 return STATUS_OK;
1872 }
1873
1874 status_t Parameters::remove_float(const char *name, double *value)
1875 {
1876 param_t *pv;
1877 status_t res = drop_value(name, VT_FLOAT, &pv);
1878 if (res != STATUS_OK)
1879 return res;
1880 if (value != NULL)
1881 *value = pv->value.v_float;
1882 destroy(pv);
1883 return STATUS_OK;
1884 }
1885
1886 status_t Parameters::remove_bool(const char *name, bool *value)
1887 {
1888 param_t *pv;
1889 status_t res = drop_value(name, VT_BOOL, &pv);
1890 if (res != STATUS_OK)
1891 return res;
1892 if (value != NULL)
1893 *value = pv->value.v_bool;
1894 destroy(pv);
1895 return STATUS_OK;
1896 }
1897
1898 status_t Parameters::remove_string(const char *name, LSPString *value)
1899 {
1900 param_t *pv;
1901 status_t res = drop_value(name, VT_STRING, &pv);
1902 if (res != STATUS_OK)
1903 return res;
1904 if (value != NULL)
1905 value->swap(pv->value.v_str);
1906 destroy(pv);
1907 return STATUS_OK;
1908 }
1909
1910 status_t Parameters::remove_null(const char *name)
1911 {
1912 param_t *pv;
1913 status_t res = drop_value(name, VT_NULL, &pv);
1914 if (res != STATUS_OK)
1915 return res;
1916 destroy(pv);
1917 return STATUS_OK;
1918 }
1919
1920 status_t Parameters::remove_undef(const char *name)
1921 {
1922 param_t *pv;
1923 status_t res = drop_value(name, VT_UNDEF, &pv);
1924 if (res != STATUS_OK)
1925 return res;
1926 destroy(pv);
1927 return STATUS_OK;
1928 }
1929
1930
1931
1932
1933 status_t Parameters::remove_int(const LSPString *name, ssize_t *value)
1934 {
1935 param_t *pv;
1936 status_t res = drop_value(name, VT_INT, &pv);
1937 if (res != STATUS_OK)
1938 return res;
1939 if (value != NULL)
1940 *value = pv->value.v_int;
1941 destroy(pv);
1942 return STATUS_OK;
1943 }
1944
1945 status_t Parameters::remove_float(const LSPString *name, double *value)
1946 {
1947 param_t *pv;
1948 status_t res = drop_value(name, VT_FLOAT, &pv);
1949 if (res != STATUS_OK)
1950 return res;
1951 if (value != NULL)
1952 *value = pv->value.v_float;
1953 destroy(pv);
1954 return STATUS_OK;
1955 }
1956
1957 status_t Parameters::remove_bool(const LSPString *name, bool *value)
1958 {
1959 param_t *pv;
1960 status_t res = drop_value(name, VT_BOOL, &pv);
1961 if (res != STATUS_OK)
1962 return res;
1963 if (value != NULL)
1964 *value = pv->value.v_bool;
1965 destroy(pv);
1966 return STATUS_OK;
1967 }
1968
1969 status_t Parameters::remove_string(const LSPString *name, LSPString *value)
1970 {
1971 param_t *pv;
1972 status_t res = drop_value(name, VT_STRING, &pv);
1973 if (res != STATUS_OK)
1974 return res;
1975 if (value != NULL)
1976 value->swap(pv->value.v_str);
1977 destroy(pv);
1978 return STATUS_OK;
1979 }
1980
1981 status_t Parameters::remove_null(const LSPString *name)
1982 {
1983 param_t *pv;
1984 status_t res = drop_value(name, VT_NULL, &pv);
1985 if (res != STATUS_OK)
1986 return res;
1987 destroy(pv);
1988 return STATUS_OK;
1989 }
1990
1991 status_t Parameters::remove_undef(const LSPString *name)
1992 {
1993 param_t *pv;
1994 status_t res = drop_value(name, VT_UNDEF, &pv);
1995 if (res != STATUS_OK)
1996 return res;
1997 destroy(pv);
1998 return STATUS_OK;
1999 }
2000
2001 } /* namespace expr */
2002 } /* namespace lsp */