bt2: Adapt test_stream_class.py and make it pass
[babeltrace.git] / bindings / python / bt2 / bt2 / field_class.py
index cd870ce85f033cdbc77044686a041dd53c30cfef..61febcc7ed52542d118090f70eb9f8a0a6aa9cd7 100644 (file)
 
 from bt2 import native_bt, object, utils
 import collections.abc
-import bt2.fields
+import bt2.field
 import abc
 import bt2
 
 
-def _create_from_ptr(ptr):
-    typeid = native_bt.field_class_get_type_id(ptr)
-    return _TYPE_ID_TO_OBJ[typeid]._create_from_ptr(ptr)
+def _create_field_class_from_ptr_and_get_ref(ptr):
+    typeid = native_bt.field_class_get_type(ptr)
+    return _FIELD_CLASS_TYPE_TO_OBJ[typeid]._create_from_ptr_and_get_ref(ptr)
 
 
-class _FieldClass(object._Object, metaclass=abc.ABCMeta):
+class _FieldClass(object._SharedObject, metaclass=abc.ABCMeta):
+    _get_ref = staticmethod(native_bt.field_class_get_ref)
+    _put_ref = staticmethod(native_bt.field_class_put_ref)
+
     def __init__(self, ptr):
         super().__init__(ptr)
 
@@ -68,10 +71,10 @@ class _FieldClass(object._Object, metaclass=abc.ABCMeta):
         if field_ptr is None:
             raise bt2.CreationError('cannot create {} field object'.format(self._NAME.lower()))
 
-        field = bt2.fields._create_from_ptr(field_ptr)
+        field = bt2.field._create_from_ptr(field_ptr)
 
         if value is not None:
-            if not isinstance(field, (bt2.fields._IntegerField, bt2.fields._FloatingPointNumberField, bt2.fields._StringField)):
+            if not isinstance(field, (bt2.field._IntegerField, bt2.field._FloatingPointNumberField, bt2.field._StringField)):
                 raise bt2.Error('cannot assign an initial value to a {} field object'.format(field._NAME))
 
             field.value = value
@@ -268,8 +271,8 @@ class _EnumerationFieldClassMapping:
         return (self.name, self.lower, self.upper) == (other.name, other.lower, other.upper)
 
 
-class _EnumerationFieldClassMappingIterator(object._Object,
-                                           collections.abc.Iterator):
+class _EnumerationFieldClassMappingIterator(object._SharedObject,
+                                            collections.abc.Iterator):
     def __init__(self, iter_ptr, is_signed):
         super().__init__(iter_ptr)
         self._is_signed = is_signed
@@ -514,7 +517,7 @@ class _StructureFieldClassFieldIterator(collections.abc.Iterator):
         return name
 
 
-class StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
+class _StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
     _NAME = 'Structure'
     _ITER_CLS = _StructureFieldClassFieldIterator
 
@@ -545,8 +548,8 @@ class StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
         return _create_from_ptr(field_class_ptr)
 
 
-StructureFieldClass.min_alignment = property(fset=StructureFieldClass.alignment.fset)
-StructureFieldClass.alignment = property(fget=StructureFieldClass.alignment.fget)
+_StructureFieldClass.min_alignment = property(fset=_StructureFieldClass.alignment.fset)
+_StructureFieldClass.alignment = property(fget=_StructureFieldClass.alignment.fget)
 
 
 class _VariantFieldClassFieldIterator(collections.abc.Iterator):
@@ -670,5 +673,6 @@ class SequenceFieldClass(_FieldClass):
         return _create_from_ptr(ptr)
 
 
-_TYPE_ID_TO_OBJ = {
+_FIELD_CLASS_TYPE_TO_OBJ = {
+    native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClass,
 }
This page took 0.02927 seconds and 4 git commands to generate.