Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: MIT |
81447b5b | 2 | # |
811644b8 | 3 | # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com> |
81447b5b PP |
4 | |
5 | from bt2 import native_bt, object, utils | |
6 | import collections.abc | |
3fb99a22 PP |
7 | from bt2 import field_path as bt2_field_path |
8 | from bt2 import integer_range_set as bt2_integer_range_set | |
5783664e | 9 | from bt2 import value as bt2_value |
81447b5b PP |
10 | import bt2 |
11 | ||
12 | ||
2bebdd7f | 13 | def _obj_type_from_field_class_ptr_template(type_map, ptr): |
3cdfbaea | 14 | typeid = native_bt.field_class_get_type(ptr) |
2bebdd7f SM |
15 | return type_map[typeid] |
16 | ||
17 | ||
18 | def _obj_type_from_field_class_ptr(ptr): | |
19 | return _obj_type_from_field_class_ptr_template(_FIELD_CLASS_TYPE_TO_OBJ, ptr) | |
20 | ||
21 | ||
22 | def _create_field_class_from_ptr_and_get_ref_template(type_map, ptr): | |
23 | return _obj_type_from_field_class_ptr_template( | |
24 | type_map, ptr | |
25 | )._create_from_ptr_and_get_ref(ptr) | |
f0a42b33 FD |
26 | |
27 | ||
28 | def _create_field_class_from_ptr_and_get_ref(ptr): | |
29 | return _create_field_class_from_ptr_and_get_ref_template( | |
30 | _FIELD_CLASS_TYPE_TO_OBJ, ptr | |
31 | ) | |
32 | ||
33 | ||
34 | def _create_field_class_from_const_ptr_and_get_ref(ptr): | |
35 | return _create_field_class_from_ptr_and_get_ref_template( | |
36 | _FIELD_CLASS_TYPE_TO_CONST_OBJ, ptr | |
37 | ) | |
81447b5b PP |
38 | |
39 | ||
d47b87ac SM |
40 | class IntegerDisplayBase: |
41 | BINARY = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY | |
42 | OCTAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL | |
43 | DECIMAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL | |
44 | HEXADECIMAL = native_bt.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL | |
81447b5b | 45 | |
81447b5b | 46 | |
f0a42b33 | 47 | class _FieldClassConst(object._SharedObject): |
9dee90bd SM |
48 | @staticmethod |
49 | def _get_ref(ptr): | |
50 | native_bt.field_class_get_ref(ptr) | |
51 | ||
52 | @staticmethod | |
53 | def _put_ref(ptr): | |
54 | native_bt.field_class_put_ref(ptr) | |
55 | ||
f0a42b33 FD |
56 | _borrow_user_attributes_ptr = staticmethod( |
57 | native_bt.field_class_borrow_user_attributes_const | |
58 | ) | |
59 | _create_value_from_ptr_and_get_ref = staticmethod( | |
60 | bt2_value._create_from_const_ptr_and_get_ref | |
61 | ) | |
81447b5b PP |
62 | |
63 | def _check_create_status(self, ptr): | |
64 | if ptr is None: | |
694c792b | 65 | raise bt2._MemoryError( |
f5567ea8 | 66 | "cannot create {} field class object".format(self._NAME.lower()) |
cfbd7cf3 | 67 | ) |
81447b5b | 68 | |
5783664e PP |
69 | @property |
70 | def user_attributes(self): | |
f0a42b33 | 71 | ptr = self._borrow_user_attributes_ptr(self._ptr) |
5783664e | 72 | assert ptr is not None |
f0a42b33 FD |
73 | return self._create_value_from_ptr_and_get_ref(ptr) |
74 | ||
75 | ||
76 | class _FieldClass(_FieldClassConst): | |
77 | _borrow_user_attributes_ptr = staticmethod( | |
78 | native_bt.field_class_borrow_user_attributes | |
79 | ) | |
80 | _create_value_from_ptr_and_get_ref = staticmethod( | |
81 | bt2_value._create_from_ptr_and_get_ref | |
82 | ) | |
5783664e PP |
83 | |
84 | def _user_attributes(self, user_attributes): | |
85 | value = bt2_value.create_value(user_attributes) | |
86 | utils._check_type(value, bt2_value.MapValue) | |
87 | native_bt.field_class_set_user_attributes(self._ptr, value._ptr) | |
88 | ||
89 | _user_attributes = property(fset=_user_attributes) | |
90 | ||
81447b5b | 91 | |
f0a42b33 | 92 | class _BoolFieldClassConst(_FieldClassConst): |
f5567ea8 | 93 | _NAME = "Const boolean" |
f0a42b33 FD |
94 | |
95 | ||
96 | class _BoolFieldClass(_BoolFieldClassConst, _FieldClass): | |
f5567ea8 | 97 | _NAME = "Boolean" |
aae30e61 PP |
98 | |
99 | ||
f0a42b33 | 100 | class _BitArrayFieldClassConst(_FieldClassConst): |
f5567ea8 | 101 | _NAME = "Const bit array" |
ead8c3d4 PP |
102 | |
103 | @property | |
104 | def length(self): | |
105 | length = native_bt.field_class_bit_array_get_length(self._ptr) | |
106 | assert length >= 1 | |
107 | return length | |
108 | ||
109 | ||
f0a42b33 | 110 | class _BitArrayFieldClass(_BitArrayFieldClassConst, _FieldClass): |
f5567ea8 | 111 | _NAME = "Bit array" |
f0a42b33 FD |
112 | |
113 | ||
114 | class _IntegerFieldClassConst(_FieldClassConst): | |
81447b5b | 115 | @property |
d47b87ac SM |
116 | def field_value_range(self): |
117 | size = native_bt.field_class_integer_get_field_value_range(self._ptr) | |
cfbd7cf3 | 118 | assert size >= 1 |
81447b5b PP |
119 | return size |
120 | ||
f0a42b33 FD |
121 | @property |
122 | def preferred_display_base(self): | |
123 | base = native_bt.field_class_integer_get_preferred_display_base(self._ptr) | |
124 | assert base >= 0 | |
125 | return base | |
126 | ||
127 | ||
128 | class _IntegerFieldClass(_FieldClass, _IntegerFieldClassConst): | |
d47b87ac SM |
129 | def _field_value_range(self, size): |
130 | if size < 1 or size > 64: | |
131 | raise ValueError("Value is outside valid range [1, 64] ({})".format(size)) | |
132 | native_bt.field_class_integer_set_field_value_range(self._ptr, size) | |
81447b5b | 133 | |
d47b87ac | 134 | _field_value_range = property(fset=_field_value_range) |
81447b5b | 135 | |
d47b87ac SM |
136 | def _preferred_display_base(self, base): |
137 | utils._check_uint64(base) | |
81447b5b | 138 | |
cfbd7cf3 FD |
139 | if base not in ( |
140 | IntegerDisplayBase.BINARY, | |
141 | IntegerDisplayBase.OCTAL, | |
142 | IntegerDisplayBase.DECIMAL, | |
143 | IntegerDisplayBase.HEXADECIMAL, | |
144 | ): | |
d47b87ac | 145 | raise ValueError("Display base is not a valid IntegerDisplayBase value") |
81447b5b | 146 | |
cfbd7cf3 | 147 | native_bt.field_class_integer_set_preferred_display_base(self._ptr, base) |
81447b5b | 148 | |
d47b87ac | 149 | _preferred_display_base = property(fset=_preferred_display_base) |
81447b5b PP |
150 | |
151 | ||
f0a42b33 | 152 | class _UnsignedIntegerFieldClassConst(_IntegerFieldClassConst, _FieldClassConst): |
f5567ea8 | 153 | _NAME = "Const unsigned integer" |
f0a42b33 FD |
154 | |
155 | ||
156 | class _UnsignedIntegerFieldClass( | |
157 | _UnsignedIntegerFieldClassConst, _IntegerFieldClass, _FieldClass | |
158 | ): | |
f5567ea8 | 159 | _NAME = "Unsigned integer" |
2ae9f48c SM |
160 | |
161 | ||
f0a42b33 | 162 | class _SignedIntegerFieldClassConst(_IntegerFieldClassConst, _FieldClassConst): |
f5567ea8 | 163 | _NAME = "Const signed integer" |
f0a42b33 FD |
164 | |
165 | ||
166 | class _SignedIntegerFieldClass( | |
167 | _SignedIntegerFieldClassConst, _IntegerFieldClass, _FieldClass | |
168 | ): | |
f5567ea8 | 169 | _NAME = "Signed integer" |
2ae9f48c | 170 | |
af4bbfc7 | 171 | |
f0a42b33 | 172 | class _RealFieldClassConst(_FieldClassConst): |
fe4df857 | 173 | pass |
81447b5b | 174 | |
fe4df857 FD |
175 | |
176 | class _SinglePrecisionRealFieldClassConst(_RealFieldClassConst): | |
f5567ea8 | 177 | _NAME = "Const single-precision real" |
fe4df857 FD |
178 | |
179 | ||
180 | class _DoublePrecisionRealFieldClassConst(_RealFieldClassConst): | |
f5567ea8 | 181 | _NAME = "Const double-precision real" |
81447b5b | 182 | |
f0a42b33 FD |
183 | |
184 | class _RealFieldClass(_FieldClass, _RealFieldClassConst): | |
fe4df857 FD |
185 | pass |
186 | ||
187 | ||
188 | class _SinglePrecisionRealFieldClass(_RealFieldClass): | |
f5567ea8 | 189 | _NAME = "Single-precision real" |
f0a42b33 | 190 | |
81447b5b | 191 | |
fe4df857 | 192 | class _DoublePrecisionRealFieldClass(_RealFieldClass): |
f5567ea8 | 193 | _NAME = "Double-precision real" |
81447b5b PP |
194 | |
195 | ||
45c51519 PP |
196 | # an enumeration field class mapping does not have a reference count, so |
197 | # we copy the properties here to avoid eventual memory access errors. | |
198 | class _EnumerationFieldClassMapping: | |
d47b87ac | 199 | def __init__(self, mapping_ptr): |
45c51519 | 200 | base_mapping_ptr = self._as_enumeration_field_class_mapping_ptr(mapping_ptr) |
cfbd7cf3 FD |
201 | self._label = native_bt.field_class_enumeration_mapping_get_label( |
202 | base_mapping_ptr | |
203 | ) | |
45c51519 PP |
204 | assert self._label is not None |
205 | ranges_ptr = self._mapping_borrow_ranges_ptr(mapping_ptr) | |
206 | assert ranges_ptr is not None | |
ef9cc185 | 207 | self._ranges = self._range_set_pycls._create_from_ptr_and_get_ref(ranges_ptr) |
81447b5b PP |
208 | |
209 | @property | |
d47b87ac | 210 | def label(self): |
45c51519 | 211 | return self._label |
81447b5b | 212 | |
45c51519 PP |
213 | @property |
214 | def ranges(self): | |
215 | return self._ranges | |
81447b5b | 216 | |
81447b5b | 217 | |
f0a42b33 | 218 | class _UnsignedEnumerationFieldClassMappingConst(_EnumerationFieldClassMapping): |
fc866000 | 219 | _range_set_pycls = bt2_integer_range_set._UnsignedIntegerRangeSetConst |
cfbd7cf3 | 220 | _as_enumeration_field_class_mapping_ptr = staticmethod( |
9c08c816 | 221 | native_bt.field_class_enumeration_unsigned_mapping_as_mapping_const |
cfbd7cf3 FD |
222 | ) |
223 | _mapping_borrow_ranges_ptr = staticmethod( | |
9c08c816 | 224 | native_bt.field_class_enumeration_unsigned_mapping_borrow_ranges_const |
cfbd7cf3 | 225 | ) |
81447b5b | 226 | |
81447b5b | 227 | |
f0a42b33 | 228 | class _SignedEnumerationFieldClassMappingConst(_EnumerationFieldClassMapping): |
fc866000 | 229 | _range_set_pycls = bt2_integer_range_set._SignedIntegerRangeSetConst |
cfbd7cf3 | 230 | _as_enumeration_field_class_mapping_ptr = staticmethod( |
9c08c816 | 231 | native_bt.field_class_enumeration_signed_mapping_as_mapping_const |
cfbd7cf3 FD |
232 | ) |
233 | _mapping_borrow_ranges_ptr = staticmethod( | |
9c08c816 | 234 | native_bt.field_class_enumeration_signed_mapping_borrow_ranges_const |
cfbd7cf3 | 235 | ) |
81447b5b | 236 | |
81447b5b | 237 | |
f0a42b33 | 238 | class _EnumerationFieldClassConst(_IntegerFieldClassConst, collections.abc.Mapping): |
81447b5b | 239 | def __len__(self): |
b4f45851 | 240 | count = native_bt.field_class_enumeration_get_mapping_count(self._ptr) |
45c51519 | 241 | assert count >= 0 |
81447b5b PP |
242 | return count |
243 | ||
45c51519 | 244 | def mappings_for_value(self, value): |
f0a42b33 FD |
245 | self._check_int_type(value) |
246 | ||
185ecf64 | 247 | status, labels = self._get_mapping_labels_for_value(self._ptr, value) |
cfbd7cf3 | 248 | utils._handle_func_status( |
f5567ea8 | 249 | status, "cannot get mapping labels for value {}".format(value) |
cfbd7cf3 | 250 | ) |
45c51519 | 251 | return [self[label] for label in labels] |
81447b5b | 252 | |
d47b87ac SM |
253 | def __iter__(self): |
254 | for idx in range(len(self)): | |
f0a42b33 FD |
255 | mapping_ptr = self._borrow_mapping_ptr_by_index(self._ptr, idx) |
256 | yield self._mapping_pycls(mapping_ptr).label | |
81447b5b | 257 | |
45c51519 PP |
258 | def __getitem__(self, label): |
259 | utils._check_str(label) | |
f0a42b33 | 260 | mapping_ptr = self._borrow_mapping_ptr_by_label(self._ptr, label) |
81447b5b | 261 | |
f0a42b33 | 262 | if mapping_ptr is None: |
45c51519 PP |
263 | raise KeyError(label) |
264 | ||
f0a42b33 FD |
265 | return self._mapping_pycls(mapping_ptr) |
266 | ||
267 | ||
268 | class _EnumerationFieldClass(_EnumerationFieldClassConst, _IntegerFieldClass): | |
269 | def add_mapping(self, label, ranges): | |
270 | utils._check_str(label) | |
ef9cc185 | 271 | utils._check_type(ranges, self._range_set_pycls) |
f0a42b33 FD |
272 | |
273 | if label in self: | |
274 | raise ValueError("duplicate mapping label '{}'".format(label)) | |
275 | ||
276 | status = self._add_mapping(self._ptr, label, ranges._ptr) | |
277 | utils._handle_func_status( | |
f5567ea8 | 278 | status, "cannot add mapping to enumeration field class object" |
f0a42b33 | 279 | ) |
81447b5b | 280 | |
d47b87ac | 281 | def __iadd__(self, mappings): |
45c51519 PP |
282 | for label, ranges in mappings: |
283 | self.add_mapping(label, ranges) | |
81447b5b | 284 | |
d47b87ac | 285 | return self |
81447b5b | 286 | |
81447b5b | 287 | |
f0a42b33 FD |
288 | class _UnsignedEnumerationFieldClassConst( |
289 | _EnumerationFieldClassConst, _UnsignedIntegerFieldClassConst | |
cfbd7cf3 | 290 | ): |
f5567ea8 | 291 | _NAME = "Const unsigned enumeration" |
f0a42b33 FD |
292 | _borrow_mapping_ptr_by_label = staticmethod( |
293 | native_bt.field_class_enumeration_unsigned_borrow_mapping_by_label_const | |
294 | ) | |
295 | _borrow_mapping_ptr_by_index = staticmethod( | |
296 | native_bt.field_class_enumeration_unsigned_borrow_mapping_by_index_const | |
297 | ) | |
298 | _mapping_pycls = property(lambda _: _UnsignedEnumerationFieldClassMappingConst) | |
299 | _get_mapping_labels_for_value = staticmethod( | |
300 | native_bt.field_class_enumeration_unsigned_get_mapping_labels_for_value | |
301 | ) | |
302 | _check_int_type = staticmethod(utils._check_uint64) | |
81447b5b | 303 | |
45c51519 | 304 | |
f0a42b33 FD |
305 | class _UnsignedEnumerationFieldClass( |
306 | _UnsignedEnumerationFieldClassConst, | |
307 | _EnumerationFieldClass, | |
308 | _UnsignedIntegerFieldClass, | |
309 | ): | |
f5567ea8 | 310 | _NAME = "Unsigned enumeration" |
fc866000 | 311 | _range_set_pycls = bt2_integer_range_set.UnsignedIntegerRangeSet |
f0a42b33 | 312 | _add_mapping = staticmethod(native_bt.field_class_enumeration_unsigned_add_mapping) |
45c51519 | 313 | |
81447b5b | 314 | |
f0a42b33 FD |
315 | class _SignedEnumerationFieldClassConst( |
316 | _EnumerationFieldClassConst, _SignedIntegerFieldClassConst | |
317 | ): | |
f5567ea8 | 318 | _NAME = "Const signed enumeration" |
f0a42b33 FD |
319 | _borrow_mapping_ptr_by_label = staticmethod( |
320 | native_bt.field_class_enumeration_signed_borrow_mapping_by_label_const | |
321 | ) | |
322 | _borrow_mapping_ptr_by_index = staticmethod( | |
323 | native_bt.field_class_enumeration_signed_borrow_mapping_by_index_const | |
324 | ) | |
325 | _mapping_pycls = property(lambda _: _SignedEnumerationFieldClassMappingConst) | |
326 | _get_mapping_labels_for_value = staticmethod( | |
327 | native_bt.field_class_enumeration_signed_get_mapping_labels_for_value | |
328 | ) | |
329 | _check_int_type = staticmethod(utils._check_int64) | |
81447b5b PP |
330 | |
331 | ||
f0a42b33 FD |
332 | class _SignedEnumerationFieldClass( |
333 | _SignedEnumerationFieldClassConst, _EnumerationFieldClass, _SignedIntegerFieldClass | |
334 | ): | |
f5567ea8 | 335 | _NAME = "Signed enumeration" |
fc866000 | 336 | _range_set_pycls = bt2_integer_range_set.SignedIntegerRangeSet |
9c08c816 | 337 | _add_mapping = staticmethod(native_bt.field_class_enumeration_signed_add_mapping) |
81447b5b | 338 | |
81447b5b | 339 | |
f0a42b33 | 340 | class _StringFieldClassConst(_FieldClassConst): |
f5567ea8 | 341 | _NAME = "Const string" |
81447b5b | 342 | |
d47b87ac | 343 | |
f0a42b33 | 344 | class _StringFieldClass(_StringFieldClassConst, _FieldClass): |
f5567ea8 | 345 | _NAME = "String" |
81447b5b PP |
346 | |
347 | ||
f0a42b33 FD |
348 | class _StructureFieldClassMemberConst: |
349 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
350 | _create_field_class_from_const_ptr_and_get_ref | |
351 | ) | |
352 | _borrow_field_class_ptr = staticmethod( | |
353 | native_bt.field_class_structure_member_borrow_field_class_const | |
354 | ) | |
355 | _borrow_user_attributes_ptr = staticmethod( | |
356 | native_bt.field_class_structure_member_borrow_user_attributes_const | |
357 | ) | |
358 | _create_value_from_ptr_and_get_ref = staticmethod( | |
359 | bt2_value._create_from_const_ptr_and_get_ref | |
360 | ) | |
361 | ||
5783664e PP |
362 | def __init__(self, owning_struct_fc, member_ptr): |
363 | # this field class owns the member; keeping it here maintains | |
364 | # the member alive as members are not shared objects | |
365 | self._owning_struct_fc = owning_struct_fc | |
366 | self._ptr = member_ptr | |
45c51519 PP |
367 | |
368 | @property | |
369 | def name(self): | |
5783664e PP |
370 | name = native_bt.field_class_structure_member_get_name(self._ptr) |
371 | assert name is not None | |
372 | return name | |
45c51519 PP |
373 | |
374 | @property | |
375 | def field_class(self): | |
f0a42b33 | 376 | fc_ptr = self._borrow_field_class_ptr(self._ptr) |
5783664e | 377 | assert fc_ptr is not None |
f0a42b33 | 378 | return self._create_field_class_from_ptr_and_get_ref(fc_ptr) |
5783664e PP |
379 | |
380 | @property | |
381 | def user_attributes(self): | |
f0a42b33 | 382 | ptr = self._borrow_user_attributes_ptr(self._ptr) |
5783664e | 383 | assert ptr is not None |
f0a42b33 FD |
384 | return self._create_value_from_ptr_and_get_ref(ptr) |
385 | ||
386 | ||
387 | class _StructureFieldClassMember(_StructureFieldClassMemberConst): | |
388 | _borrow_field_class_ptr = staticmethod( | |
389 | native_bt.field_class_structure_member_borrow_field_class | |
390 | ) | |
391 | _borrow_user_attributes_ptr = staticmethod( | |
392 | native_bt.field_class_structure_member_borrow_user_attributes | |
393 | ) | |
394 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
395 | _create_field_class_from_ptr_and_get_ref | |
396 | ) | |
397 | _create_value_from_ptr_and_get_ref = staticmethod( | |
398 | bt2_value._create_from_ptr_and_get_ref | |
399 | ) | |
5783664e PP |
400 | |
401 | def _user_attributes(self, user_attributes): | |
402 | value = bt2_value.create_value(user_attributes) | |
403 | utils._check_type(value, bt2_value.MapValue) | |
404 | native_bt.field_class_structure_member_set_user_attributes( | |
405 | self._ptr, value._ptr | |
406 | ) | |
407 | ||
408 | _user_attributes = property(fset=_user_attributes) | |
45c51519 PP |
409 | |
410 | ||
f0a42b33 | 411 | class _StructureFieldClassConst(_FieldClassConst, collections.abc.Mapping): |
f5567ea8 | 412 | _NAME = "Const structure" |
f0a42b33 FD |
413 | _borrow_member_ptr_by_index = staticmethod( |
414 | native_bt.field_class_structure_borrow_member_by_index_const | |
415 | ) | |
416 | _borrow_member_ptr_by_name = staticmethod( | |
417 | native_bt.field_class_structure_borrow_member_by_name_const | |
418 | ) | |
419 | _structure_member_field_class_pycls = property( | |
420 | lambda _: _StructureFieldClassMemberConst | |
421 | ) | |
422 | ||
423 | def __len__(self): | |
424 | count = native_bt.field_class_structure_get_member_count(self._ptr) | |
425 | assert count >= 0 | |
426 | return count | |
427 | ||
428 | def __getitem__(self, key): | |
429 | if not isinstance(key, str): | |
430 | raise TypeError( | |
431 | "key must be a 'str' object, got '{}'".format(key.__class__.__name__) | |
432 | ) | |
433 | ||
434 | member_ptr = self._borrow_member_ptr_by_name(self._ptr, key) | |
435 | ||
436 | if member_ptr is None: | |
437 | raise KeyError(key) | |
438 | ||
439 | return self._structure_member_field_class_pycls(self, member_ptr) | |
440 | ||
441 | def __iter__(self): | |
442 | for idx in range(len(self)): | |
443 | member_ptr = self._borrow_member_ptr_by_index(self._ptr, idx) | |
444 | assert member_ptr is not None | |
445 | yield native_bt.field_class_structure_member_get_name(member_ptr) | |
446 | ||
447 | def member_at_index(self, index): | |
448 | utils._check_uint64(index) | |
449 | ||
450 | if index >= len(self): | |
451 | raise IndexError | |
452 | ||
453 | member_ptr = self._borrow_member_ptr_by_index(self._ptr, index) | |
454 | assert member_ptr is not None | |
455 | return self._structure_member_field_class_pycls(self, member_ptr) | |
456 | ||
457 | ||
458 | class _StructureFieldClass(_StructureFieldClassConst, _FieldClass): | |
f5567ea8 | 459 | _NAME = "Structure" |
f0a42b33 FD |
460 | _borrow_member_by_index = staticmethod( |
461 | native_bt.field_class_structure_borrow_member_by_index | |
462 | ) | |
463 | _borrow_member_ptr_by_name = staticmethod( | |
464 | native_bt.field_class_structure_borrow_member_by_name | |
465 | ) | |
466 | _structure_member_field_class_pycls = property(lambda _: _StructureFieldClassMember) | |
45c51519 | 467 | |
5783664e | 468 | def append_member(self, name, field_class, user_attributes=None): |
45c51519 PP |
469 | utils._check_str(name) |
470 | utils._check_type(field_class, _FieldClass) | |
471 | ||
472 | if name in self: | |
ce4923b0 | 473 | raise ValueError("duplicate member name '{}'".format(name)) |
45c51519 | 474 | |
5783664e PP |
475 | user_attributes_value = None |
476 | ||
477 | if user_attributes is not None: | |
478 | # check now that user attributes are valid | |
479 | user_attributes_value = bt2.create_value(user_attributes) | |
480 | ||
cfbd7cf3 FD |
481 | status = native_bt.field_class_structure_append_member( |
482 | self._ptr, name, field_class._ptr | |
483 | ) | |
484 | utils._handle_func_status( | |
f5567ea8 | 485 | status, "cannot append member to structure field class object" |
cfbd7cf3 | 486 | ) |
45c51519 | 487 | |
5783664e PP |
488 | if user_attributes is not None: |
489 | self[name]._user_attributes = user_attributes_value | |
490 | ||
45c51519 PP |
491 | def __iadd__(self, members): |
492 | for name, field_class in members: | |
493 | self.append_member(name, field_class) | |
81447b5b PP |
494 | |
495 | return self | |
496 | ||
45c51519 | 497 | |
f0a42b33 | 498 | class _OptionFieldClassConst(_FieldClassConst): |
f5567ea8 | 499 | _NAME = "Const option" |
f0a42b33 FD |
500 | _create_field_class_from_ptr_and_get_ref = staticmethod( |
501 | _create_field_class_from_const_ptr_and_get_ref | |
502 | ) | |
503 | _borrow_field_class_ptr = staticmethod( | |
504 | native_bt.field_class_option_borrow_field_class_const | |
505 | ) | |
81447b5b | 506 | |
cec0261d PP |
507 | @property |
508 | def field_class(self): | |
f0a42b33 FD |
509 | elem_fc_ptr = self._borrow_field_class_ptr(self._ptr) |
510 | return self._create_field_class_from_ptr_and_get_ref(elem_fc_ptr) | |
cec0261d | 511 | |
0aa006b7 PP |
512 | |
513 | class _OptionWithSelectorFieldClassConst(_OptionFieldClassConst): | |
f5567ea8 | 514 | _NAME = "Const option (with selector)" |
0aa006b7 | 515 | |
cec0261d PP |
516 | @property |
517 | def selector_field_path(self): | |
de821fe5 | 518 | ptr = native_bt.field_class_option_with_selector_field_borrow_selector_field_path_const( |
0aa006b7 PP |
519 | self._ptr |
520 | ) | |
cec0261d PP |
521 | if ptr is None: |
522 | return | |
523 | ||
5679964c | 524 | return bt2_field_path._FieldPathConst._create_from_ptr_and_get_ref(ptr) |
cec0261d PP |
525 | |
526 | ||
0aa006b7 | 527 | class _OptionWithBoolSelectorFieldClassConst(_OptionWithSelectorFieldClassConst): |
f5567ea8 | 528 | _NAME = "Const option (with boolean selector)" |
0aa006b7 PP |
529 | |
530 | @property | |
531 | def selector_is_reversed(self): | |
532 | return bool( | |
de821fe5 | 533 | native_bt.field_class_option_with_selector_field_bool_selector_is_reversed( |
0aa006b7 PP |
534 | self._ptr |
535 | ) | |
536 | ) | |
537 | ||
538 | ||
539 | class _OptionWithIntegerSelectorFieldClassConst(_OptionWithSelectorFieldClassConst): | |
f5567ea8 | 540 | _NAME = "Const option (with integer selector)" |
0aa006b7 PP |
541 | |
542 | @property | |
543 | def ranges(self): | |
544 | range_set_ptr = self._borrow_selector_ranges_ptr(self._ptr) | |
545 | assert range_set_ptr is not None | |
546 | return self._range_set_pycls._create_from_ptr_and_get_ref(range_set_ptr) | |
547 | ||
548 | ||
549 | class _OptionWithUnsignedIntegerSelectorFieldClassConst( | |
550 | _OptionWithIntegerSelectorFieldClassConst | |
551 | ): | |
f5567ea8 | 552 | _NAME = "Const option (with unsigned integer selector)" |
0aa006b7 PP |
553 | _range_set_pycls = bt2_integer_range_set._UnsignedIntegerRangeSetConst |
554 | _borrow_selector_ranges_ptr = staticmethod( | |
de821fe5 | 555 | native_bt.field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const |
0aa006b7 PP |
556 | ) |
557 | ||
558 | ||
559 | class _OptionWithSignedIntegerSelectorFieldClassConst( | |
560 | _OptionWithIntegerSelectorFieldClassConst | |
561 | ): | |
f5567ea8 | 562 | _NAME = "Const option (with signed integer selector)" |
0aa006b7 PP |
563 | _range_set_pycls = bt2_integer_range_set._SignedIntegerRangeSetConst |
564 | _borrow_selector_ranges_ptr = staticmethod( | |
de821fe5 | 565 | native_bt.field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const |
0aa006b7 PP |
566 | ) |
567 | ||
568 | ||
f0a42b33 | 569 | class _OptionFieldClass(_OptionFieldClassConst, _FieldClass): |
f5567ea8 | 570 | _NAME = "Option" |
f0a42b33 FD |
571 | _borrow_field_class_ptr = staticmethod( |
572 | native_bt.field_class_option_borrow_field_class | |
573 | ) | |
574 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
575 | _create_field_class_from_ptr_and_get_ref | |
576 | ) | |
577 | ||
578 | ||
0aa006b7 PP |
579 | class _OptionWithSelectorFieldClass( |
580 | _OptionWithSelectorFieldClassConst, _OptionFieldClass | |
581 | ): | |
f5567ea8 | 582 | _NAME = "Option (with selector)" |
0aa006b7 PP |
583 | |
584 | ||
585 | class _OptionWithBoolSelectorFieldClass( | |
586 | _OptionWithBoolSelectorFieldClassConst, _OptionWithSelectorFieldClass | |
587 | ): | |
f5567ea8 | 588 | _NAME = "Option (with boolean selector)" |
0aa006b7 PP |
589 | |
590 | def _selector_is_reversed(self, selector_is_reversed): | |
591 | utils._check_bool(selector_is_reversed) | |
de821fe5 | 592 | native_bt.field_class_option_with_selector_field_bool_set_selector_is_reversed( |
0aa006b7 PP |
593 | self._ptr, selector_is_reversed |
594 | ) | |
595 | ||
596 | _selector_is_reversed = property(fset=_selector_is_reversed) | |
597 | ||
598 | ||
599 | class _OptionWithIntegerSelectorFieldClass( | |
600 | _OptionWithIntegerSelectorFieldClassConst, _OptionWithSelectorFieldClass | |
601 | ): | |
f5567ea8 | 602 | _NAME = "Option (with integer selector)" |
0aa006b7 PP |
603 | |
604 | ||
605 | class _OptionWithUnsignedIntegerSelectorFieldClass( | |
606 | _OptionWithUnsignedIntegerSelectorFieldClassConst, | |
607 | _OptionWithIntegerSelectorFieldClass, | |
608 | ): | |
f5567ea8 | 609 | _NAME = "Option (with unsigned integer selector)" |
0aa006b7 PP |
610 | |
611 | ||
612 | class _OptionWithSignedIntegerSelectorFieldClass( | |
613 | _OptionWithSignedIntegerSelectorFieldClassConst, | |
614 | _OptionWithIntegerSelectorFieldClass, | |
615 | ): | |
f5567ea8 | 616 | _NAME = "Option (with signed integer selector)" |
0aa006b7 PP |
617 | |
618 | ||
f0a42b33 FD |
619 | class _VariantFieldClassOptionConst: |
620 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
621 | _create_field_class_from_const_ptr_and_get_ref | |
622 | ) | |
623 | _borrow_field_class_ptr = staticmethod( | |
624 | native_bt.field_class_variant_option_borrow_field_class_const | |
625 | ) | |
626 | _borrow_user_attributes_ptr = staticmethod( | |
627 | native_bt.field_class_variant_option_borrow_user_attributes_const | |
628 | ) | |
629 | _create_value_from_ptr_and_get_ref = staticmethod( | |
630 | bt2_value._create_from_const_ptr_and_get_ref | |
631 | ) | |
632 | ||
5783664e PP |
633 | def __init__(self, owning_var_fc, option_ptr): |
634 | # this field class owns the option; keeping it here maintains | |
635 | # the option alive as options are not shared objects | |
636 | self._owning_var_fc = owning_var_fc | |
637 | self._ptr = option_ptr | |
81447b5b | 638 | |
45c51519 PP |
639 | @property |
640 | def name(self): | |
5783664e PP |
641 | name = native_bt.field_class_variant_option_get_name(self._ptr) |
642 | assert name is not None | |
643 | return name | |
81447b5b | 644 | |
45c51519 PP |
645 | @property |
646 | def field_class(self): | |
f0a42b33 | 647 | fc_ptr = self._borrow_field_class_ptr(self._ptr) |
5783664e | 648 | assert fc_ptr is not None |
f0a42b33 | 649 | return self._create_field_class_from_ptr_and_get_ref(fc_ptr) |
81447b5b | 650 | |
5783664e PP |
651 | @property |
652 | def user_attributes(self): | |
f0a42b33 | 653 | ptr = self._borrow_user_attributes_ptr(self._ptr) |
5783664e | 654 | assert ptr is not None |
f0a42b33 FD |
655 | return self._create_value_from_ptr_and_get_ref(ptr) |
656 | ||
657 | ||
658 | class _VariantFieldClassOption(_VariantFieldClassOptionConst): | |
659 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
660 | _create_field_class_from_ptr_and_get_ref | |
661 | ) | |
662 | _borrow_field_class_ptr = staticmethod( | |
663 | native_bt.field_class_variant_option_borrow_field_class | |
664 | ) | |
665 | _borrow_user_attributes_ptr = staticmethod( | |
70a79f65 | 666 | native_bt.field_class_variant_option_borrow_user_attributes |
f0a42b33 FD |
667 | ) |
668 | _create_value_from_ptr_and_get_ref = staticmethod( | |
669 | bt2_value._create_from_ptr_and_get_ref | |
670 | ) | |
81447b5b | 671 | |
5783664e PP |
672 | def _user_attributes(self, user_attributes): |
673 | value = bt2_value.create_value(user_attributes) | |
674 | utils._check_type(value, bt2_value.MapValue) | |
675 | native_bt.field_class_variant_option_set_user_attributes(self._ptr, value._ptr) | |
81447b5b | 676 | |
5783664e | 677 | _user_attributes = property(fset=_user_attributes) |
81447b5b PP |
678 | |
679 | ||
fabfe034 | 680 | class _VariantFieldClassWithIntegerSelectorOptionConst(_VariantFieldClassOptionConst): |
f0a42b33 FD |
681 | def __init__(self, owning_var_fc, spec_opt_ptr): |
682 | self._spec_ptr = spec_opt_ptr | |
683 | super().__init__(owning_var_fc, self._as_option_ptr(spec_opt_ptr)) | |
684 | ||
685 | @property | |
686 | def ranges(self): | |
687 | range_set_ptr = self._borrow_ranges_ptr(self._spec_ptr) | |
688 | assert range_set_ptr is not None | |
ef9cc185 | 689 | return self._range_set_pycls._create_from_ptr_and_get_ref(range_set_ptr) |
f0a42b33 FD |
690 | |
691 | ||
fabfe034 PP |
692 | class _VariantFieldClassWithIntegerSelectorOption( |
693 | _VariantFieldClassWithIntegerSelectorOptionConst, _VariantFieldClassOption | |
f0a42b33 FD |
694 | ): |
695 | pass | |
696 | ||
697 | ||
fabfe034 PP |
698 | class _VariantFieldClassWithSignedIntegerSelectorOptionConst( |
699 | _VariantFieldClassWithIntegerSelectorOptionConst | |
f0a42b33 FD |
700 | ): |
701 | _as_option_ptr = staticmethod( | |
de821fe5 | 702 | native_bt.field_class_variant_with_selector_field_integer_signed_option_as_option_const |
f0a42b33 FD |
703 | ) |
704 | _borrow_ranges_ptr = staticmethod( | |
de821fe5 | 705 | native_bt.field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const |
f0a42b33 | 706 | ) |
fc866000 | 707 | _range_set_pycls = bt2_integer_range_set._SignedIntegerRangeSetConst |
f0a42b33 FD |
708 | |
709 | ||
fabfe034 PP |
710 | class _VariantFieldClassWithSignedIntegerSelectorOption( |
711 | _VariantFieldClassWithSignedIntegerSelectorOptionConst, | |
712 | _VariantFieldClassWithIntegerSelectorOption, | |
f0a42b33 FD |
713 | ): |
714 | pass | |
715 | ||
716 | ||
fabfe034 PP |
717 | class _VariantFieldClassWithUnsignedIntegerSelectorOptionConst( |
718 | _VariantFieldClassWithIntegerSelectorOptionConst | |
f0a42b33 FD |
719 | ): |
720 | _as_option_ptr = staticmethod( | |
de821fe5 | 721 | native_bt.field_class_variant_with_selector_field_integer_unsigned_option_as_option_const |
f0a42b33 FD |
722 | ) |
723 | _borrow_ranges_ptr = staticmethod( | |
de821fe5 | 724 | native_bt.field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const |
f0a42b33 | 725 | ) |
fc866000 | 726 | _range_set_pycls = bt2_integer_range_set._UnsignedIntegerRangeSetConst |
f0a42b33 FD |
727 | |
728 | ||
fabfe034 PP |
729 | class _VariantFieldClassWithUnsignedIntegerSelectorOption( |
730 | _VariantFieldClassWithUnsignedIntegerSelectorOptionConst, | |
731 | _VariantFieldClassWithIntegerSelectorOption, | |
f0a42b33 FD |
732 | ): |
733 | pass | |
734 | ||
735 | ||
736 | class _VariantFieldClassConst(_FieldClassConst, collections.abc.Mapping): | |
f5567ea8 | 737 | _NAME = "Const variant" |
f0a42b33 | 738 | _borrow_option_ptr_by_name = staticmethod( |
cfbd7cf3 FD |
739 | native_bt.field_class_variant_borrow_option_by_name_const |
740 | ) | |
f0a42b33 | 741 | _borrow_option_ptr_by_index = staticmethod( |
cfbd7cf3 FD |
742 | native_bt.field_class_variant_borrow_option_by_index_const |
743 | ) | |
f0a42b33 | 744 | _variant_option_pycls = _VariantFieldClassOptionConst |
811644b8 | 745 | |
45c51519 PP |
746 | @staticmethod |
747 | def _as_option_ptr(opt_ptr): | |
748 | return opt_ptr | |
749 | ||
750 | def _create_option_from_ptr(self, opt_ptr): | |
f0a42b33 | 751 | return self._variant_option_pycls(self, opt_ptr) |
45c51519 PP |
752 | |
753 | def __len__(self): | |
754 | count = native_bt.field_class_variant_get_option_count(self._ptr) | |
755 | assert count >= 0 | |
756 | return count | |
757 | ||
758 | def __getitem__(self, key): | |
759 | if not isinstance(key, str): | |
cfbd7cf3 FD |
760 | raise TypeError( |
761 | "key must be a 'str' object, got '{}'".format(key.__class__.__name__) | |
762 | ) | |
45c51519 | 763 | |
f0a42b33 | 764 | opt_ptr = self._borrow_option_ptr_by_name(self._ptr, key) |
45c51519 PP |
765 | |
766 | if opt_ptr is None: | |
767 | raise KeyError(key) | |
768 | ||
769 | return self._create_option_from_ptr(opt_ptr) | |
770 | ||
771 | def __iter__(self): | |
772 | for idx in range(len(self)): | |
f0a42b33 | 773 | opt_ptr = self._borrow_option_ptr_by_index(self._ptr, idx) |
45c51519 PP |
774 | assert opt_ptr is not None |
775 | base_opt_ptr = self._as_option_ptr(opt_ptr) | |
776 | yield native_bt.field_class_variant_option_get_name(base_opt_ptr) | |
811644b8 | 777 | |
d47b87ac | 778 | def option_at_index(self, index): |
45c51519 PP |
779 | utils._check_uint64(index) |
780 | ||
781 | if index >= len(self): | |
782 | raise IndexError | |
783 | ||
f0a42b33 | 784 | opt_ptr = self._borrow_option_ptr_by_index(self._ptr, index) |
45c51519 PP |
785 | assert opt_ptr is not None |
786 | return self._create_option_from_ptr(opt_ptr) | |
787 | ||
788 | ||
f0a42b33 | 789 | class _VariantFieldClass(_VariantFieldClassConst, _FieldClass, collections.abc.Mapping): |
f5567ea8 | 790 | _NAME = "Variant" |
f0a42b33 FD |
791 | _borrow_option_ptr_by_name = staticmethod( |
792 | native_bt.field_class_variant_borrow_option_by_name | |
793 | ) | |
794 | _borrow_option_ptr_by_index = staticmethod( | |
795 | native_bt.field_class_variant_borrow_option_by_index | |
796 | ) | |
797 | _variant_option_pycls = _VariantFieldClassOption | |
798 | ||
799 | ||
800 | class _VariantFieldClassWithoutSelectorConst(_VariantFieldClassConst): | |
f5567ea8 | 801 | _NAME = "Const variant (without selector)" |
f0a42b33 FD |
802 | |
803 | ||
804 | class _VariantFieldClassWithoutSelector( | |
805 | _VariantFieldClassWithoutSelectorConst, _VariantFieldClass | |
806 | ): | |
f5567ea8 | 807 | _NAME = "Variant (without selector)" |
45c51519 | 808 | |
5783664e | 809 | def append_option(self, name, field_class, user_attributes=None): |
45c51519 PP |
810 | utils._check_str(name) |
811 | utils._check_type(field_class, _FieldClass) | |
812 | ||
813 | if name in self: | |
ce4923b0 | 814 | raise ValueError("duplicate option name '{}'".format(name)) |
45c51519 | 815 | |
5783664e PP |
816 | user_attributes_value = None |
817 | ||
818 | if user_attributes is not None: | |
819 | # check now that user attributes are valid | |
820 | user_attributes_value = bt2.create_value(user_attributes) | |
821 | ||
cfbd7cf3 FD |
822 | status = native_bt.field_class_variant_without_selector_append_option( |
823 | self._ptr, name, field_class._ptr | |
824 | ) | |
825 | utils._handle_func_status( | |
f5567ea8 | 826 | status, "cannot append option to variant field class object" |
cfbd7cf3 | 827 | ) |
45c51519 | 828 | |
5783664e PP |
829 | if user_attributes is not None: |
830 | self[name]._user_attributes = user_attributes_value | |
831 | ||
45c51519 PP |
832 | def __iadd__(self, options): |
833 | for name, field_class in options: | |
834 | self.append_option(name, field_class) | |
835 | ||
836 | return self | |
837 | ||
838 | ||
fabfe034 | 839 | class _VariantFieldClassWithIntegerSelectorConst(_VariantFieldClassConst): |
f5567ea8 | 840 | _NAME = "Const variant (with selector)" |
81447b5b PP |
841 | |
842 | @property | |
d47b87ac | 843 | def selector_field_path(self): |
de821fe5 | 844 | ptr = native_bt.field_class_variant_with_selector_field_borrow_selector_field_path_const( |
cfbd7cf3 FD |
845 | self._ptr |
846 | ) | |
45c51519 | 847 | |
d47b87ac | 848 | if ptr is None: |
811644b8 PP |
849 | return |
850 | ||
5679964c | 851 | return bt2_field_path._FieldPathConst._create_from_ptr_and_get_ref(ptr) |
81447b5b | 852 | |
f0a42b33 | 853 | |
fabfe034 PP |
854 | class _VariantFieldClassWithIntegerSelector( |
855 | _VariantFieldClassWithIntegerSelectorConst, _VariantFieldClass | |
f0a42b33 | 856 | ): |
f5567ea8 | 857 | _NAME = "Variant (with selector)" |
f0a42b33 | 858 | |
5783664e | 859 | def append_option(self, name, field_class, ranges, user_attributes=None): |
45c51519 PP |
860 | utils._check_str(name) |
861 | utils._check_type(field_class, _FieldClass) | |
ef9cc185 | 862 | utils._check_type(ranges, self._variant_option_pycls._range_set_pycls) |
45c51519 PP |
863 | |
864 | if name in self: | |
ce4923b0 | 865 | raise ValueError("duplicate option name '{}'".format(name)) |
45c51519 PP |
866 | |
867 | if len(ranges) == 0: | |
f5567ea8 | 868 | raise ValueError("range set is empty") |
45c51519 | 869 | |
5783664e PP |
870 | user_attributes_value = None |
871 | ||
872 | if user_attributes is not None: | |
873 | # check now that user attributes are valid | |
874 | user_attributes_value = bt2.create_value(user_attributes) | |
875 | ||
45c51519 PP |
876 | # TODO: check overlaps (precondition of self._append_option()) |
877 | ||
878 | status = self._append_option(self._ptr, name, field_class._ptr, ranges._ptr) | |
cfbd7cf3 | 879 | utils._handle_func_status( |
f5567ea8 | 880 | status, "cannot append option to variant field class object" |
cfbd7cf3 | 881 | ) |
45c51519 | 882 | |
5783664e PP |
883 | if user_attributes is not None: |
884 | self[name]._user_attributes = user_attributes_value | |
885 | ||
45c51519 PP |
886 | def __iadd__(self, options): |
887 | for name, field_class, ranges in options: | |
888 | self.append_option(name, field_class, ranges) | |
889 | ||
890 | return self | |
891 | ||
892 | ||
fabfe034 PP |
893 | class _VariantFieldClassWithUnsignedIntegerSelectorConst( |
894 | _VariantFieldClassWithIntegerSelectorConst | |
895 | ): | |
f5567ea8 | 896 | _NAME = "Const variant (with unsigned integer selector)" |
f0a42b33 | 897 | _borrow_option_ptr_by_name = staticmethod( |
de821fe5 | 898 | native_bt.field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const |
cfbd7cf3 | 899 | ) |
f0a42b33 | 900 | _borrow_option_ptr_by_index = staticmethod( |
de821fe5 | 901 | native_bt.field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const |
cfbd7cf3 | 902 | ) |
fabfe034 | 903 | _variant_option_pycls = _VariantFieldClassWithUnsignedIntegerSelectorOptionConst |
f0a42b33 | 904 | _as_option_ptr = staticmethod(_variant_option_pycls._as_option_ptr) |
45c51519 | 905 | |
81447b5b | 906 | |
fabfe034 PP |
907 | class _VariantFieldClassWithUnsignedIntegerSelector( |
908 | _VariantFieldClassWithUnsignedIntegerSelectorConst, | |
909 | _VariantFieldClassWithIntegerSelector, | |
f0a42b33 | 910 | ): |
f5567ea8 | 911 | _NAME = "Variant (with unsigned integer selector)" |
fabfe034 | 912 | _variant_option_pycls = _VariantFieldClassWithUnsignedIntegerSelectorOption |
f0a42b33 | 913 | _as_option_ptr = staticmethod(_variant_option_pycls._as_option_ptr) |
8863ba6f | 914 | _append_option = staticmethod( |
de821fe5 | 915 | native_bt.field_class_variant_with_selector_field_integer_unsigned_append_option |
8863ba6f | 916 | ) |
f0a42b33 FD |
917 | |
918 | ||
fabfe034 PP |
919 | class _VariantFieldClassWithSignedIntegerSelectorConst( |
920 | _VariantFieldClassWithIntegerSelectorConst | |
921 | ): | |
f5567ea8 | 922 | _NAME = "Const variant (with signed integer selector)" |
f0a42b33 | 923 | _borrow_option_ptr_by_name = staticmethod( |
de821fe5 | 924 | native_bt.field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const |
cfbd7cf3 | 925 | ) |
f0a42b33 | 926 | _borrow_option_ptr_by_index = staticmethod( |
de821fe5 | 927 | native_bt.field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const |
cfbd7cf3 | 928 | ) |
fabfe034 | 929 | _variant_option_pycls = _VariantFieldClassWithSignedIntegerSelectorOptionConst |
f0a42b33 FD |
930 | _as_option_ptr = staticmethod(_variant_option_pycls._as_option_ptr) |
931 | ||
932 | ||
fabfe034 PP |
933 | class _VariantFieldClassWithSignedIntegerSelector( |
934 | _VariantFieldClassWithSignedIntegerSelectorConst, | |
935 | _VariantFieldClassWithIntegerSelector, | |
f0a42b33 | 936 | ): |
f5567ea8 | 937 | _NAME = "Variant (with signed integer selector)" |
fabfe034 | 938 | _variant_option_pycls = _VariantFieldClassWithSignedIntegerSelectorOption |
f0a42b33 | 939 | _as_option_ptr = staticmethod(_variant_option_pycls._as_option_ptr) |
8863ba6f | 940 | _append_option = staticmethod( |
de821fe5 | 941 | native_bt.field_class_variant_with_selector_field_integer_signed_append_option |
8863ba6f | 942 | ) |
811644b8 | 943 | |
81447b5b | 944 | |
f0a42b33 FD |
945 | class _ArrayFieldClassConst(_FieldClassConst): |
946 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
947 | _create_field_class_from_const_ptr_and_get_ref | |
948 | ) | |
949 | _borrow_element_field_class = staticmethod( | |
950 | native_bt.field_class_array_borrow_element_field_class_const | |
951 | ) | |
952 | ||
d47b87ac SM |
953 | @property |
954 | def element_field_class(self): | |
f0a42b33 FD |
955 | elem_fc_ptr = self._borrow_element_field_class(self._ptr) |
956 | return self._create_field_class_from_ptr_and_get_ref(elem_fc_ptr) | |
957 | ||
958 | ||
959 | class _ArrayFieldClass(_ArrayFieldClassConst, _FieldClass): | |
960 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
961 | _create_field_class_from_ptr_and_get_ref | |
962 | ) | |
963 | _borrow_element_field_class = staticmethod( | |
964 | native_bt.field_class_array_borrow_element_field_class | |
965 | ) | |
81447b5b | 966 | |
81447b5b | 967 | |
f0a42b33 | 968 | class _StaticArrayFieldClassConst(_ArrayFieldClassConst): |
f5567ea8 | 969 | _NAME = "Const static array" |
f0a42b33 | 970 | |
81447b5b PP |
971 | @property |
972 | def length(self): | |
9c08c816 | 973 | return native_bt.field_class_array_static_get_length(self._ptr) |
81447b5b PP |
974 | |
975 | ||
f0a42b33 | 976 | class _StaticArrayFieldClass(_StaticArrayFieldClassConst, _ArrayFieldClass): |
f5567ea8 | 977 | _NAME = "Static array" |
f0a42b33 FD |
978 | |
979 | ||
980 | class _DynamicArrayFieldClassConst(_ArrayFieldClassConst): | |
f5567ea8 | 981 | _NAME = "Const dynamic array" |
f0a42b33 | 982 | |
81b8fa44 PP |
983 | |
984 | class _DynamicArrayWithLengthFieldFieldClassConst(_DynamicArrayFieldClassConst): | |
f5567ea8 | 985 | _NAME = "Const dynamic array (with length field)" |
81b8fa44 | 986 | |
d47b87ac SM |
987 | @property |
988 | def length_field_path(self): | |
81b8fa44 | 989 | ptr = native_bt.field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
cfbd7cf3 FD |
990 | self._ptr |
991 | ) | |
d47b87ac SM |
992 | if ptr is None: |
993 | return | |
81447b5b | 994 | |
5679964c | 995 | return bt2_field_path._FieldPathConst._create_from_ptr_and_get_ref(ptr) |
81447b5b | 996 | |
81447b5b | 997 | |
f0a42b33 | 998 | class _DynamicArrayFieldClass(_DynamicArrayFieldClassConst, _ArrayFieldClass): |
f5567ea8 | 999 | _NAME = "Dynamic array" |
f0a42b33 FD |
1000 | |
1001 | ||
81b8fa44 PP |
1002 | class _DynamicArrayWithLengthFieldFieldClass( |
1003 | _DynamicArrayWithLengthFieldFieldClassConst, _DynamicArrayFieldClass | |
1004 | ): | |
f5567ea8 | 1005 | _NAME = "Dynamic array (with length field)" |
81b8fa44 PP |
1006 | |
1007 | ||
f0a42b33 FD |
1008 | _FIELD_CLASS_TYPE_TO_CONST_OBJ = { |
1009 | native_bt.FIELD_CLASS_TYPE_BOOL: _BoolFieldClassConst, | |
1010 | native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClassConst, | |
1011 | native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClassConst, | |
1012 | native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClassConst, | |
fe4df857 FD |
1013 | native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClassConst, |
1014 | native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClassConst, | |
f0a42b33 FD |
1015 | native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClassConst, |
1016 | native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClassConst, | |
1017 | native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClassConst, | |
1018 | native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClassConst, | |
1019 | native_bt.FIELD_CLASS_TYPE_STATIC_ARRAY: _StaticArrayFieldClassConst, | |
81b8fa44 PP |
1020 | native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: _DynamicArrayFieldClassConst, |
1021 | native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: _DynamicArrayWithLengthFieldFieldClassConst, | |
de821fe5 PP |
1022 | native_bt.FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD: _OptionFieldClassConst, |
1023 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD: _OptionWithBoolSelectorFieldClassConst, | |
1024 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: _OptionWithUnsignedIntegerSelectorFieldClassConst, | |
1025 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD: _OptionWithSignedIntegerSelectorFieldClassConst, | |
1026 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: _VariantFieldClassWithoutSelectorConst, | |
1027 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: _VariantFieldClassWithUnsignedIntegerSelectorConst, | |
1028 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: _VariantFieldClassWithSignedIntegerSelectorConst, | |
f0a42b33 FD |
1029 | } |
1030 | ||
3cdfbaea | 1031 | _FIELD_CLASS_TYPE_TO_OBJ = { |
aae30e61 | 1032 | native_bt.FIELD_CLASS_TYPE_BOOL: _BoolFieldClass, |
ead8c3d4 | 1033 | native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClass, |
d47b87ac SM |
1034 | native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass, |
1035 | native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClass, | |
fe4df857 FD |
1036 | native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClass, |
1037 | native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClass, | |
d47b87ac SM |
1038 | native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClass, |
1039 | native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClass, | |
1040 | native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClass, | |
3cdfbaea | 1041 | native_bt.FIELD_CLASS_TYPE_STRUCTURE: _StructureFieldClass, |
d47b87ac | 1042 | native_bt.FIELD_CLASS_TYPE_STATIC_ARRAY: _StaticArrayFieldClass, |
81b8fa44 PP |
1043 | native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: _DynamicArrayFieldClass, |
1044 | native_bt.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: _DynamicArrayWithLengthFieldFieldClass, | |
de821fe5 PP |
1045 | native_bt.FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD: _OptionFieldClass, |
1046 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD: _OptionWithBoolSelectorFieldClass, | |
1047 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: _OptionWithUnsignedIntegerSelectorFieldClass, | |
1048 | native_bt.FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD: _OptionWithSignedIntegerSelectorFieldClass, | |
1049 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD: _VariantFieldClassWithoutSelector, | |
1050 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD: _VariantFieldClassWithUnsignedIntegerSelector, | |
1051 | native_bt.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD: _VariantFieldClassWithSignedIntegerSelector, | |
81447b5b | 1052 | } |