from bt2 import native_bt, object, utils
import collections.abc
-import bt2.field
-import bt2.field_path
-import bt2.integer_range_set
+from bt2 import field_path as bt2_field_path
+from bt2 import integer_range_set as bt2_integer_range_set
import bt2
def _check_create_status(self, ptr):
if ptr is None:
- raise bt2.CreationError(
+ raise bt2._MemoryError(
'cannot create {} field class object'.format(self._NAME.lower())
)
+class _BoolFieldClass(_FieldClass):
+ _NAME = 'Boolean'
+
+
+class _BitArrayFieldClass(_FieldClass):
+ _NAME = 'Bit array'
+
+ @property
+ def length(self):
+ length = native_bt.field_class_bit_array_get_length(self._ptr)
+ assert length >= 1
+ return length
+
+
class _IntegerFieldClass(_FieldClass):
@property
def field_value_range(self):
class _UnsignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping):
- _ranges_type = bt2.integer_range_set.UnsignedIntegerRangeSet
+ _ranges_type = bt2_integer_range_set.UnsignedIntegerRangeSet
_as_enumeration_field_class_mapping_ptr = staticmethod(
- native_bt.field_class_unsigned_enumeration_mapping_as_mapping_const
+ native_bt.field_class_enumeration_unsigned_mapping_as_mapping_const
)
_mapping_borrow_ranges_ptr = staticmethod(
- native_bt.field_class_unsigned_enumeration_mapping_borrow_ranges_const
+ native_bt.field_class_enumeration_unsigned_mapping_borrow_ranges_const
)
class _SignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping):
- _ranges_type = bt2.integer_range_set.SignedIntegerRangeSet
+ _ranges_type = bt2_integer_range_set.SignedIntegerRangeSet
_as_enumeration_field_class_mapping_ptr = staticmethod(
- native_bt.field_class_signed_enumeration_mapping_as_mapping_const
+ native_bt.field_class_enumeration_signed_mapping_as_mapping_const
)
_mapping_borrow_ranges_ptr = staticmethod(
- native_bt.field_class_signed_enumeration_mapping_borrow_ranges_const
+ native_bt.field_class_enumeration_signed_mapping_borrow_ranges_const
)
utils._check_type(ranges, self._range_set_type)
if label in self:
- raise bt2.Error("duplicate mapping label '{}'".format(label))
+ raise ValueError("duplicate mapping label '{}'".format(label))
status = self._add_mapping(self._ptr, label, ranges._ptr)
utils._handle_func_status(
_EnumerationFieldClass, _UnsignedIntegerFieldClass
):
_NAME = 'Unsigned enumeration'
- _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet
- _add_mapping = staticmethod(native_bt.field_class_unsigned_enumeration_add_mapping)
+ _range_set_type = bt2_integer_range_set.UnsignedIntegerRangeSet
+ _add_mapping = staticmethod(native_bt.field_class_enumeration_unsigned_add_mapping)
@staticmethod
def _get_mapping_by_index(enum_ptr, index):
- mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_index_const(
+ mapping_ptr = native_bt.field_class_enumeration_unsigned_borrow_mapping_by_index_const(
enum_ptr, index
)
assert mapping_ptr is not None
@staticmethod
def _get_mapping_by_label(enum_ptr, label):
- mapping_ptr = native_bt.field_class_unsigned_enumeration_borrow_mapping_by_label_const(
+ mapping_ptr = native_bt.field_class_enumeration_unsigned_borrow_mapping_by_label_const(
enum_ptr, label
)
@staticmethod
def _get_mapping_labels_for_value(enum_ptr, value):
utils._check_uint64(value)
- return native_bt.field_class_unsigned_enumeration_get_mapping_labels_for_value(
+ return native_bt.field_class_enumeration_unsigned_get_mapping_labels_for_value(
enum_ptr, value
)
class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldClass):
_NAME = 'Signed enumeration'
- _range_set_type = bt2.integer_range_set.SignedIntegerRangeSet
- _add_mapping = staticmethod(native_bt.field_class_signed_enumeration_add_mapping)
+ _range_set_type = bt2_integer_range_set.SignedIntegerRangeSet
+ _add_mapping = staticmethod(native_bt.field_class_enumeration_signed_add_mapping)
@staticmethod
def _get_mapping_by_index(enum_ptr, index):
- mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_index_const(
+ mapping_ptr = native_bt.field_class_enumeration_signed_borrow_mapping_by_index_const(
enum_ptr, index
)
assert mapping_ptr is not None
@staticmethod
def _get_mapping_by_label(enum_ptr, label):
- mapping_ptr = native_bt.field_class_signed_enumeration_borrow_mapping_by_label_const(
+ mapping_ptr = native_bt.field_class_enumeration_signed_borrow_mapping_by_label_const(
enum_ptr, label
)
@staticmethod
def _get_mapping_labels_for_value(enum_ptr, value):
utils._check_int64(value)
- return native_bt.field_class_signed_enumeration_get_mapping_labels_for_value(
+ return native_bt.field_class_enumeration_signed_get_mapping_labels_for_value(
enum_ptr, value
)
utils._check_type(field_class, _FieldClass)
if name in self:
- raise bt2.Error("duplicate member name '{}'".format(name))
+ raise ValueError("duplicate member name '{}'".format(name))
status = native_bt.field_class_structure_append_member(
self._ptr, name, field_class._ptr
return self._create_member_from_ptr(member_ptr)
+class _OptionFieldClass(_FieldClass):
+ @property
+ def field_class(self):
+ elem_fc_ptr = native_bt.field_class_option_borrow_field_class_const(self._ptr)
+ return _create_field_class_from_ptr_and_get_ref(elem_fc_ptr)
+
+ @property
+ def selector_field_path(self):
+ ptr = native_bt.field_class_option_borrow_selector_field_path_const(self._ptr)
+ if ptr is None:
+ return
+
+ return bt2_field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
+
+
class _VariantFieldClassOption:
def __init__(self, name, field_class):
self._name = name
utils._check_type(field_class, _FieldClass)
if name in self:
- raise bt2.Error("duplicate option name '{}'".format(name))
+ raise ValueError("duplicate option name '{}'".format(name))
status = native_bt.field_class_variant_without_selector_append_option(
self._ptr, name, field_class._ptr
if ptr is None:
return
- return bt2.field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
+ return bt2_field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
def append_option(self, name, field_class, ranges):
utils._check_str(name)
utils._check_type(ranges, self._range_set_type)
if name in self:
- raise bt2.Error("duplicate option name '{}'".format(name))
+ raise ValueError("duplicate option name '{}'".format(name))
if len(ranges) == 0:
raise ValueError('range set is empty')
class _VariantFieldClassWithUnsignedSelector(_VariantFieldClassWithSelector):
_NAME = 'Variant (with unsigned selector)'
_borrow_option_by_name_ptr = staticmethod(
- native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_name_const
+ native_bt.field_class_variant_with_selector_unsigned_borrow_option_by_name_const
)
_borrow_member_by_index_ptr = staticmethod(
- native_bt.field_class_variant_with_unsigned_selector_borrow_option_by_index_const
+ native_bt.field_class_variant_with_selector_unsigned_borrow_option_by_index_const
)
_as_option_ptr = staticmethod(
- native_bt.field_class_variant_with_unsigned_selector_option_as_option_const
+ native_bt.field_class_variant_with_selector_unsigned_option_as_option_const
)
_append_option = staticmethod(
- native_bt.field_class_variant_with_unsigned_selector_append_option
+ native_bt.field_class_variant_with_selector_unsigned_append_option
)
_option_borrow_ranges_ptr = staticmethod(
- native_bt.field_class_variant_with_unsigned_selector_option_borrow_ranges_const
+ native_bt.field_class_variant_with_selector_unsigned_option_borrow_ranges_const
)
- _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet
+ _range_set_type = bt2_integer_range_set.UnsignedIntegerRangeSet
class _VariantFieldClassWithSignedSelector(_VariantFieldClassWithSelector):
_NAME = 'Variant (with signed selector)'
_borrow_option_by_name_ptr = staticmethod(
- native_bt.field_class_variant_with_signed_selector_borrow_option_by_name_const
+ native_bt.field_class_variant_with_selector_signed_borrow_option_by_name_const
)
_borrow_member_by_index_ptr = staticmethod(
- native_bt.field_class_variant_with_signed_selector_borrow_option_by_index_const
+ native_bt.field_class_variant_with_selector_signed_borrow_option_by_index_const
)
_as_option_ptr = staticmethod(
- native_bt.field_class_variant_with_signed_selector_option_as_option_const
+ native_bt.field_class_variant_with_selector_signed_option_as_option_const
)
_append_option = staticmethod(
- native_bt.field_class_variant_with_signed_selector_append_option
+ native_bt.field_class_variant_with_selector_signed_append_option
)
_option_borrow_ranges_ptr = staticmethod(
- native_bt.field_class_variant_with_signed_selector_option_borrow_ranges_const
+ native_bt.field_class_variant_with_selector_signed_option_borrow_ranges_const
)
- _range_set_type = bt2.integer_range_set.SignedIntegerRangeSet
+ _range_set_type = bt2_integer_range_set.SignedIntegerRangeSet
class _ArrayFieldClass(_FieldClass):
class _StaticArrayFieldClass(_ArrayFieldClass):
@property
def length(self):
- return native_bt.field_class_static_array_get_length(self._ptr)
+ return native_bt.field_class_array_static_get_length(self._ptr)
class _DynamicArrayFieldClass(_ArrayFieldClass):
@property
def length_field_path(self):
- ptr = native_bt.field_class_dynamic_array_borrow_length_field_path_const(
+ ptr = native_bt.field_class_array_dynamic_borrow_length_field_path_const(
self._ptr
)
if ptr is None:
return
- return bt2.field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
+ return bt2_field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
_FIELD_CLASS_TYPE_TO_OBJ = {
+ native_bt.FIELD_CLASS_TYPE_BOOL: _BoolFieldClass,
+ native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClass,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass,
native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClass,
native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClass,
native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClass,
native_bt.FIELD_CLASS_TYPE_STATIC_ARRAY: _StaticArrayFieldClass,
native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY: _DynamicArrayFieldClass,
+ native_bt.FIELD_CLASS_TYPE_OPTION: _OptionFieldClass,
native_bt.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: _VariantFieldClassWithoutSelector,
native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: _VariantFieldClassWithUnsignedSelector,
native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: _VariantFieldClassWithSignedSelector,