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