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