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