+
+class _OptionFieldClassConst(_FieldClassConst):
+ _NAME = 'Const Option'
+ _create_field_class_from_ptr_and_get_ref = staticmethod(
+ _create_field_class_from_const_ptr_and_get_ref
+ )
+ _borrow_field_class_ptr = staticmethod(
+ native_bt.field_class_option_borrow_field_class_const
+ )
+
+ @property
+ def field_class(self):
+ elem_fc_ptr = self._borrow_field_class_ptr(self._ptr)
+ return self._create_field_class_from_ptr_and_get_ref(elem_fc_ptr)
+
+
+class _OptionWithSelectorFieldClassConst(_OptionFieldClassConst):
+ _NAME = 'Const Option (with selector)'
+
+ @property
+ def selector_field_path(self):
+ ptr = native_bt.field_class_option_with_selector_borrow_selector_field_path_const(
+ self._ptr
+ )
+ if ptr is None:
+ return
+
+ return bt2_field_path._FieldPathConst._create_from_ptr_and_get_ref(ptr)
+
+
+class _OptionWithBoolSelectorFieldClassConst(_OptionWithSelectorFieldClassConst):
+ _NAME = 'Const Option (with boolean selector)'
+
+ @property
+ def selector_is_reversed(self):
+ return bool(
+ native_bt.field_class_option_with_selector_bool_selector_is_reversed(
+ self._ptr
+ )
+ )
+
+
+class _OptionWithIntegerSelectorFieldClassConst(_OptionWithSelectorFieldClassConst):
+ _NAME = 'Const Option (with integer selector)'
+
+ @property
+ def ranges(self):
+ range_set_ptr = self._borrow_selector_ranges_ptr(self._ptr)
+ assert range_set_ptr is not None
+ return self._range_set_pycls._create_from_ptr_and_get_ref(range_set_ptr)
+
+
+class _OptionWithUnsignedIntegerSelectorFieldClassConst(
+ _OptionWithIntegerSelectorFieldClassConst
+):
+ _NAME = 'Const Option (with unsigned integer selector)'
+ _range_set_pycls = bt2_integer_range_set._UnsignedIntegerRangeSetConst
+ _borrow_selector_ranges_ptr = staticmethod(
+ native_bt.field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const
+ )
+
+
+class _OptionWithSignedIntegerSelectorFieldClassConst(
+ _OptionWithIntegerSelectorFieldClassConst
+):
+ _NAME = 'Const Option (with signed integer selector)'
+ _range_set_pycls = bt2_integer_range_set._SignedIntegerRangeSetConst
+ _borrow_selector_ranges_ptr = staticmethod(
+ native_bt.field_class_option_with_selector_integer_signed_borrow_selector_ranges_const
+ )
+
+
+class _OptionFieldClass(_OptionFieldClassConst, _FieldClass):
+ _NAME = 'Option'
+ _borrow_field_class_ptr = staticmethod(
+ native_bt.field_class_option_borrow_field_class
+ )
+ _create_field_class_from_ptr_and_get_ref = staticmethod(
+ _create_field_class_from_ptr_and_get_ref
+ )
+
+
+class _OptionWithSelectorFieldClass(
+ _OptionWithSelectorFieldClassConst, _OptionFieldClass
+):
+ _NAME = 'Option (with selector)'
+
+
+class _OptionWithBoolSelectorFieldClass(
+ _OptionWithBoolSelectorFieldClassConst, _OptionWithSelectorFieldClass
+):
+ _NAME = 'Option (with boolean selector)'
+
+ def _selector_is_reversed(self, selector_is_reversed):
+ utils._check_bool(selector_is_reversed)
+ native_bt.field_class_option_with_selector_bool_set_selector_is_reversed(
+ self._ptr, selector_is_reversed
+ )
+
+ _selector_is_reversed = property(fset=_selector_is_reversed)
+
+
+class _OptionWithIntegerSelectorFieldClass(
+ _OptionWithIntegerSelectorFieldClassConst, _OptionWithSelectorFieldClass
+):
+ _NAME = 'Option (with integer selector)'
+
+
+class _OptionWithUnsignedIntegerSelectorFieldClass(
+ _OptionWithUnsignedIntegerSelectorFieldClassConst,
+ _OptionWithIntegerSelectorFieldClass,
+):
+ _NAME = 'Option (with unsigned integer selector)'
+
+
+class _OptionWithSignedIntegerSelectorFieldClass(
+ _OptionWithSignedIntegerSelectorFieldClassConst,
+ _OptionWithIntegerSelectorFieldClass,
+):
+ _NAME = 'Option (with signed integer selector)'
+
+
+class _VariantFieldClassOptionConst:
+ _create_field_class_from_ptr_and_get_ref = staticmethod(
+ _create_field_class_from_const_ptr_and_get_ref
+ )
+ _borrow_field_class_ptr = staticmethod(
+ native_bt.field_class_variant_option_borrow_field_class_const
+ )
+ _borrow_user_attributes_ptr = staticmethod(
+ native_bt.field_class_variant_option_borrow_user_attributes_const
+ )
+ _create_value_from_ptr_and_get_ref = staticmethod(
+ bt2_value._create_from_const_ptr_and_get_ref
+ )
+
+ def __init__(self, owning_var_fc, option_ptr):
+ # this field class owns the option; keeping it here maintains
+ # the option alive as options are not shared objects
+ self._owning_var_fc = owning_var_fc
+ self._ptr = option_ptr
+
+ @property
+ def name(self):
+ name = native_bt.field_class_variant_option_get_name(self._ptr)
+ assert name is not None
+ return name
+
+ @property
+ def field_class(self):
+ fc_ptr = self._borrow_field_class_ptr(self._ptr)
+ assert fc_ptr is not None
+ return self._create_field_class_from_ptr_and_get_ref(fc_ptr)
+
+ @property
+ def user_attributes(self):
+ ptr = self._borrow_user_attributes_ptr(self._ptr)
+ assert ptr is not None
+ return self._create_value_from_ptr_and_get_ref(ptr)
+
+
+class _VariantFieldClassOption(_VariantFieldClassOptionConst):
+ _create_field_class_from_ptr_and_get_ref = staticmethod(
+ _create_field_class_from_ptr_and_get_ref
+ )
+ _borrow_field_class_ptr = staticmethod(
+ native_bt.field_class_variant_option_borrow_field_class
+ )
+ _borrow_user_attributes_ptr = staticmethod(
+ native_bt.field_class_variant_option_borrow_user_attributes
+ )
+ _create_value_from_ptr_and_get_ref = staticmethod(
+ bt2_value._create_from_ptr_and_get_ref
+ )
+
+ def _user_attributes(self, user_attributes):
+ value = bt2_value.create_value(user_attributes)
+ utils._check_type(value, bt2_value.MapValue)
+ native_bt.field_class_variant_option_set_user_attributes(self._ptr, value._ptr)
+
+ _user_attributes = property(fset=_user_attributes)
+
+
+class _VariantFieldClassWithIntegerSelectorOptionConst(_VariantFieldClassOptionConst):
+ def __init__(self, owning_var_fc, spec_opt_ptr):
+ self._spec_ptr = spec_opt_ptr
+ super().__init__(owning_var_fc, self._as_option_ptr(spec_opt_ptr))
+
+ @property
+ def ranges(self):
+ range_set_ptr = self._borrow_ranges_ptr(self._spec_ptr)
+ assert range_set_ptr is not None
+ return self._range_set_pycls._create_from_ptr_and_get_ref(range_set_ptr)
+
+
+class _VariantFieldClassWithIntegerSelectorOption(
+ _VariantFieldClassWithIntegerSelectorOptionConst, _VariantFieldClassOption
+):
+ pass
+
+
+class _VariantFieldClassWithSignedIntegerSelectorOptionConst(
+ _VariantFieldClassWithIntegerSelectorOptionConst
+):
+ _as_option_ptr = staticmethod(
+ native_bt.field_class_variant_with_selector_integer_signed_option_as_option_const
+ )
+ _borrow_ranges_ptr = staticmethod(
+ native_bt.field_class_variant_with_selector_integer_signed_option_borrow_ranges_const
+ )
+ _range_set_pycls = bt2_integer_range_set._SignedIntegerRangeSetConst
+
+
+class _VariantFieldClassWithSignedIntegerSelectorOption(
+ _VariantFieldClassWithSignedIntegerSelectorOptionConst,
+ _VariantFieldClassWithIntegerSelectorOption,
+):
+ pass
+
+
+class _VariantFieldClassWithUnsignedIntegerSelectorOptionConst(
+ _VariantFieldClassWithIntegerSelectorOptionConst
+):
+ _as_option_ptr = staticmethod(
+ native_bt.field_class_variant_with_selector_integer_unsigned_option_as_option_const
+ )
+ _borrow_ranges_ptr = staticmethod(
+ native_bt.field_class_variant_with_selector_integer_unsigned_option_borrow_ranges_const
+ )
+ _range_set_pycls = bt2_integer_range_set._UnsignedIntegerRangeSetConst
+
+
+class _VariantFieldClassWithUnsignedIntegerSelectorOption(
+ _VariantFieldClassWithUnsignedIntegerSelectorOptionConst,
+ _VariantFieldClassWithIntegerSelectorOption,
+):
+ pass
+
+
+class _VariantFieldClassConst(_FieldClassConst, collections.abc.Mapping):
+ _NAME = 'Const Variant'
+ _borrow_option_ptr_by_name = staticmethod(
+ native_bt.field_class_variant_borrow_option_by_name_const
+ )
+ _borrow_option_ptr_by_index = staticmethod(
+ native_bt.field_class_variant_borrow_option_by_index_const
+ )
+ _variant_option_pycls = _VariantFieldClassOptionConst
+
+ @staticmethod
+ def _as_option_ptr(opt_ptr):
+ return opt_ptr
+
+ def _create_option_from_ptr(self, opt_ptr):
+ return self._variant_option_pycls(self, opt_ptr)
+
+ def __len__(self):
+ count = native_bt.field_class_variant_get_option_count(self._ptr)
+ assert count >= 0
+ return count
+
+ def __getitem__(self, key):
+ if not isinstance(key, str):
+ raise TypeError(
+ "key must be a 'str' object, got '{}'".format(key.__class__.__name__)
+ )
+
+ opt_ptr = self._borrow_option_ptr_by_name(self._ptr, key)
+
+ if opt_ptr is None:
+ raise KeyError(key)
+
+ return self._create_option_from_ptr(opt_ptr)
+
+ def __iter__(self):
+ for idx in range(len(self)):
+ opt_ptr = self._borrow_option_ptr_by_index(self._ptr, idx)
+ assert opt_ptr is not None
+ base_opt_ptr = self._as_option_ptr(opt_ptr)
+ yield native_bt.field_class_variant_option_get_name(base_opt_ptr)
+
+ def option_at_index(self, index):