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