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