+class _EnumerationFieldClass(_EnumerationFieldClassConst, _IntegerFieldClass):
+ def add_mapping(self, label, ranges):
+ utils._check_str(label)
+ utils._check_type(ranges, self._range_set_type)
+
+ if label in self:
+ raise ValueError("duplicate mapping label '{}'".format(label))
+
+ status = self._add_mapping(self._ptr, label, ranges._ptr)
+ utils._handle_func_status(
+ status, 'cannot add mapping to enumeration field class object'
+ )
+
+ def __iadd__(self, mappings):
+ for label, ranges in mappings:
+ self.add_mapping(label, ranges)
+
+ return self
+
+
+class _UnsignedEnumerationFieldClassConst(
+ _EnumerationFieldClassConst, _UnsignedIntegerFieldClassConst
+):
+ _NAME = 'Const nsigned enumeration'
+ _range_set_type = bt2_integer_range_set.UnsignedIntegerRangeSet
+ _borrow_mapping_ptr_by_label = staticmethod(
+ native_bt.field_class_enumeration_unsigned_borrow_mapping_by_label_const
+ )
+ _borrow_mapping_ptr_by_index = staticmethod(
+ native_bt.field_class_enumeration_unsigned_borrow_mapping_by_index_const
+ )
+ _mapping_pycls = property(lambda _: _UnsignedEnumerationFieldClassMappingConst)
+ _get_mapping_labels_for_value = staticmethod(
+ native_bt.field_class_enumeration_unsigned_get_mapping_labels_for_value
+ )
+ _check_int_type = staticmethod(utils._check_uint64)
+
+
+class _UnsignedEnumerationFieldClass(
+ _UnsignedEnumerationFieldClassConst,
+ _EnumerationFieldClass,
+ _UnsignedIntegerFieldClass,
+):
+ _NAME = 'Unsigned enumeration'
+ _add_mapping = staticmethod(native_bt.field_class_enumeration_unsigned_add_mapping)
+
+
+class _SignedEnumerationFieldClassConst(
+ _EnumerationFieldClassConst, _SignedIntegerFieldClassConst
+):
+ _NAME = 'Const signed enumeration'
+ _range_set_type = bt2_integer_range_set.SignedIntegerRangeSet
+ _borrow_mapping_ptr_by_label = staticmethod(
+ native_bt.field_class_enumeration_signed_borrow_mapping_by_label_const
+ )
+ _borrow_mapping_ptr_by_index = staticmethod(
+ native_bt.field_class_enumeration_signed_borrow_mapping_by_index_const
+ )
+ _mapping_pycls = property(lambda _: _SignedEnumerationFieldClassMappingConst)
+ _get_mapping_labels_for_value = staticmethod(
+ native_bt.field_class_enumeration_signed_get_mapping_labels_for_value
+ )
+ _check_int_type = staticmethod(utils._check_int64)
+
+
+class _SignedEnumerationFieldClass(
+ _SignedEnumerationFieldClassConst, _EnumerationFieldClass, _SignedIntegerFieldClass
+):
+ _NAME = 'Signed enumeration'
+ _add_mapping = staticmethod(native_bt.field_class_enumeration_signed_add_mapping)
+
+
+class _StringFieldClassConst(_FieldClassConst):
+ _NAME = 'Const string'
+
+
+class _StringFieldClass(_StringFieldClassConst, _FieldClass):
+ _NAME = 'String'
+
+
+class _StructureFieldClassMemberConst:
+ _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_structure_member_borrow_field_class_const
+ )
+ _borrow_user_attributes_ptr = staticmethod(
+ native_bt.field_class_structure_member_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_struct_fc, member_ptr):
+ # this field class owns the member; keeping it here maintains
+ # the member alive as members are not shared objects
+ self._owning_struct_fc = owning_struct_fc
+ self._ptr = member_ptr
+
+ @property
+ def name(self):
+ name = native_bt.field_class_structure_member_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 _StructureFieldClassMember(_StructureFieldClassMemberConst):
+ _borrow_field_class_ptr = staticmethod(
+ native_bt.field_class_structure_member_borrow_field_class
+ )
+ _borrow_user_attributes_ptr = staticmethod(
+ native_bt.field_class_structure_member_borrow_user_attributes
+ )
+ _create_field_class_from_ptr_and_get_ref = staticmethod(
+ _create_field_class_from_ptr_and_get_ref
+ )
+ _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_structure_member_set_user_attributes(
+ self._ptr, value._ptr
+ )
+
+ _user_attributes = property(fset=_user_attributes)
+
+
+class _StructureFieldClassConst(_FieldClassConst, collections.abc.Mapping):
+ _NAME = 'Const structure'
+ _borrow_member_ptr_by_index = staticmethod(
+ native_bt.field_class_structure_borrow_member_by_index_const
+ )
+ _borrow_member_ptr_by_name = staticmethod(
+ native_bt.field_class_structure_borrow_member_by_name_const
+ )
+ _structure_member_field_class_pycls = property(
+ lambda _: _StructureFieldClassMemberConst
+ )