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)
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
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
return name
-class StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
+class _StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
_NAME = 'Structure'
_ITER_CLS = _StructureFieldClassFieldIterator
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):
return _create_from_ptr(ptr)
-_TYPE_ID_TO_OBJ = {
+_FIELD_CLASS_TYPE_TO_OBJ = {
+ native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClass,
}