bt2: make bt2 add graph listener wrappers append error causes
[babeltrace.git] / src / bindings / python / bt2 / bt2 / field_class.py
CommitLineData
81447b5b
PP
1# The MIT License (MIT)
2#
f6a5e476 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b
PP
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22
23from bt2 import native_bt, object, utils
24import collections.abc
ae0bfae8 25import bt2.field
c8820b76 26import bt2.field_path
02b61fe0 27import bt2.integer_range_set
81447b5b
PP
28import bt2
29
30
060aee52
SM
31def _create_field_class_from_ptr_and_get_ref(ptr):
32 typeid = native_bt.field_class_get_type(ptr)
33 return _FIELD_CLASS_TYPE_TO_OBJ[typeid]._create_from_ptr_and_get_ref(ptr)
81447b5b
PP
34
35
c8820b76
SM
36class IntegerDisplayBase:
37 BINARY = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
38 OCTAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
39 DECIMAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
40 HEXADECIMAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
81447b5b 41
81447b5b 42
c8820b76
SM
43class _FieldClass(object._SharedObject):
44 _get_ref = staticmethod(native_bt.field_class_get_ref)
45 _put_ref = staticmethod(native_bt.field_class_put_ref)
81447b5b
PP
46
47 def _check_create_status(self, ptr):
48 if ptr is None:
61d96b89
FD
49 raise bt2.CreationError(
50 'cannot create {} field class object'.format(self._NAME.lower())
51 )
81447b5b 52
81447b5b 53
a728f6c3 54class _IntegerFieldClass(_FieldClass):
81447b5b 55 @property
c8820b76
SM
56 def field_value_range(self):
57 size = native_bt.field_class_integer_get_field_value_range(self._ptr)
61d96b89 58 assert size >= 1
81447b5b
PP
59 return size
60
c8820b76
SM
61 def _field_value_range(self, size):
62 if size < 1 or size > 64:
63 raise ValueError("Value is outside valid range [1, 64] ({})".format(size))
64 native_bt.field_class_integer_set_field_value_range(self._ptr, size)
81447b5b 65
c8820b76 66 _field_value_range = property(fset=_field_value_range)
81447b5b
PP
67
68 @property
c8820b76 69 def preferred_display_base(self):
61d96b89
FD
70 base = native_bt.field_class_integer_get_preferred_display_base(self._ptr)
71 assert base >= 0
81447b5b
PP
72 return base
73
c8820b76
SM
74 def _preferred_display_base(self, base):
75 utils._check_uint64(base)
81447b5b 76
61d96b89
FD
77 if base not in (
78 IntegerDisplayBase.BINARY,
79 IntegerDisplayBase.OCTAL,
80 IntegerDisplayBase.DECIMAL,
81 IntegerDisplayBase.HEXADECIMAL,
82 ):
c8820b76 83 raise ValueError("Display base is not a valid IntegerDisplayBase value")
81447b5b 84
61d96b89 85 native_bt.field_class_integer_set_preferred_display_base(self._ptr, base)
81447b5b 86
c8820b76 87 _preferred_display_base = property(fset=_preferred_display_base)
81447b5b
PP
88
89
27d97a3f 90class _UnsignedIntegerFieldClass(_IntegerFieldClass):
c8820b76 91 _NAME = 'Unsigned integer'
27d97a3f
SM
92
93
a728f6c3 94class _SignedIntegerFieldClass(_IntegerFieldClass):
c8820b76 95 _NAME = 'Signed integer'
27d97a3f 96
a728f6c3 97
c8820b76 98class _RealFieldClass(_FieldClass):
27d97a3f 99 _NAME = 'Real'
81447b5b 100
81447b5b 101 @property
c8820b76
SM
102 def is_single_precision(self):
103 return native_bt.field_class_real_is_single_precision(self._ptr)
81447b5b 104
c8820b76
SM
105 def _is_single_precision(self, is_single_precision):
106 utils._check_bool(is_single_precision)
107 native_bt.field_class_real_set_is_single_precision(
61d96b89
FD
108 self._ptr, is_single_precision
109 )
81447b5b 110
c8820b76 111 _is_single_precision = property(fset=_is_single_precision)
81447b5b
PP
112
113
02b61fe0
PP
114# an enumeration field class mapping does not have a reference count, so
115# we copy the properties here to avoid eventual memory access errors.
116class _EnumerationFieldClassMapping:
c8820b76 117 def __init__(self, mapping_ptr):
02b61fe0 118 base_mapping_ptr = self._as_enumeration_field_class_mapping_ptr(mapping_ptr)
61d96b89
FD
119 self._label = native_bt.field_class_enumeration_mapping_get_label(
120 base_mapping_ptr
121 )
02b61fe0
PP
122 assert self._label is not None
123 ranges_ptr = self._mapping_borrow_ranges_ptr(mapping_ptr)
124 assert ranges_ptr is not None
125 self._ranges = self._ranges_type._create_from_ptr_and_get_ref(ranges_ptr)
81447b5b
PP
126
127 @property
c8820b76 128 def label(self):
02b61fe0 129 return self._label
81447b5b 130
02b61fe0
PP
131 @property
132 def ranges(self):
133 return self._ranges
81447b5b 134
81447b5b 135
c8820b76 136class _UnsignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping):
02b61fe0 137 _ranges_type = bt2.integer_range_set.UnsignedIntegerRangeSet
61d96b89 138 _as_enumeration_field_class_mapping_ptr = staticmethod(
60bbfc7c 139 native_bt.field_class_enumeration_unsigned_mapping_as_mapping_const
61d96b89
FD
140 )
141 _mapping_borrow_ranges_ptr = staticmethod(
60bbfc7c 142 native_bt.field_class_enumeration_unsigned_mapping_borrow_ranges_const
61d96b89 143 )
81447b5b 144
81447b5b 145
c8820b76 146class _SignedEnumerationFieldClassMapping(_EnumerationFieldClassMapping):
02b61fe0 147 _ranges_type = bt2.integer_range_set.SignedIntegerRangeSet
61d96b89 148 _as_enumeration_field_class_mapping_ptr = staticmethod(
60bbfc7c 149 native_bt.field_class_enumeration_signed_mapping_as_mapping_const
61d96b89
FD
150 )
151 _mapping_borrow_ranges_ptr = staticmethod(
60bbfc7c 152 native_bt.field_class_enumeration_signed_mapping_borrow_ranges_const
61d96b89 153 )
81447b5b 154
81447b5b 155
c8820b76 156class _EnumerationFieldClass(_IntegerFieldClass, collections.abc.Mapping):
81447b5b 157 def __len__(self):
32656995 158 count = native_bt.field_class_enumeration_get_mapping_count(self._ptr)
02b61fe0 159 assert count >= 0
81447b5b
PP
160 return count
161
02b61fe0 162 def add_mapping(self, label, ranges):
c8820b76 163 utils._check_str(label)
02b61fe0 164 utils._check_type(ranges, self._range_set_type)
81447b5b 165
02b61fe0
PP
166 if label in self:
167 raise bt2.Error("duplicate mapping label '{}'".format(label))
81447b5b 168
02b61fe0 169 status = self._add_mapping(self._ptr, label, ranges._ptr)
61d96b89
FD
170 utils._handle_func_status(
171 status, 'cannot add mapping to enumeration field class object'
172 )
81447b5b 173
02b61fe0 174 def mappings_for_value(self, value):
1091bb60 175 status, labels = self._get_mapping_labels_for_value(self._ptr, value)
61d96b89
FD
176 utils._handle_func_status(
177 status, 'cannot get mapping labels for value {}'.format(value)
178 )
02b61fe0 179 return [self[label] for label in labels]
81447b5b 180
c8820b76
SM
181 def __iter__(self):
182 for idx in range(len(self)):
183 mapping = self._get_mapping_by_index(self._ptr, idx)
184 yield mapping.label
81447b5b 185
02b61fe0
PP
186 def __getitem__(self, label):
187 utils._check_str(label)
188 mapping = self._get_mapping_by_label(self._ptr, label)
81447b5b 189
02b61fe0
PP
190 if mapping is None:
191 raise KeyError(label)
192
193 return mapping
81447b5b 194
c8820b76 195 def __iadd__(self, mappings):
02b61fe0
PP
196 for label, ranges in mappings:
197 self.add_mapping(label, ranges)
81447b5b 198
c8820b76 199 return self
81447b5b 200
81447b5b 201
61d96b89
FD
202class _UnsignedEnumerationFieldClass(
203 _EnumerationFieldClass, _UnsignedIntegerFieldClass
204):
c8820b76 205 _NAME = 'Unsigned enumeration'
02b61fe0 206 _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet
60bbfc7c 207 _add_mapping = staticmethod(native_bt.field_class_enumeration_unsigned_add_mapping)
81447b5b 208
c8820b76
SM
209 @staticmethod
210 def _get_mapping_by_index(enum_ptr, index):
60bbfc7c 211 mapping_ptr = native_bt.field_class_enumeration_unsigned_borrow_mapping_by_index_const(
61d96b89
FD
212 enum_ptr, index
213 )
c8820b76
SM
214 assert mapping_ptr is not None
215 return _UnsignedEnumerationFieldClassMapping(mapping_ptr)
81447b5b 216
c8820b76 217 @staticmethod
02b61fe0 218 def _get_mapping_by_label(enum_ptr, label):
60bbfc7c 219 mapping_ptr = native_bt.field_class_enumeration_unsigned_borrow_mapping_by_label_const(
61d96b89
FD
220 enum_ptr, label
221 )
02b61fe0
PP
222
223 if mapping_ptr is None:
224 return
225
226 return _UnsignedEnumerationFieldClassMapping(mapping_ptr)
81447b5b 227
c8820b76 228 @staticmethod
1091bb60 229 def _get_mapping_labels_for_value(enum_ptr, value):
c8820b76 230 utils._check_uint64(value)
60bbfc7c 231 return native_bt.field_class_enumeration_unsigned_get_mapping_labels_for_value(
61d96b89
FD
232 enum_ptr, value
233 )
81447b5b
PP
234
235
c8820b76
SM
236class _SignedEnumerationFieldClass(_EnumerationFieldClass, _SignedIntegerFieldClass):
237 _NAME = 'Signed enumeration'
02b61fe0 238 _range_set_type = bt2.integer_range_set.SignedIntegerRangeSet
60bbfc7c 239 _add_mapping = staticmethod(native_bt.field_class_enumeration_signed_add_mapping)
81447b5b 240
c8820b76
SM
241 @staticmethod
242 def _get_mapping_by_index(enum_ptr, index):
60bbfc7c 243 mapping_ptr = native_bt.field_class_enumeration_signed_borrow_mapping_by_index_const(
61d96b89
FD
244 enum_ptr, index
245 )
c8820b76
SM
246 assert mapping_ptr is not None
247 return _SignedEnumerationFieldClassMapping(mapping_ptr)
81447b5b 248
c8820b76 249 @staticmethod
02b61fe0 250 def _get_mapping_by_label(enum_ptr, label):
60bbfc7c 251 mapping_ptr = native_bt.field_class_enumeration_signed_borrow_mapping_by_label_const(
61d96b89
FD
252 enum_ptr, label
253 )
02b61fe0
PP
254
255 if mapping_ptr is None:
256 return
257
258 return _SignedEnumerationFieldClassMapping(mapping_ptr)
81447b5b 259
c8820b76 260 @staticmethod
1091bb60 261 def _get_mapping_labels_for_value(enum_ptr, value):
c8820b76 262 utils._check_int64(value)
60bbfc7c 263 return native_bt.field_class_enumeration_signed_get_mapping_labels_for_value(
61d96b89
FD
264 enum_ptr, value
265 )
81447b5b 266
c8820b76
SM
267
268class _StringFieldClass(_FieldClass):
269 _NAME = 'String'
81447b5b
PP
270
271
02b61fe0
PP
272class _StructureFieldClassMember:
273 def __init__(self, name, field_class):
274 self._name = name
275 self._field_class = field_class
276
277 @property
278 def name(self):
279 return self._name
280
281 @property
282 def field_class(self):
283 return self._field_class
284
285
286class _StructureFieldClass(_FieldClass, collections.abc.Mapping):
287 _NAME = 'Structure'
288
289 def append_member(self, name, field_class):
290 utils._check_str(name)
291 utils._check_type(field_class, _FieldClass)
292
293 if name in self:
294 raise bt2.Error("duplicate member name '{}'".format(name))
295
61d96b89
FD
296 status = native_bt.field_class_structure_append_member(
297 self._ptr, name, field_class._ptr
298 )
299 utils._handle_func_status(
300 status, 'cannot append member to structure field class object'
301 )
02b61fe0 302
81447b5b 303 def __len__(self):
02b61fe0 304 count = native_bt.field_class_structure_get_member_count(self._ptr)
c8820b76 305 assert count >= 0
81447b5b
PP
306 return count
307
02b61fe0
PP
308 @staticmethod
309 def _create_member_from_ptr(member_ptr):
310 name = native_bt.field_class_structure_member_get_name(member_ptr)
311 assert name is not None
61d96b89
FD
312 fc_ptr = native_bt.field_class_structure_member_borrow_field_class_const(
313 member_ptr
314 )
02b61fe0
PP
315 assert fc_ptr is not None
316 fc = _create_field_class_from_ptr_and_get_ref(fc_ptr)
317 return _StructureFieldClassMember(name, fc)
318
81447b5b
PP
319 def __getitem__(self, key):
320 if not isinstance(key, str):
61d96b89
FD
321 raise TypeError(
322 "key must be a 'str' object, got '{}'".format(key.__class__.__name__)
323 )
81447b5b 324
61d96b89
FD
325 member_ptr = native_bt.field_class_structure_borrow_member_by_name_const(
326 self._ptr, key
327 )
81447b5b 328
02b61fe0 329 if member_ptr is None:
81447b5b
PP
330 raise KeyError(key)
331
02b61fe0 332 return self._create_member_from_ptr(member_ptr)
81447b5b
PP
333
334 def __iter__(self):
c8820b76 335 for idx in range(len(self)):
61d96b89
FD
336 member_ptr = native_bt.field_class_structure_borrow_member_by_index_const(
337 self._ptr, idx
338 )
02b61fe0
PP
339 assert member_ptr is not None
340 yield native_bt.field_class_structure_member_get_name(member_ptr)
81447b5b 341
02b61fe0
PP
342 def __iadd__(self, members):
343 for name, field_class in members:
344 self.append_member(name, field_class)
81447b5b
PP
345
346 return self
347
02b61fe0 348 def member_at_index(self, index):
81447b5b 349 utils._check_uint64(index)
81447b5b 350
02b61fe0 351 if index >= len(self):
f6a5e476
PP
352 raise IndexError
353
61d96b89
FD
354 member_ptr = native_bt.field_class_structure_borrow_member_by_index_const(
355 self._ptr, index
356 )
02b61fe0
PP
357 assert member_ptr is not None
358 return self._create_member_from_ptr(member_ptr)
359
81447b5b 360
02b61fe0
PP
361class _VariantFieldClassOption:
362 def __init__(self, name, field_class):
363 self._name = name
364 self._field_class = field_class
81447b5b 365
02b61fe0
PP
366 @property
367 def name(self):
368 return self._name
81447b5b 369
02b61fe0
PP
370 @property
371 def field_class(self):
372 return self._field_class
81447b5b 373
81447b5b 374
02b61fe0
PP
375class _VariantFieldClassWithSelectorOption(_VariantFieldClassOption):
376 def __init__(self, name, field_class, ranges):
377 super().__init__(name, field_class)
378 self._ranges = ranges
81447b5b 379
02b61fe0
PP
380 @property
381 def ranges(self):
382 return self._ranges
81447b5b
PP
383
384
02b61fe0 385class _VariantFieldClass(_FieldClass, collections.abc.Mapping):
81447b5b 386 _NAME = 'Variant'
61d96b89
FD
387 _borrow_option_by_name_ptr = staticmethod(
388 native_bt.field_class_variant_borrow_option_by_name_const
389 )
390 _borrow_member_by_index_ptr = staticmethod(
391 native_bt.field_class_variant_borrow_option_by_index_const
392 )
f6a5e476 393
02b61fe0
PP
394 @staticmethod
395 def _as_option_ptr(opt_ptr):
396 return opt_ptr
397
398 def _create_option_from_ptr(self, opt_ptr):
399 name = native_bt.field_class_variant_option_get_name(opt_ptr)
400 assert name is not None
401 fc_ptr = native_bt.field_class_variant_option_borrow_field_class_const(opt_ptr)
402 assert fc_ptr is not None
403 fc = _create_field_class_from_ptr_and_get_ref(fc_ptr)
404 return _VariantFieldClassOption(name, fc)
405
406 def __len__(self):
407 count = native_bt.field_class_variant_get_option_count(self._ptr)
408 assert count >= 0
409 return count
410
411 def __getitem__(self, key):
412 if not isinstance(key, str):
61d96b89
FD
413 raise TypeError(
414 "key must be a 'str' object, got '{}'".format(key.__class__.__name__)
415 )
02b61fe0
PP
416
417 opt_ptr = self._borrow_option_by_name_ptr(self._ptr, key)
418
419 if opt_ptr is None:
420 raise KeyError(key)
421
422 return self._create_option_from_ptr(opt_ptr)
423
424 def __iter__(self):
425 for idx in range(len(self)):
426 opt_ptr = self._borrow_member_by_index_ptr(self._ptr, idx)
427 assert opt_ptr is not None
428 base_opt_ptr = self._as_option_ptr(opt_ptr)
429 yield native_bt.field_class_variant_option_get_name(base_opt_ptr)
f6a5e476 430
c8820b76 431 def option_at_index(self, index):
02b61fe0
PP
432 utils._check_uint64(index)
433
434 if index >= len(self):
435 raise IndexError
436
437 opt_ptr = self._borrow_member_by_index_ptr(self._ptr, index)
438 assert opt_ptr is not None
439 return self._create_option_from_ptr(opt_ptr)
440
441
442class _VariantFieldClassWithoutSelector(_VariantFieldClass):
443 _NAME = 'Variant (without selector)'
444
445 def append_option(self, name, field_class):
446 utils._check_str(name)
447 utils._check_type(field_class, _FieldClass)
448
449 if name in self:
450 raise bt2.Error("duplicate option name '{}'".format(name))
451
61d96b89
FD
452 status = native_bt.field_class_variant_without_selector_append_option(
453 self._ptr, name, field_class._ptr
454 )
455 utils._handle_func_status(
456 status, 'cannot append option to variant field class object'
457 )
02b61fe0
PP
458
459 def __iadd__(self, options):
460 for name, field_class in options:
461 self.append_option(name, field_class)
462
463 return self
464
465
466class _VariantFieldClassWithSelector(_VariantFieldClass):
467 _NAME = 'Variant (with selector)'
468
469 def _create_option_from_ptr(self, opt_ptr):
470 base_opt_ptr = self._as_option_ptr(opt_ptr)
471 name = native_bt.field_class_variant_option_get_name(base_opt_ptr)
472 assert name is not None
61d96b89
FD
473 fc_ptr = native_bt.field_class_variant_option_borrow_field_class_const(
474 base_opt_ptr
475 )
02b61fe0
PP
476 assert fc_ptr is not None
477 fc = _create_field_class_from_ptr_and_get_ref(fc_ptr)
478 range_set_ptr = self._option_borrow_ranges_ptr(opt_ptr)
479 assert range_set_ptr is not None
480 range_set = self._range_set_type._create_from_ptr_and_get_ref(range_set_ptr)
481 return _VariantFieldClassWithSelectorOption(name, fc, range_set)
81447b5b
PP
482
483 @property
c8820b76 484 def selector_field_path(self):
61d96b89
FD
485 ptr = native_bt.field_class_variant_with_selector_borrow_selector_field_path_const(
486 self._ptr
487 )
02b61fe0 488
c8820b76 489 if ptr is None:
f6a5e476
PP
490 return
491
c8820b76 492 return bt2.field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
81447b5b 493
02b61fe0
PP
494 def append_option(self, name, field_class, ranges):
495 utils._check_str(name)
496 utils._check_type(field_class, _FieldClass)
497 utils._check_type(ranges, self._range_set_type)
498
499 if name in self:
500 raise bt2.Error("duplicate option name '{}'".format(name))
501
502 if len(ranges) == 0:
503 raise ValueError('range set is empty')
504
505 # TODO: check overlaps (precondition of self._append_option())
506
507 status = self._append_option(self._ptr, name, field_class._ptr, ranges._ptr)
61d96b89
FD
508 utils._handle_func_status(
509 status, 'cannot append option to variant field class object'
510 )
02b61fe0
PP
511
512 def __iadd__(self, options):
513 for name, field_class, ranges in options:
514 self.append_option(name, field_class, ranges)
515
516 return self
517
518
519class _VariantFieldClassWithUnsignedSelector(_VariantFieldClassWithSelector):
520 _NAME = 'Variant (with unsigned selector)'
61d96b89 521 _borrow_option_by_name_ptr = staticmethod(
60bbfc7c 522 native_bt.field_class_variant_with_selector_unsigned_borrow_option_by_name_const
61d96b89
FD
523 )
524 _borrow_member_by_index_ptr = staticmethod(
60bbfc7c 525 native_bt.field_class_variant_with_selector_unsigned_borrow_option_by_index_const
61d96b89
FD
526 )
527 _as_option_ptr = staticmethod(
60bbfc7c 528 native_bt.field_class_variant_with_selector_unsigned_option_as_option_const
61d96b89
FD
529 )
530 _append_option = staticmethod(
60bbfc7c 531 native_bt.field_class_variant_with_selector_unsigned_append_option
61d96b89
FD
532 )
533 _option_borrow_ranges_ptr = staticmethod(
60bbfc7c 534 native_bt.field_class_variant_with_selector_unsigned_option_borrow_ranges_const
61d96b89 535 )
02b61fe0
PP
536 _range_set_type = bt2.integer_range_set.UnsignedIntegerRangeSet
537
81447b5b 538
02b61fe0
PP
539class _VariantFieldClassWithSignedSelector(_VariantFieldClassWithSelector):
540 _NAME = 'Variant (with signed selector)'
61d96b89 541 _borrow_option_by_name_ptr = staticmethod(
60bbfc7c 542 native_bt.field_class_variant_with_selector_signed_borrow_option_by_name_const
61d96b89
FD
543 )
544 _borrow_member_by_index_ptr = staticmethod(
60bbfc7c 545 native_bt.field_class_variant_with_selector_signed_borrow_option_by_index_const
61d96b89
FD
546 )
547 _as_option_ptr = staticmethod(
60bbfc7c 548 native_bt.field_class_variant_with_selector_signed_option_as_option_const
61d96b89
FD
549 )
550 _append_option = staticmethod(
60bbfc7c 551 native_bt.field_class_variant_with_selector_signed_append_option
61d96b89
FD
552 )
553 _option_borrow_ranges_ptr = staticmethod(
60bbfc7c 554 native_bt.field_class_variant_with_selector_signed_option_borrow_ranges_const
61d96b89 555 )
02b61fe0 556 _range_set_type = bt2.integer_range_set.SignedIntegerRangeSet
f6a5e476 557
81447b5b 558
c8820b76
SM
559class _ArrayFieldClass(_FieldClass):
560 @property
561 def element_field_class(self):
61d96b89
FD
562 elem_fc_ptr = native_bt.field_class_array_borrow_element_field_class_const(
563 self._ptr
564 )
c8820b76 565 return _create_field_class_from_ptr_and_get_ref(elem_fc_ptr)
81447b5b 566
81447b5b 567
c8820b76 568class _StaticArrayFieldClass(_ArrayFieldClass):
81447b5b
PP
569 @property
570 def length(self):
60bbfc7c 571 return native_bt.field_class_array_static_get_length(self._ptr)
81447b5b
PP
572
573
c8820b76
SM
574class _DynamicArrayFieldClass(_ArrayFieldClass):
575 @property
576 def length_field_path(self):
60bbfc7c 577 ptr = native_bt.field_class_array_dynamic_borrow_length_field_path_const(
61d96b89
FD
578 self._ptr
579 )
c8820b76
SM
580 if ptr is None:
581 return
81447b5b 582
c8820b76 583 return bt2.field_path._FieldPath._create_from_ptr_and_get_ref(ptr)
81447b5b 584
81447b5b 585
060aee52 586_FIELD_CLASS_TYPE_TO_OBJ = {
c8820b76
SM
587 native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass,
588 native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClass,
589 native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClass,
590 native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClass,
591 native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClass,
592 native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClass,
060aee52 593 native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClass,
c8820b76
SM
594 native_bt.FIELD_CLASS_TYPE_STATIC_ARRAY: _StaticArrayFieldClass,
595 native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY: _DynamicArrayFieldClass,
02b61fe0
PP
596 native_bt.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: _VariantFieldClassWithoutSelector,
597 native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: _VariantFieldClassWithUnsignedSelector,
598 native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: _VariantFieldClassWithSignedSelector,
81447b5b 599}
This page took 0.072503 seconds and 4 git commands to generate.