18 #ifndef ION_BASE_VARIANT_H_
19 #define ION_BASE_VARIANT_H_
33 namespace internal_variant_utils {
41 static const bool value =
false;
48 template <
typename Type>
51 template <
typename T1>
inline void Init(
const T1& p1) {
60 const size_t size = count *
sizeof(Type);
63 *
reinterpret_cast<void**
>(space_) = ptr;
65 val_ =
static_cast<Type*
>(ptr);
72 const size_t size = count *
sizeof(Type);
74 const Type* other_array =
75 *
reinterpret_cast<const Type*const*
>(other.space_);
78 for (
size_t i = 0; i < count; ++i)
79 new(&array[i]) Type(other_array[i]);
80 *
reinterpret_cast<void**
>(space_) = array;
82 val_ =
static_cast<Type*
>(array);
87 return reinterpret_cast<Type*
>(space_);
89 inline const Type*
Get()
const {
90 return reinterpret_cast<const Type*
>(space_);
92 inline const Type&
GetAt(
size_t i)
const {
93 return (*reinterpret_cast<const Type* const*>(space_))[i];
96 (*
reinterpret_cast<Type**
>(space_))[i] =
value;
101 if (Type* values = *reinterpret_cast<Type**>(space_)) {
102 for (
size_t i = 0; i < count; ++i)
107 reinterpret_cast<Type*
>(space_)->~Type();
112 ION_ALIGN(16) char space_[sizeof(Type)];
160 template <
typename T1,
161 typename T2 = internal_variant_utils::EmptyType<2>,
162 typename T3 = internal_variant_utils::EmptyType<3>,
163 typename T4 = internal_variant_utils::EmptyType<4>,
164 typename T5 = internal_variant_utils::EmptyType<5>,
165 typename T6 = internal_variant_utils::EmptyType<6>,
166 typename T7 = internal_variant_utils::EmptyType<7>,
167 typename T8 = internal_variant_utils::EmptyType<8>,
168 typename T9 = internal_variant_utils::EmptyType<9>,
169 typename T10 = internal_variant_utils::EmptyType<10>,
170 typename T11 = internal_variant_utils::EmptyType<11>,
171 typename T12 = internal_variant_utils::EmptyType<12>,
172 typename T13 = internal_variant_utils::EmptyType<13>,
173 typename T14 = internal_variant_utils::EmptyType<14>,
174 typename T15 = internal_variant_utils::EmptyType<15>,
175 typename T16 = internal_variant_utils::EmptyType<16>,
176 typename T17 = internal_variant_utils::EmptyType<17>,
177 typename T18 = internal_variant_utils::EmptyType<18>,
178 typename T19 = internal_variant_utils::EmptyType<19>,
179 typename T20 = internal_variant_utils::EmptyType<20>,
180 typename T21 = internal_variant_utils::EmptyType<21>,
181 typename T22 = internal_variant_utils::EmptyType<22>,
182 typename T23 = internal_variant_utils::EmptyType<23>,
183 typename T24 = internal_variant_utils::EmptyType<24>,
184 typename T25 = internal_variant_utils::EmptyType<25>,
185 typename T26 = internal_variant_utils::EmptyType<26>,
186 typename T27 = internal_variant_utils::EmptyType<27>,
187 typename T28 = internal_variant_utils::EmptyType<28>,
188 typename T29 = internal_variant_utils::EmptyType<29>,
189 typename T30 = internal_variant_utils::EmptyType<30>,
190 typename T31 = internal_variant_utils::EmptyType<31>,
191 typename T32 = internal_variant_utils::EmptyType<32>,
192 typename T33 = internal_variant_utils::EmptyType<33>,
193 typename T34 = internal_variant_utils::EmptyType<34>,
194 typename T35 = internal_variant_utils::EmptyType<35>,
195 typename T36 = internal_variant_utils::EmptyType<36>,
196 typename T37 = internal_variant_utils::EmptyType<37>,
197 typename T38 = internal_variant_utils::EmptyType<38>,
198 typename T39 = internal_variant_utils::EmptyType<39>,
199 typename T40 = internal_variant_utils::EmptyType<40> >
298 template <
typename T>
303 tag_ = Tag<T>::kValue;
304 MakeArray(static_cast<const T*>(NULL), count);
311 alloc_ = from.alloc_;
312 count_ = from.count_;
320 template <
typename T>
bool Is()
const {
322 "Empty type for Variant::Is");
323 return !count_ && tag_ == ExactTag<T>::kValue;
330 "Empty type for Variant::IsArrayOf");
331 return count_ && tag_ == ExactTag<T>::kValue;
350 "Empty type for Variant::IsAssignableTo");
351 return !count_ && tag_ == Tag<T>::kValue;
357 "Empty type for Variant::ElementsAssignableTo");
358 return count_ && tag_ == Tag<T>::kValue;
364 template <
typename T>
const T&
Get()
const {
365 return Is<T>() ? GetValue(static_cast<const T*>(NULL)) :
366 InvalidReference<T>();
373 return IsArrayOf<T>() && i < count_ ? GetAt(static_cast<const T*>(NULL), i)
374 : InvalidReference<T>();
380 if (ElementsAssignableTo<T>() && i < count_)
415 template <
typename T>
416 operator const T()
const {
417 return variant_->template GetValueAt<T>(
i);
419 template <
typename T>
423 template <
typename T>
425 return variant_->template GetValueAt<T>(
i) == value;
434 return ArrayAccessor(
this, i);
439 template <
int N>
struct SizedArray {
char array[N]; };
451 static SizedArray<1> GetSizedArrayForTag(
const T1&);
452 static SizedArray<2> GetSizedArrayForTag(
const T2&);
453 static SizedArray<3> GetSizedArrayForTag(
const T3&);
454 static SizedArray<4> GetSizedArrayForTag(
const T4&);
455 static SizedArray<5> GetSizedArrayForTag(
const T5&);
456 static SizedArray<6> GetSizedArrayForTag(
const T6&);
457 static SizedArray<7> GetSizedArrayForTag(
const T7&);
458 static SizedArray<8> GetSizedArrayForTag(
const T8&);
459 static SizedArray<9> GetSizedArrayForTag(
const T9&);
460 static SizedArray<10> GetSizedArrayForTag(
const T10&);
461 static SizedArray<11> GetSizedArrayForTag(
const T11&);
462 static SizedArray<12> GetSizedArrayForTag(
const T12&);
463 static SizedArray<13> GetSizedArrayForTag(
const T13&);
464 static SizedArray<14> GetSizedArrayForTag(
const T14&);
465 static SizedArray<15> GetSizedArrayForTag(
const T15&);
466 static SizedArray<16> GetSizedArrayForTag(
const T16&);
467 static SizedArray<17> GetSizedArrayForTag(
const T17&);
468 static SizedArray<18> GetSizedArrayForTag(
const T18&);
469 static SizedArray<19> GetSizedArrayForTag(
const T19&);
470 static SizedArray<20> GetSizedArrayForTag(
const T20&);
471 static SizedArray<21> GetSizedArrayForTag(
const T21&);
472 static SizedArray<22> GetSizedArrayForTag(
const T22&);
473 static SizedArray<23> GetSizedArrayForTag(
const T23&);
474 static SizedArray<24> GetSizedArrayForTag(
const T24&);
475 static SizedArray<25> GetSizedArrayForTag(
const T25&);
476 static SizedArray<26> GetSizedArrayForTag(
const T26&);
477 static SizedArray<27> GetSizedArrayForTag(
const T27&);
478 static SizedArray<28> GetSizedArrayForTag(
const T28&);
479 static SizedArray<29> GetSizedArrayForTag(
const T29&);
480 static SizedArray<30> GetSizedArrayForTag(
const T30&);
481 static SizedArray<31> GetSizedArrayForTag(
const T31&);
482 static SizedArray<32> GetSizedArrayForTag(
const T32&);
483 static SizedArray<33> GetSizedArrayForTag(
const T33&);
484 static SizedArray<34> GetSizedArrayForTag(
const T34&);
485 static SizedArray<35> GetSizedArrayForTag(
const T35&);
486 static SizedArray<36> GetSizedArrayForTag(
const T36&);
487 static SizedArray<37> GetSizedArrayForTag(
const T37&);
488 static SizedArray<38> GetSizedArrayForTag(
const T38&);
489 static SizedArray<39> GetSizedArrayForTag(
const T39&);
490 static SizedArray<40> GetSizedArrayForTag(
const T40&);
495 template<
typename T>
struct ExactMatch {};
496 static SizedArray<1> GetSizedArrayForExactTag(
const ExactMatch<T1>&);
497 static SizedArray<2> GetSizedArrayForExactTag(
const ExactMatch<T2>&);
498 static SizedArray<3> GetSizedArrayForExactTag(
const ExactMatch<T3>&);
499 static SizedArray<4> GetSizedArrayForExactTag(
const ExactMatch<T4>&);
500 static SizedArray<5> GetSizedArrayForExactTag(
const ExactMatch<T5>&);
501 static SizedArray<6> GetSizedArrayForExactTag(
const ExactMatch<T6>&);
502 static SizedArray<7> GetSizedArrayForExactTag(
const ExactMatch<T7>&);
503 static SizedArray<8> GetSizedArrayForExactTag(
const ExactMatch<T8>&);
504 static SizedArray<9> GetSizedArrayForExactTag(
const ExactMatch<T9>&);
505 static SizedArray<10> GetSizedArrayForExactTag(
const ExactMatch<T10>&);
506 static SizedArray<11> GetSizedArrayForExactTag(
const ExactMatch<T11>&);
507 static SizedArray<12> GetSizedArrayForExactTag(
const ExactMatch<T12>&);
508 static SizedArray<13> GetSizedArrayForExactTag(
const ExactMatch<T13>&);
509 static SizedArray<14> GetSizedArrayForExactTag(
const ExactMatch<T14>&);
510 static SizedArray<15> GetSizedArrayForExactTag(
const ExactMatch<T15>&);
511 static SizedArray<16> GetSizedArrayForExactTag(
const ExactMatch<T16>&);
512 static SizedArray<17> GetSizedArrayForExactTag(
const ExactMatch<T17>&);
513 static SizedArray<18> GetSizedArrayForExactTag(
const ExactMatch<T18>&);
514 static SizedArray<19> GetSizedArrayForExactTag(
const ExactMatch<T19>&);
515 static SizedArray<20> GetSizedArrayForExactTag(
const ExactMatch<T20>&);
516 static SizedArray<21> GetSizedArrayForExactTag(
const ExactMatch<T21>&);
517 static SizedArray<22> GetSizedArrayForExactTag(
const ExactMatch<T22>&);
518 static SizedArray<23> GetSizedArrayForExactTag(
const ExactMatch<T23>&);
519 static SizedArray<24> GetSizedArrayForExactTag(
const ExactMatch<T24>&);
520 static SizedArray<25> GetSizedArrayForExactTag(
const ExactMatch<T25>&);
521 static SizedArray<26> GetSizedArrayForExactTag(
const ExactMatch<T26>&);
522 static SizedArray<27> GetSizedArrayForExactTag(
const ExactMatch<T27>&);
523 static SizedArray<28> GetSizedArrayForExactTag(
const ExactMatch<T28>&);
524 static SizedArray<29> GetSizedArrayForExactTag(
const ExactMatch<T29>&);
525 static SizedArray<30> GetSizedArrayForExactTag(
const ExactMatch<T30>&);
526 static SizedArray<31> GetSizedArrayForExactTag(
const ExactMatch<T31>&);
527 static SizedArray<32> GetSizedArrayForExactTag(
const ExactMatch<T32>&);
528 static SizedArray<33> GetSizedArrayForExactTag(
const ExactMatch<T33>&);
529 static SizedArray<34> GetSizedArrayForExactTag(
const ExactMatch<T34>&);
530 static SizedArray<35> GetSizedArrayForExactTag(
const ExactMatch<T35>&);
531 static SizedArray<36> GetSizedArrayForExactTag(
const ExactMatch<T36>&);
532 static SizedArray<37> GetSizedArrayForExactTag(
const ExactMatch<T37>&);
533 static SizedArray<38> GetSizedArrayForExactTag(
const ExactMatch<T38>&);
534 static SizedArray<39> GetSizedArrayForExactTag(
const ExactMatch<T39>&);
535 static SizedArray<40> GetSizedArrayForExactTag(
const ExactMatch<T40>&);
540 template <
typename T>
struct Tag {
541 static const int kValue =
542 sizeof(GetSizedArrayForTag(*static_cast<const T*>(NULL)).array);
544 template <
typename T>
struct ExactTag {
545 static const int kValue =
546 sizeof(GetSizedArrayForExactTag(ExactMatch<T>()).array);
552 case Tag<T1>::kValue: values_.t1.Destroy(alloc_, count_);
break;
553 case Tag<T2>::kValue: values_.t2.Destroy(alloc_, count_);
break;
554 case Tag<T3>::kValue: values_.t3.Destroy(alloc_, count_);
break;
555 case Tag<T4>::kValue: values_.t4.Destroy(alloc_, count_);
break;
556 case Tag<T5>::kValue: values_.t5.Destroy(alloc_, count_);
break;
557 case Tag<T6>::kValue: values_.t6.Destroy(alloc_, count_);
break;
558 case Tag<T7>::kValue: values_.t7.Destroy(alloc_, count_);
break;
559 case Tag<T8>::kValue: values_.t8.Destroy(alloc_, count_);
break;
560 case Tag<T9>::kValue: values_.t9.Destroy(alloc_, count_);
break;
561 case Tag<T10>::kValue: values_.t10.Destroy(alloc_, count_);
break;
562 case Tag<T11>::kValue: values_.t11.Destroy(alloc_, count_);
break;
563 case Tag<T12>::kValue: values_.t12.Destroy(alloc_, count_);
break;
564 case Tag<T13>::kValue: values_.t13.Destroy(alloc_, count_);
break;
565 case Tag<T14>::kValue: values_.t14.Destroy(alloc_, count_);
break;
566 case Tag<T15>::kValue: values_.t15.Destroy(alloc_, count_);
break;
567 case Tag<T16>::kValue: values_.t16.Destroy(alloc_, count_);
break;
568 case Tag<T17>::kValue: values_.t17.Destroy(alloc_, count_);
break;
569 case Tag<T18>::kValue: values_.t18.Destroy(alloc_, count_);
break;
570 case Tag<T19>::kValue: values_.t19.Destroy(alloc_, count_);
break;
571 case Tag<T20>::kValue: values_.t20.Destroy(alloc_, count_);
break;
572 case Tag<T21>::kValue: values_.t21.Destroy(alloc_, count_);
break;
573 case Tag<T22>::kValue: values_.t22.Destroy(alloc_, count_);
break;
574 case Tag<T23>::kValue: values_.t23.Destroy(alloc_, count_);
break;
575 case Tag<T24>::kValue: values_.t24.Destroy(alloc_, count_);
break;
576 case Tag<T25>::kValue: values_.t25.Destroy(alloc_, count_);
break;
577 case Tag<T26>::kValue: values_.t26.Destroy(alloc_, count_);
break;
578 case Tag<T27>::kValue: values_.t27.Destroy(alloc_, count_);
break;
579 case Tag<T28>::kValue: values_.t28.Destroy(alloc_, count_);
break;
580 case Tag<T29>::kValue: values_.t29.Destroy(alloc_, count_);
break;
581 case Tag<T30>::kValue: values_.t30.Destroy(alloc_, count_);
break;
582 case Tag<T31>::kValue: values_.t31.Destroy(alloc_, count_);
break;
583 case Tag<T32>::kValue: values_.t32.Destroy(alloc_, count_);
break;
584 case Tag<T33>::kValue: values_.t33.Destroy(alloc_, count_);
break;
585 case Tag<T34>::kValue: values_.t34.Destroy(alloc_, count_);
break;
586 case Tag<T35>::kValue: values_.t35.Destroy(alloc_, count_);
break;
587 case Tag<T36>::kValue: values_.t36.Destroy(alloc_, count_);
break;
588 case Tag<T37>::kValue: values_.t37.Destroy(alloc_, count_);
break;
589 case Tag<T38>::kValue: values_.t38.Destroy(alloc_, count_);
break;
590 case Tag<T39>::kValue: values_.t39.Destroy(alloc_, count_);
break;
591 case Tag<T40>::kValue: values_.t40.Destroy(alloc_, count_);
break;
597 void MakeArray(
const T1*,
size_t count) { values_.t1.Init(alloc_, count); }
598 void MakeArray(
const T2*,
size_t count) { values_.t2.Init(alloc_, count); }
599 void MakeArray(
const T3*,
size_t count) { values_.t3.Init(alloc_, count); }
600 void MakeArray(
const T4*,
size_t count) { values_.t4.Init(alloc_, count); }
601 void MakeArray(
const T5*,
size_t count) { values_.t5.Init(alloc_, count); }
602 void MakeArray(
const T6*,
size_t count) { values_.t6.Init(alloc_, count); }
603 void MakeArray(
const T7*,
size_t count) { values_.t7.Init(alloc_, count); }
604 void MakeArray(
const T8*,
size_t count) { values_.t8.Init(alloc_, count); }
605 void MakeArray(
const T9*,
size_t count) { values_.t9.Init(alloc_, count); }
606 void MakeArray(
const T10*,
size_t count) { values_.t10.Init(alloc_, count); }
607 void MakeArray(
const T11*,
size_t count) { values_.t11.Init(alloc_, count); }
608 void MakeArray(
const T12*,
size_t count) { values_.t12.Init(alloc_, count); }
609 void MakeArray(
const T13*,
size_t count) { values_.t13.Init(alloc_, count); }
610 void MakeArray(
const T14*,
size_t count) { values_.t14.Init(alloc_, count); }
611 void MakeArray(
const T15*,
size_t count) { values_.t15.Init(alloc_, count); }
612 void MakeArray(
const T16*,
size_t count) { values_.t16.Init(alloc_, count); }
613 void MakeArray(
const T17*,
size_t count) { values_.t17.Init(alloc_, count); }
614 void MakeArray(
const T18*,
size_t count) { values_.t18.Init(alloc_, count); }
615 void MakeArray(
const T19*,
size_t count) { values_.t19.Init(alloc_, count); }
616 void MakeArray(
const T20*,
size_t count) { values_.t20.Init(alloc_, count); }
617 void MakeArray(
const T21*,
size_t count) { values_.t21.Init(alloc_, count); }
618 void MakeArray(
const T22*,
size_t count) { values_.t22.Init(alloc_, count); }
619 void MakeArray(
const T23*,
size_t count) { values_.t23.Init(alloc_, count); }
620 void MakeArray(
const T24*,
size_t count) { values_.t24.Init(alloc_, count); }
621 void MakeArray(
const T25*,
size_t count) { values_.t25.Init(alloc_, count); }
622 void MakeArray(
const T26*,
size_t count) { values_.t26.Init(alloc_, count); }
623 void MakeArray(
const T27*,
size_t count) { values_.t27.Init(alloc_, count); }
624 void MakeArray(
const T28*,
size_t count) { values_.t28.Init(alloc_, count); }
625 void MakeArray(
const T29*,
size_t count) { values_.t29.Init(alloc_, count); }
626 void MakeArray(
const T30*,
size_t count) { values_.t30.Init(alloc_, count); }
627 void MakeArray(
const T31*,
size_t count) { values_.t31.Init(alloc_, count); }
628 void MakeArray(
const T32*,
size_t count) { values_.t32.Init(alloc_, count); }
629 void MakeArray(
const T33*,
size_t count) { values_.t33.Init(alloc_, count); }
630 void MakeArray(
const T34*,
size_t count) { values_.t34.Init(alloc_, count); }
631 void MakeArray(
const T35*,
size_t count) { values_.t35.Init(alloc_, count); }
632 void MakeArray(
const T36*,
size_t count) { values_.t36.Init(alloc_, count); }
633 void MakeArray(
const T37*,
size_t count) { values_.t37.Init(alloc_, count); }
634 void MakeArray(
const T38*,
size_t count) { values_.t38.Init(alloc_, count); }
635 void MakeArray(
const T39*,
size_t count) { values_.t39.Init(alloc_, count); }
636 void MakeArray(
const T40*,
size_t count) { values_.t40.Init(alloc_, count); }
639 template <
typename T>
void SetValue(
640 const T&
value, internal_variant_utils::ManualConstructor<T>* target) {
642 "Empty type for Variant::Set");
645 tag_ = Tag<T>::kValue;
650 void CopyValueFrom(
const Variant& from) {
653 case Tag<T1>::kValue:
654 values_.t1.InitArray(alloc_, from.values_.t1, count_);
656 case Tag<T2>::kValue:
657 values_.t2.InitArray(alloc_, from.values_.t2, count_);
659 case Tag<T3>::kValue:
660 values_.t3.InitArray(alloc_, from.values_.t3, count_);
662 case Tag<T4>::kValue:
663 values_.t4.InitArray(alloc_, from.values_.t4, count_);
665 case Tag<T5>::kValue:
666 values_.t5.InitArray(alloc_, from.values_.t5, count_);
668 case Tag<T6>::kValue:
669 values_.t6.InitArray(alloc_, from.values_.t6, count_);
671 case Tag<T7>::kValue:
672 values_.t7.InitArray(alloc_, from.values_.t7, count_);
674 case Tag<T8>::kValue:
675 values_.t8.InitArray(alloc_, from.values_.t8, count_);
677 case Tag<T9>::kValue:
678 values_.t9.InitArray(alloc_, from.values_.t9, count_);
680 case Tag<T10>::kValue:
681 values_.t10.InitArray(alloc_, from.values_.t10, count_);
683 case Tag<T11>::kValue:
684 values_.t11.InitArray(alloc_, from.values_.t11, count_);
686 case Tag<T12>::kValue:
687 values_.t12.InitArray(alloc_, from.values_.t12, count_);
689 case Tag<T13>::kValue:
690 values_.t13.InitArray(alloc_, from.values_.t13, count_);
692 case Tag<T14>::kValue:
693 values_.t14.InitArray(alloc_, from.values_.t14, count_);
695 case Tag<T15>::kValue:
696 values_.t15.InitArray(alloc_, from.values_.t15, count_);
698 case Tag<T16>::kValue:
699 values_.t16.InitArray(alloc_, from.values_.t16, count_);
701 case Tag<T17>::kValue:
702 values_.t17.InitArray(alloc_, from.values_.t17, count_);
704 case Tag<T18>::kValue:
705 values_.t18.InitArray(alloc_, from.values_.t18, count_);
707 case Tag<T19>::kValue:
708 values_.t19.InitArray(alloc_, from.values_.t19, count_);
710 case Tag<T20>::kValue:
711 values_.t20.InitArray(alloc_, from.values_.t20, count_);
713 case Tag<T21>::kValue:
714 values_.t21.InitArray(alloc_, from.values_.t21, count_);
716 case Tag<T22>::kValue:
717 values_.t22.InitArray(alloc_, from.values_.t22, count_);
719 case Tag<T23>::kValue:
720 values_.t23.InitArray(alloc_, from.values_.t23, count_);
722 case Tag<T24>::kValue:
723 values_.t24.InitArray(alloc_, from.values_.t24, count_);
725 case Tag<T25>::kValue:
726 values_.t25.InitArray(alloc_, from.values_.t25, count_);
728 case Tag<T26>::kValue:
729 values_.t26.InitArray(alloc_, from.values_.t26, count_);
731 case Tag<T27>::kValue:
732 values_.t27.InitArray(alloc_, from.values_.t27, count_);
734 case Tag<T28>::kValue:
735 values_.t28.InitArray(alloc_, from.values_.t28, count_);
737 case Tag<T29>::kValue:
738 values_.t29.InitArray(alloc_, from.values_.t29, count_);
740 case Tag<T30>::kValue:
741 values_.t30.InitArray(alloc_, from.values_.t30, count_);
743 case Tag<T31>::kValue:
744 values_.t31.InitArray(alloc_, from.values_.t31, count_);
746 case Tag<T32>::kValue:
747 values_.t32.InitArray(alloc_, from.values_.t32, count_);
749 case Tag<T33>::kValue:
750 values_.t33.InitArray(alloc_, from.values_.t33, count_);
752 case Tag<T34>::kValue:
753 values_.t34.InitArray(alloc_, from.values_.t34, count_);
755 case Tag<T35>::kValue:
756 values_.t35.InitArray(alloc_, from.values_.t35, count_);
758 case Tag<T36>::kValue:
759 values_.t36.InitArray(alloc_, from.values_.t36, count_);
761 case Tag<T37>::kValue:
762 values_.t37.InitArray(alloc_, from.values_.t37, count_);
764 case Tag<T38>::kValue:
765 values_.t38.InitArray(alloc_, from.values_.t38, count_);
767 case Tag<T39>::kValue:
768 values_.t39.InitArray(alloc_, from.values_.t39, count_);
770 case Tag<T40>::kValue:
771 values_.t40.InitArray(alloc_, from.values_.t40, count_);
774 #if !defined(ION_COVERAGE) // COV_NF_START
775 DCHECK(
false) <<
"Invalid tag in array variant";
783 case Tag<T1>::kValue:
784 values_.t1.Init(*(from.values_.t1.Get()));
786 case Tag<T2>::kValue:
787 values_.t2.Init(*(from.values_.t2.Get()));
789 case Tag<T3>::kValue:
790 values_.t3.Init(*(from.values_.t3.Get()));
792 case Tag<T4>::kValue:
793 values_.t4.Init(*(from.values_.t4.Get()));
795 case Tag<T5>::kValue:
796 values_.t5.Init(*(from.values_.t5.Get()));
798 case Tag<T6>::kValue:
799 values_.t6.Init(*(from.values_.t6.Get()));
801 case Tag<T7>::kValue:
802 values_.t7.Init(*(from.values_.t7.Get()));
804 case Tag<T8>::kValue:
805 values_.t8.Init(*(from.values_.t8.Get()));
807 case Tag<T9>::kValue:
808 values_.t9.Init(*(from.values_.t9.Get()));
810 case Tag<T10>::kValue:
811 values_.t10.Init(*(from.values_.t10.Get()));
813 case Tag<T11>::kValue:
814 values_.t11.Init(*(from.values_.t11.Get()));
816 case Tag<T12>::kValue:
817 values_.t12.Init(*(from.values_.t12.Get()));
819 case Tag<T13>::kValue:
820 values_.t13.Init(*(from.values_.t13.Get()));
822 case Tag<T14>::kValue:
823 values_.t14.Init(*(from.values_.t14.Get()));
825 case Tag<T15>::kValue:
826 values_.t15.Init(*(from.values_.t15.Get()));
828 case Tag<T16>::kValue:
829 values_.t16.Init(*(from.values_.t16.Get()));
831 case Tag<T17>::kValue:
832 values_.t17.Init(*(from.values_.t17.Get()));
834 case Tag<T18>::kValue:
835 values_.t18.Init(*(from.values_.t18.Get()));
837 case Tag<T19>::kValue:
838 values_.t19.Init(*(from.values_.t19.Get()));
840 case Tag<T20>::kValue:
841 values_.t20.Init(*(from.values_.t20.Get()));
843 case Tag<T21>::kValue:
844 values_.t21.Init(*(from.values_.t21.Get()));
846 case Tag<T22>::kValue:
847 values_.t22.Init(*(from.values_.t22.Get()));
849 case Tag<T23>::kValue:
850 values_.t23.Init(*(from.values_.t23.Get()));
852 case Tag<T24>::kValue:
853 values_.t24.Init(*(from.values_.t24.Get()));
855 case Tag<T25>::kValue:
856 values_.t25.Init(*(from.values_.t25.Get()));
858 case Tag<T26>::kValue:
859 values_.t26.Init(*(from.values_.t26.Get()));
861 case Tag<T27>::kValue:
862 values_.t27.Init(*(from.values_.t27.Get()));
864 case Tag<T28>::kValue:
865 values_.t28.Init(*(from.values_.t28.Get()));
867 case Tag<T29>::kValue:
868 values_.t29.Init(*(from.values_.t29.Get()));
870 case Tag<T30>::kValue:
871 values_.t30.Init(*(from.values_.t30.Get()));
873 case Tag<T31>::kValue:
874 values_.t31.Init(*(from.values_.t31.Get()));
876 case Tag<T32>::kValue:
877 values_.t32.Init(*(from.values_.t32.Get()));
879 case Tag<T33>::kValue:
880 values_.t33.Init(*(from.values_.t33.Get()));
882 case Tag<T34>::kValue:
883 values_.t34.Init(*(from.values_.t34.Get()));
885 case Tag<T35>::kValue:
886 values_.t35.Init(*(from.values_.t35.Get()));
888 case Tag<T36>::kValue:
889 values_.t36.Init(*(from.values_.t36.Get()));
891 case Tag<T37>::kValue:
892 values_.t37.Init(*(from.values_.t37.Get()));
894 case Tag<T38>::kValue:
895 values_.t38.Init(*(from.values_.t38.Get()));
897 case Tag<T39>::kValue:
898 values_.t39.Init(*(from.values_.t39.Get()));
900 case Tag<T40>::kValue:
901 values_.t40.Init(*(from.values_.t40.Get()));
911 const T1& GetValue(
const T1*)
const {
return *values_.t1.Get(); }
912 const T2& GetValue(
const T2*)
const {
return *values_.t2.Get(); }
913 const T3& GetValue(
const T3*)
const {
return *values_.t3.Get(); }
914 const T4& GetValue(
const T4*)
const {
return *values_.t4.Get(); }
915 const T5& GetValue(
const T5*)
const {
return *values_.t5.Get(); }
916 const T6& GetValue(
const T6*)
const {
return *values_.t6.Get(); }
917 const T7& GetValue(
const T7*)
const {
return *values_.t7.Get(); }
918 const T8& GetValue(
const T8*)
const {
return *values_.t8.Get(); }
919 const T9& GetValue(
const T9*)
const {
return *values_.t9.Get(); }
920 const T10& GetValue(
const T10*)
const {
return *values_.t10.Get(); }
921 const T11& GetValue(
const T11*)
const {
return *values_.t11.Get(); }
922 const T12& GetValue(
const T12*)
const {
return *values_.t12.Get(); }
923 const T13& GetValue(
const T13*)
const {
return *values_.t13.Get(); }
924 const T14& GetValue(
const T14*)
const {
return *values_.t14.Get(); }
925 const T15& GetValue(
const T15*)
const {
return *values_.t15.Get(); }
926 const T16& GetValue(
const T16*)
const {
return *values_.t16.Get(); }
927 const T17& GetValue(
const T17*)
const {
return *values_.t17.Get(); }
928 const T18& GetValue(
const T18*)
const {
return *values_.t18.Get(); }
929 const T19& GetValue(
const T19*)
const {
return *values_.t19.Get(); }
930 const T20& GetValue(
const T20*)
const {
return *values_.t20.Get(); }
931 const T21& GetValue(
const T21*)
const {
return *values_.t21.Get(); }
932 const T22& GetValue(
const T22*)
const {
return *values_.t22.Get(); }
933 const T23& GetValue(
const T23*)
const {
return *values_.t23.Get(); }
934 const T24& GetValue(
const T24*)
const {
return *values_.t24.Get(); }
935 const T25& GetValue(
const T25*)
const {
return *values_.t25.Get(); }
936 const T26& GetValue(
const T26*)
const {
return *values_.t26.Get(); }
937 const T27& GetValue(
const T27*)
const {
return *values_.t27.Get(); }
938 const T28& GetValue(
const T28*)
const {
return *values_.t28.Get(); }
939 const T29& GetValue(
const T29*)
const {
return *values_.t29.Get(); }
940 const T30& GetValue(
const T30*)
const {
return *values_.t30.Get(); }
941 const T31& GetValue(
const T31*)
const {
return *values_.t31.Get(); }
942 const T32& GetValue(
const T32*)
const {
return *values_.t32.Get(); }
943 const T33& GetValue(
const T33*)
const {
return *values_.t33.Get(); }
944 const T34& GetValue(
const T34*)
const {
return *values_.t34.Get(); }
945 const T35& GetValue(
const T35*)
const {
return *values_.t35.Get(); }
946 const T36& GetValue(
const T36*)
const {
return *values_.t36.Get(); }
947 const T37& GetValue(
const T37*)
const {
return *values_.t37.Get(); }
948 const T38& GetValue(
const T38*)
const {
return *values_.t38.Get(); }
949 const T39& GetValue(
const T39*)
const {
return *values_.t39.Get(); }
950 const T40& GetValue(
const T40*)
const {
return *values_.t40.Get(); }
954 const T1& GetAt(
const T1*,
size_t i)
const {
return values_.t1.GetAt(i); }
955 const T2& GetAt(
const T2*,
size_t i)
const {
return values_.t2.GetAt(i); }
956 const T3& GetAt(
const T3*,
size_t i)
const {
return values_.t3.GetAt(i); }
957 const T4& GetAt(
const T4*,
size_t i)
const {
return values_.t4.GetAt(i); }
958 const T5& GetAt(
const T5*,
size_t i)
const {
return values_.t5.GetAt(i); }
959 const T6& GetAt(
const T6*,
size_t i)
const {
return values_.t6.GetAt(i); }
960 const T7& GetAt(
const T7*,
size_t i)
const {
return values_.t7.GetAt(i); }
961 const T8& GetAt(
const T8*,
size_t i)
const {
return values_.t8.GetAt(i); }
962 const T9& GetAt(
const T9*,
size_t i)
const {
return values_.t9.GetAt(i); }
963 const T10& GetAt(
const T10*,
size_t i)
const {
return values_.t10.GetAt(i); }
964 const T11& GetAt(
const T11*,
size_t i)
const {
return values_.t11.GetAt(i); }
965 const T12& GetAt(
const T12*,
size_t i)
const {
return values_.t12.GetAt(i); }
966 const T13& GetAt(
const T13*,
size_t i)
const {
return values_.t13.GetAt(i); }
967 const T14& GetAt(
const T14*,
size_t i)
const {
return values_.t14.GetAt(i); }
968 const T15& GetAt(
const T15*,
size_t i)
const {
return values_.t15.GetAt(i); }
969 const T16& GetAt(
const T16*,
size_t i)
const {
return values_.t16.GetAt(i); }
970 const T17& GetAt(
const T17*,
size_t i)
const {
return values_.t17.GetAt(i); }
971 const T18& GetAt(
const T18*,
size_t i)
const {
return values_.t18.GetAt(i); }
972 const T19& GetAt(
const T19*,
size_t i)
const {
return values_.t19.GetAt(i); }
973 const T20& GetAt(
const T20*,
size_t i)
const {
return values_.t20.GetAt(i); }
974 const T21& GetAt(
const T21*,
size_t i)
const {
return values_.t21.GetAt(i); }
975 const T22& GetAt(
const T22*,
size_t i)
const {
return values_.t22.GetAt(i); }
976 const T23& GetAt(
const T23*,
size_t i)
const {
return values_.t23.GetAt(i); }
977 const T24& GetAt(
const T24*,
size_t i)
const {
return values_.t24.GetAt(i); }
978 const T25& GetAt(
const T25*,
size_t i)
const {
return values_.t25.GetAt(i); }
979 const T26& GetAt(
const T26*,
size_t i)
const {
return values_.t26.GetAt(i); }
980 const T27& GetAt(
const T27*,
size_t i)
const {
return values_.t27.GetAt(i); }
981 const T28& GetAt(
const T28*,
size_t i)
const {
return values_.t28.GetAt(i); }
982 const T29& GetAt(
const T29*,
size_t i)
const {
return values_.t29.GetAt(i); }
983 const T30& GetAt(
const T30*,
size_t i)
const {
return values_.t30.GetAt(i); }
984 const T31& GetAt(
const T31*,
size_t i)
const {
return values_.t31.GetAt(i); }
985 const T32& GetAt(
const T32*,
size_t i)
const {
return values_.t32.GetAt(i); }
986 const T33& GetAt(
const T33*,
size_t i)
const {
return values_.t33.GetAt(i); }
987 const T34& GetAt(
const T34*,
size_t i)
const {
return values_.t34.GetAt(i); }
988 const T35& GetAt(
const T35*,
size_t i)
const {
return values_.t35.GetAt(i); }
989 const T36& GetAt(
const T36*,
size_t i)
const {
return values_.t36.GetAt(i); }
990 const T37& GetAt(
const T37*,
size_t i)
const {
return values_.t37.GetAt(i); }
991 const T38& GetAt(
const T38*,
size_t i)
const {
return values_.t38.GetAt(i); }
992 const T39& GetAt(
const T39*,
size_t i)
const {
return values_.t39.GetAt(i); }
993 const T40& GetAt(
const T40*,
size_t i)
const {
return values_.t40.GetAt(i); }
997 void SetAt(
size_t i,
const T1& v) { values_.t1.SetAt(i, v); }
998 void SetAt(
size_t i,
const T2& v) { values_.t2.SetAt(i, v); }
999 void SetAt(
size_t i,
const T3& v) { values_.t3.SetAt(i, v); }
1000 void SetAt(
size_t i,
const T4& v) { values_.t4.SetAt(i, v); }
1001 void SetAt(
size_t i,
const T5& v) { values_.t5.SetAt(i, v); }
1002 void SetAt(
size_t i,
const T6& v) { values_.t6.SetAt(i, v); }
1003 void SetAt(
size_t i,
const T7& v) { values_.t7.SetAt(i, v); }
1004 void SetAt(
size_t i,
const T8& v) { values_.t8.SetAt(i, v); }
1005 void SetAt(
size_t i,
const T9& v) { values_.t9.SetAt(i, v); }
1006 void SetAt(
size_t i,
const T10& v) { values_.t10.SetAt(i, v); }
1007 void SetAt(
size_t i,
const T11& v) { values_.t11.SetAt(i, v); }
1008 void SetAt(
size_t i,
const T12& v) { values_.t12.SetAt(i, v); }
1009 void SetAt(
size_t i,
const T13& v) { values_.t13.SetAt(i, v); }
1010 void SetAt(
size_t i,
const T14& v) { values_.t14.SetAt(i, v); }
1011 void SetAt(
size_t i,
const T15& v) { values_.t15.SetAt(i, v); }
1012 void SetAt(
size_t i,
const T16& v) { values_.t16.SetAt(i, v); }
1013 void SetAt(
size_t i,
const T17& v) { values_.t17.SetAt(i, v); }
1014 void SetAt(
size_t i,
const T18& v) { values_.t18.SetAt(i, v); }
1015 void SetAt(
size_t i,
const T19& v) { values_.t19.SetAt(i, v); }
1016 void SetAt(
size_t i,
const T20& v) { values_.t20.SetAt(i, v); }
1017 void SetAt(
size_t i,
const T21& v) { values_.t21.SetAt(i, v); }
1018 void SetAt(
size_t i,
const T22& v) { values_.t22.SetAt(i, v); }
1019 void SetAt(
size_t i,
const T23& v) { values_.t23.SetAt(i, v); }
1020 void SetAt(
size_t i,
const T24& v) { values_.t24.SetAt(i, v); }
1021 void SetAt(
size_t i,
const T25& v) { values_.t25.SetAt(i, v); }
1022 void SetAt(
size_t i,
const T26& v) { values_.t26.SetAt(i, v); }
1023 void SetAt(
size_t i,
const T27& v) { values_.t27.SetAt(i, v); }
1024 void SetAt(
size_t i,
const T28& v) { values_.t28.SetAt(i, v); }
1025 void SetAt(
size_t i,
const T29& v) { values_.t29.SetAt(i, v); }
1026 void SetAt(
size_t i,
const T30& v) { values_.t30.SetAt(i, v); }
1027 void SetAt(
size_t i,
const T31& v) { values_.t31.SetAt(i, v); }
1028 void SetAt(
size_t i,
const T32& v) { values_.t32.SetAt(i, v); }
1029 void SetAt(
size_t i,
const T33& v) { values_.t33.SetAt(i, v); }
1030 void SetAt(
size_t i,
const T34& v) { values_.t34.SetAt(i, v); }
1031 void SetAt(
size_t i,
const T35& v) { values_.t35.SetAt(i, v); }
1032 void SetAt(
size_t i,
const T36& v) { values_.t36.SetAt(i, v); }
1033 void SetAt(
size_t i,
const T37& v) { values_.t37.SetAt(i, v); }
1034 void SetAt(
size_t i,
const T38& v) { values_.t38.SetAt(i, v); }
1035 void SetAt(
size_t i,
const T39& v) { values_.t39.SetAt(i, v); }
1036 void SetAt(
size_t i,
const T40& v) { values_.t40.SetAt(i, v); }
1094 #endif // ION_BASE_VARIANT_H_
Simplification of util/gtl/manual_constructor.h.
void Set(const T35 &value)
const T & Get() const
If this contains an object of type T (which must be one of the defined types), this returns a const r...
void Set(const T19 &value)
void Set(const T23 &value)
void Set(const T40 &value)
internal_variant_utils::ManualConstructor< T33 > t33
void Set(const T22 &value)
void Set(const T9 &value)
void SetAt(size_t i, const Type &value)
internal_variant_utils::ManualConstructor< T39 > t39
bool ElementsAssignableTo() const
Similar to above but only returns true if the elements of the array that this contains are assignable...
void Set(const T34 &value)
void Set(const T26 &value)
void Set(const T10 &value)
void Set(const T25 &value)
void Set(const T20 &value)
internal_variant_utils::ManualConstructor< T35 > t35
ArrayAccessor(Variant *v, size_t i)
void Set(const T13 &value)
internal_variant_utils::ManualConstructor< T13 > t13
internal_variant_utils::ManualConstructor< T26 > t26
void Set(const T8 &value)
internal_variant_utils::ManualConstructor< T8 > t8
void Set(const T17 &value)
void Set(const T15 &value)
void Set(const T14 &value)
internal_variant_utils::ManualConstructor< T40 > t40
void Set(const T3 &value)
void Set(const T21 &value)
internal_variant_utils::ManualConstructor< T24 > t24
Variant(const Variant &from)
Copy constructor and assignment operator.
internal_variant_utils::ManualConstructor< T22 > t22
void Set(const T28 &value)
SharedPtr< Allocator > AllocatorPtr
void Set(const T16 &value)
void Init(const base::AllocatorPtr &allocator, size_t count)
internal_variant_utils::ManualConstructor< T31 > t31
bool Is() const
Returns true if this contains an object of type T, which must be an exact match with one of the templ...
internal_variant_utils::ManualConstructor< T23 > t23
internal_variant_utils::ManualConstructor< T5 > t5
bool operator==(const T &value) const
void Set(const T36 &value)
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
const Type & GetAt(size_t i) const
ArrayAccessor operator[](size_t i)
Returns an ArrayAccessor object that facilitates the getting of the actual array element from this...
internal_variant_utils::ManualConstructor< T9 > t9
internal_variant_utils::ManualConstructor< T6 > t6
void Set(const T24 &value)
internal_variant_utils::ManualConstructor< T2 > t2
const T & GetValueAt(size_t i) const
If this contains an array of objects of type T (which must be one of the defined types), this returns a const reference to it if the index is valid.
internal_variant_utils::ManualConstructor< T20 > t20
internal_variant_utils::ManualConstructor< T11 > t11
static const AllocatorPtr & GetNonNullAllocator(const AllocatorPtr &allocator)
This convenience function can be used where a non-NULL Allocator pointer is needed.
void Destroy(const base::AllocatorPtr &allocator, size_t count)
void InitArray(const base::AllocatorPtr &allocator, const ManualConstructor &other, size_t count)
internal_variant_utils::ManualConstructor< T18 > t18
internal_variant_utils::ManualConstructor< T25 > t25
void Set(const T29 &value)
internal_variant_utils::ManualConstructor< T3 > t3
void Set(const T18 &value)
void Set(const T6 &value)
void Set(const T1 &value)
Each version of Set() sets the variant to contain a value of one of the defined types or to a type th...
internal_variant_utils::ManualConstructor< T14 > t14
void Set(const T4 &value)
internal_variant_utils::ManualConstructor< T36 > t36
The Variant class is similar to boost::variant.
void Set(const T33 &value)
bool IsArrayOf() const
Returns true if this contains an array of type T, which must be an exact match with one of the templa...
internal_variant_utils::ManualConstructor< T10 > t10
internal_variant_utils::ManualConstructor< T27 > t27
size_t GetCount() const
Returns the number of array elements this contains, which is 0 when this holds only a scalar value...
void Set(const T38 &value)
internal_variant_utils::ManualConstructor< T12 > t12
void Set(const T39 &value)
void Set(const T31 &value)
internal_variant_utils::ManualConstructor< T32 > t32
void Set(const T12 &value)
T1 Type1
Expose the defined types as typedefs.
internal_variant_utils::ManualConstructor< T30 > t30
internal_variant_utils::ManualConstructor< T1 > t1
Use ManualConstructor<> so that we can explicitly control the construction/destruction.
internal_variant_utils::ManualConstructor< T4 > t4
void Set(const T5 &value)
void CopyFrom(const Variant &from)
Copies the variant's type and value from another instance.
Copyright 2016 Google Inc.
void DeallocateMemory(void *p)
Deallocates a previously-allocated memory block.
void Set(const T32 &value)
const AllocatorPtr & GetArrayAllocator() const
Returns the allocator used to make array allocations.
void InitArray(const base::AllocatorPtr &allocator, size_t count)
Sets the type of this variant to be an array of count Ts.
void Set(const T27 &value)
internal_variant_utils::ManualConstructor< T37 > t37
void Reset(T *new_shared)
Changes the pointer to point to the given shared, which may be NULL.
internal_variant_utils::ManualConstructor< T16 > t16
void Set(const T2 &value)
void * AllocateMemory(size_t size)
Allocates memory of the given size.
void Set(const T7 &value)
void Set(const T37 &value)
ArrayAccessor lets callers use operator[] with a Variant in most simple cases, as opposed to using th...
void Set(const T30 &value)
Variant & operator=(const Variant &from)
#define ION_STATIC_ASSERT(expr, message)
Copyright 2016 Google Inc.
internal_variant_utils::ManualConstructor< T38 > t38
void SetValueAt(size_t i, const T &value)
Sets the ith element of the array to the passed value.
Variant()
The default constructor defines a Variant with an invalid tag and leaves the Variant value in an unde...
internal_variant_utils::ManualConstructor< T21 > t21
bool IsAssignableTo() const
Returns true if this contains an object of type T or an object which a T can be assigned to...
internal_variant_utils::ManualConstructor< T29 > t29
internal_variant_utils::ManualConstructor< T34 > t34
void Set(const T11 &value)
Taken from util/gtl/emptytype.h.
internal_variant_utils::ManualConstructor< T28 > t28
internal_variant_utils::ManualConstructor< T15 > t15
internal_variant_utils::ManualConstructor< T7 > t7
void operator=(const T &value)
internal_variant_utils::ManualConstructor< T19 > t19
internal_variant_utils::ManualConstructor< T17 > t17