sink.text.details: print user attributes
[babeltrace.git] / src / bindings / python / bt2 / bt2 / field_class.py
index 1128e4df689ef56e8eb1c76061d680e4ba52a2f5..75d7cc5a785bf3f75c3119e153d3fb2c73f7e370 100644 (file)
@@ -22,9 +22,8 @@
 
 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
 
 
@@ -46,11 +45,25 @@ class _FieldClass(object._SharedObject):
 
     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):
@@ -134,22 +147,22 @@ class _EnumerationFieldClassMapping:
 
 
 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
     )
 
 
@@ -164,7 +177,7 @@ class _EnumerationFieldClass(_IntegerFieldClass, collections.abc.Mapping):
         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(
@@ -203,12 +216,12 @@ class _UnsignedEnumerationFieldClass(
     _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
@@ -216,7 +229,7 @@ class _UnsignedEnumerationFieldClass(
 
     @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
         )
 
@@ -228,19 +241,19 @@ class _UnsignedEnumerationFieldClass(
     @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
@@ -248,7 +261,7 @@ class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldCl
 
     @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
         )
 
@@ -260,7 +273,7 @@ class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldCl
     @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
         )
 
@@ -291,7 +304,7 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping):
         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
@@ -358,6 +371,21 @@ class _StructureFieldClass(_FieldClass, collections.abc.Mapping):
         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
@@ -447,7 +475,7 @@ class _VariantFieldClassWithoutSelector(_VariantFieldClass):
         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
@@ -489,7 +517,7 @@ class _VariantFieldClassWithSelector(_VariantFieldClass):
         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)
@@ -497,7 +525,7 @@ class _VariantFieldClassWithSelector(_VariantFieldClass):
         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')
@@ -519,41 +547,41 @@ class _VariantFieldClassWithSelector(_VariantFieldClass):
 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):
@@ -568,22 +596,24 @@ 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,
@@ -593,6 +623,7 @@ _FIELD_CLASS_TYPE_TO_OBJ = {
     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,
This page took 0.02954 seconds and 4 git commands to generate.