| 1 | /* |
| 2 | * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP |
| 8 | #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <type_traits> |
| 12 | |
| 13 | #include <babeltrace2/babeltrace.h> |
| 14 | |
| 15 | #include "common/assert.h" |
| 16 | #include "cpp-common/bt2s/optional.hpp" |
| 17 | |
| 18 | #include "borrowed-object-iterator.hpp" |
| 19 | #include "borrowed-object.hpp" |
| 20 | #include "exc.hpp" |
| 21 | #include "field-path.hpp" |
| 22 | #include "integer-range-set.hpp" |
| 23 | #include "internal/utils.hpp" |
| 24 | #include "shared-object.hpp" |
| 25 | #include "value.hpp" |
| 26 | |
| 27 | namespace bt2 { |
| 28 | namespace internal { |
| 29 | |
| 30 | struct FieldClassRefFuncs final |
| 31 | { |
| 32 | static void get(const bt_field_class * const libObjPtr) noexcept |
| 33 | { |
| 34 | bt_field_class_get_ref(libObjPtr); |
| 35 | } |
| 36 | |
| 37 | static void put(const bt_field_class * const libObjPtr) noexcept |
| 38 | { |
| 39 | bt_field_class_put_ref(libObjPtr); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | template <typename LibObjT> |
| 44 | struct CommonFieldClassSpec; |
| 45 | |
| 46 | /* Functions specific to mutable field classes */ |
| 47 | template <> |
| 48 | struct CommonFieldClassSpec<bt_field_class> final |
| 49 | { |
| 50 | static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept |
| 51 | { |
| 52 | return bt_field_class_borrow_user_attributes(libObjPtr); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | /* Functions specific to constant field classes */ |
| 57 | template <> |
| 58 | struct CommonFieldClassSpec<const bt_field_class> final |
| 59 | { |
| 60 | static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept |
| 61 | { |
| 62 | return bt_field_class_borrow_user_attributes_const(libObjPtr); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | } /* namespace internal */ |
| 67 | |
| 68 | template <typename ObjT, typename LibObjT> |
| 69 | using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>; |
| 70 | |
| 71 | template <typename LibObjT> |
| 72 | class CommonBitArrayFieldClass; |
| 73 | |
| 74 | template <typename LibObjT> |
| 75 | class CommonIntegerFieldClass; |
| 76 | |
| 77 | template <typename LibObjT> |
| 78 | class ConstEnumerationFieldClassMapping; |
| 79 | |
| 80 | template <typename LibObjT> |
| 81 | class CommonBaseEnumerationFieldClass; |
| 82 | |
| 83 | template <typename LibObjT, typename MappingT> |
| 84 | class CommonEnumerationFieldClass; |
| 85 | |
| 86 | template <typename LibObjT> |
| 87 | class CommonStructureFieldClass; |
| 88 | |
| 89 | template <typename LibObjT> |
| 90 | class CommonArrayFieldClass; |
| 91 | |
| 92 | template <typename LibObjT> |
| 93 | class CommonStaticArrayFieldClass; |
| 94 | |
| 95 | template <typename LibObjT> |
| 96 | class CommonDynamicArrayWithLengthFieldClass; |
| 97 | |
| 98 | template <typename LibObjT> |
| 99 | class CommonOptionFieldClass; |
| 100 | |
| 101 | template <typename LibObjT> |
| 102 | class CommonOptionWithSelectorFieldClass; |
| 103 | |
| 104 | template <typename LibObjT> |
| 105 | class CommonOptionWithBoolSelectorFieldClass; |
| 106 | |
| 107 | template <typename LibObjT> |
| 108 | class CommonVariantFieldClass; |
| 109 | |
| 110 | template <typename LibObjT, typename RangeSetT> |
| 111 | class CommonOptionWithIntegerSelectorFieldClass; |
| 112 | |
| 113 | template <typename LibObjT> |
| 114 | class CommonVariantWithoutSelectorFieldClass; |
| 115 | |
| 116 | template <typename LibObjT> |
| 117 | class CommonVariantWithSelectorFieldClass; |
| 118 | |
| 119 | template <typename LibObjT> |
| 120 | class ConstVariantWithIntegerSelectorFieldClassOption; |
| 121 | |
| 122 | template <typename LibObjT, typename RangeSetT> |
| 123 | class CommonVariantWithIntegerSelectorFieldClass; |
| 124 | |
| 125 | template <typename LibObjT> |
| 126 | class CommonEventClass; |
| 127 | |
| 128 | template <typename LibObjT> |
| 129 | class CommonStreamClass; |
| 130 | |
| 131 | template <typename LibObjT> |
| 132 | class CommonTraceClass; |
| 133 | |
| 134 | enum class FieldClassType |
| 135 | { |
| 136 | BOOL = BT_FIELD_CLASS_TYPE_BOOL, |
| 137 | BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY, |
| 138 | UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER, |
| 139 | SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER, |
| 140 | UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
| 141 | SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
| 142 | SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, |
| 143 | DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, |
| 144 | STRING = BT_FIELD_CLASS_TYPE_STRING, |
| 145 | STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE, |
| 146 | STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY, |
| 147 | DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, |
| 148 | DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, |
| 149 | OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD, |
| 150 | OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, |
| 151 | OPTION_WITH_UNSIGNED_INTEGER_SELECTOR = |
| 152 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
| 153 | OPTION_WITH_SIGNED_INTEGER_SELECTOR = |
| 154 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
| 155 | VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, |
| 156 | VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR = |
| 157 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
| 158 | VARIANT_WITH_SIGNED_INTEGER_SELECTOR = |
| 159 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
| 160 | }; |
| 161 | |
| 162 | template <typename LibObjT> |
| 163 | class CommonFieldClass : public BorrowedObject<LibObjT> |
| 164 | { |
| 165 | private: |
| 166 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 167 | |
| 168 | protected: |
| 169 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
| 170 | using _ThisCommonFieldClass = CommonFieldClass<LibObjT>; |
| 171 | |
| 172 | public: |
| 173 | using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>; |
| 174 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 175 | |
| 176 | explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 177 | { |
| 178 | } |
| 179 | |
| 180 | template <typename OtherLibObjT> |
| 181 | CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc} |
| 182 | { |
| 183 | } |
| 184 | |
| 185 | template <typename OtherLibObjT> |
| 186 | CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept |
| 187 | { |
| 188 | _ThisBorrowedObject::operator=(fc); |
| 189 | return *this; |
| 190 | } |
| 191 | |
| 192 | CommonFieldClass<const bt_field_class> asConst() const noexcept |
| 193 | { |
| 194 | return CommonFieldClass<const bt_field_class> {*this}; |
| 195 | } |
| 196 | |
| 197 | FieldClassType type() const noexcept |
| 198 | { |
| 199 | return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr())); |
| 200 | } |
| 201 | |
| 202 | bool isBool() const noexcept |
| 203 | { |
| 204 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL); |
| 205 | } |
| 206 | |
| 207 | bool isBitArray() const noexcept |
| 208 | { |
| 209 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY); |
| 210 | } |
| 211 | |
| 212 | bool isInteger() const noexcept |
| 213 | { |
| 214 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER); |
| 215 | } |
| 216 | |
| 217 | bool isUnsignedInteger() const noexcept |
| 218 | { |
| 219 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
| 220 | } |
| 221 | |
| 222 | bool isSignedInteger() const noexcept |
| 223 | { |
| 224 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); |
| 225 | } |
| 226 | |
| 227 | bool isEnumeration() const noexcept |
| 228 | { |
| 229 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION); |
| 230 | } |
| 231 | |
| 232 | bool isUnsignedEnumeration() const noexcept |
| 233 | { |
| 234 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); |
| 235 | } |
| 236 | |
| 237 | bool isSignedEnumeration() const noexcept |
| 238 | { |
| 239 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); |
| 240 | } |
| 241 | |
| 242 | bool isReal() const noexcept |
| 243 | { |
| 244 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL); |
| 245 | } |
| 246 | |
| 247 | bool isSinglePrecisionReal() const noexcept |
| 248 | { |
| 249 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); |
| 250 | } |
| 251 | |
| 252 | bool isDoublePrecisionReal() const noexcept |
| 253 | { |
| 254 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); |
| 255 | } |
| 256 | |
| 257 | bool isString() const noexcept |
| 258 | { |
| 259 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING); |
| 260 | } |
| 261 | |
| 262 | bool isStructure() const noexcept |
| 263 | { |
| 264 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE); |
| 265 | } |
| 266 | |
| 267 | bool isArray() const noexcept |
| 268 | { |
| 269 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY); |
| 270 | } |
| 271 | |
| 272 | bool isStaticArray() const noexcept |
| 273 | { |
| 274 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY); |
| 275 | } |
| 276 | |
| 277 | bool isDynamicArray() const noexcept |
| 278 | { |
| 279 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY); |
| 280 | } |
| 281 | |
| 282 | bool isDynamicArrayWithoutLength() const noexcept |
| 283 | { |
| 284 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD); |
| 285 | } |
| 286 | |
| 287 | bool isDynamicArrayWithLength() const noexcept |
| 288 | { |
| 289 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); |
| 290 | } |
| 291 | |
| 292 | bool isOption() const noexcept |
| 293 | { |
| 294 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION); |
| 295 | } |
| 296 | |
| 297 | bool isOptionWithoutSelector() const noexcept |
| 298 | { |
| 299 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD); |
| 300 | } |
| 301 | |
| 302 | bool isOptionWithSelector() const noexcept |
| 303 | { |
| 304 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD); |
| 305 | } |
| 306 | |
| 307 | bool isOptionWithBoolSelector() const noexcept |
| 308 | { |
| 309 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD); |
| 310 | } |
| 311 | |
| 312 | bool isOptionWithIntegerSelector() const noexcept |
| 313 | { |
| 314 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD); |
| 315 | } |
| 316 | |
| 317 | bool isOptionWithUnsignedIntegerSelector() const noexcept |
| 318 | { |
| 319 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); |
| 320 | } |
| 321 | |
| 322 | bool isOptionWithSignedIntegerSelector() const noexcept |
| 323 | { |
| 324 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD); |
| 325 | } |
| 326 | |
| 327 | bool isVariant() const noexcept |
| 328 | { |
| 329 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT); |
| 330 | } |
| 331 | |
| 332 | bool isVariantWithoutSelector() const noexcept |
| 333 | { |
| 334 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); |
| 335 | } |
| 336 | |
| 337 | bool isVariantWithSelector() const noexcept |
| 338 | { |
| 339 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD); |
| 340 | } |
| 341 | |
| 342 | bool isVariantWithIntegerSelector() const noexcept |
| 343 | { |
| 344 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD); |
| 345 | } |
| 346 | |
| 347 | bool isVariantWithUnsignedIntegerSelector() const noexcept |
| 348 | { |
| 349 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); |
| 350 | } |
| 351 | |
| 352 | bool isVariantWithSignedIntegerSelector() const noexcept |
| 353 | { |
| 354 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD); |
| 355 | } |
| 356 | |
| 357 | template <typename FieldClassT> |
| 358 | FieldClassT as() const noexcept |
| 359 | { |
| 360 | return FieldClassT {this->libObjPtr()}; |
| 361 | } |
| 362 | |
| 363 | CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept; |
| 364 | CommonIntegerFieldClass<LibObjT> asInteger() const noexcept; |
| 365 | CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept; |
| 366 | CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping< |
| 367 | const bt_field_class_enumeration_unsigned_mapping>> |
| 368 | asUnsignedEnumeration() const noexcept; |
| 369 | |
| 370 | CommonEnumerationFieldClass< |
| 371 | LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>> |
| 372 | asSignedEnumeration() const noexcept; |
| 373 | |
| 374 | CommonStructureFieldClass<LibObjT> asStructure() const noexcept; |
| 375 | CommonArrayFieldClass<LibObjT> asArray() const noexcept; |
| 376 | CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept; |
| 377 | CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept; |
| 378 | CommonOptionFieldClass<LibObjT> asOption() const noexcept; |
| 379 | CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept; |
| 380 | CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept; |
| 381 | |
| 382 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> |
| 383 | asOptionWithUnsignedIntegerSelector() const noexcept; |
| 384 | |
| 385 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> |
| 386 | asOptionWithSignedIntegerSelector() const noexcept; |
| 387 | |
| 388 | CommonVariantFieldClass<LibObjT> asVariant() const noexcept; |
| 389 | CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept; |
| 390 | CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept; |
| 391 | |
| 392 | CommonVariantWithIntegerSelectorFieldClass< |
| 393 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< |
| 394 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>> |
| 395 | asVariantWithUnsignedIntegerSelector() const noexcept; |
| 396 | |
| 397 | CommonVariantWithIntegerSelectorFieldClass< |
| 398 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< |
| 399 | const bt_field_class_variant_with_selector_field_integer_signed_option>> |
| 400 | asVariantWithSignedIntegerSelector() const noexcept; |
| 401 | |
| 402 | template <typename LibValT> |
| 403 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 404 | { |
| 405 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`."); |
| 406 | |
| 407 | bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 408 | } |
| 409 | |
| 410 | UserAttributes userAttributes() const noexcept |
| 411 | { |
| 412 | return UserAttributes { |
| 413 | internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())}; |
| 414 | } |
| 415 | |
| 416 | Shared shared() const noexcept |
| 417 | { |
| 418 | return Shared::createWithRef(*this); |
| 419 | } |
| 420 | |
| 421 | protected: |
| 422 | bool _libTypeIs(const bt_field_class_type type) const noexcept |
| 423 | { |
| 424 | return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type); |
| 425 | } |
| 426 | }; |
| 427 | |
| 428 | using FieldClass = CommonFieldClass<bt_field_class>; |
| 429 | using ConstFieldClass = CommonFieldClass<const bt_field_class>; |
| 430 | |
| 431 | namespace internal { |
| 432 | |
| 433 | struct FieldClassTypeDescr |
| 434 | { |
| 435 | using Const = ConstFieldClass; |
| 436 | using NonConst = FieldClass; |
| 437 | }; |
| 438 | |
| 439 | template <> |
| 440 | struct TypeDescr<FieldClass> : public FieldClassTypeDescr |
| 441 | { |
| 442 | }; |
| 443 | |
| 444 | template <> |
| 445 | struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr |
| 446 | { |
| 447 | }; |
| 448 | |
| 449 | } /* namespace internal */ |
| 450 | |
| 451 | template <typename LibObjT> |
| 452 | class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT> |
| 453 | { |
| 454 | private: |
| 455 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 456 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 457 | |
| 458 | public: |
| 459 | using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>; |
| 460 | |
| 461 | explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 462 | _ThisCommonFieldClass {libObjPtr} |
| 463 | { |
| 464 | BT_ASSERT_DBG(this->isBitArray()); |
| 465 | } |
| 466 | |
| 467 | template <typename OtherLibObjT> |
| 468 | CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 469 | _ThisCommonFieldClass {fc} |
| 470 | { |
| 471 | } |
| 472 | |
| 473 | template <typename OtherLibObjT> |
| 474 | CommonBitArrayFieldClass<LibObjT> |
| 475 | operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept |
| 476 | { |
| 477 | _ThisCommonFieldClass::operator=(fc); |
| 478 | return *this; |
| 479 | } |
| 480 | |
| 481 | CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 482 | { |
| 483 | return CommonBitArrayFieldClass<const bt_field_class> {*this}; |
| 484 | } |
| 485 | |
| 486 | std::uint64_t length() const noexcept |
| 487 | { |
| 488 | return bt_field_class_bit_array_get_length(this->libObjPtr()); |
| 489 | } |
| 490 | |
| 491 | Shared shared() const noexcept |
| 492 | { |
| 493 | return Shared::createWithRef(*this); |
| 494 | } |
| 495 | }; |
| 496 | |
| 497 | using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>; |
| 498 | using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>; |
| 499 | |
| 500 | namespace internal { |
| 501 | |
| 502 | struct BitArrayFieldClassTypeDescr |
| 503 | { |
| 504 | using Const = ConstBitArrayFieldClass; |
| 505 | using NonConst = BitArrayFieldClass; |
| 506 | }; |
| 507 | |
| 508 | template <> |
| 509 | struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr |
| 510 | { |
| 511 | }; |
| 512 | |
| 513 | template <> |
| 514 | struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr |
| 515 | { |
| 516 | }; |
| 517 | |
| 518 | } /* namespace internal */ |
| 519 | |
| 520 | enum class DisplayBase |
| 521 | { |
| 522 | BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY, |
| 523 | OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL, |
| 524 | DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL, |
| 525 | HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL, |
| 526 | }; |
| 527 | |
| 528 | template <typename LibObjT> |
| 529 | class CommonIntegerFieldClass : public CommonFieldClass<LibObjT> |
| 530 | { |
| 531 | private: |
| 532 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 533 | |
| 534 | protected: |
| 535 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 536 | using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>; |
| 537 | |
| 538 | public: |
| 539 | using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>; |
| 540 | |
| 541 | explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 542 | _ThisCommonFieldClass {libObjPtr} |
| 543 | { |
| 544 | BT_ASSERT_DBG(this->isInteger()); |
| 545 | } |
| 546 | |
| 547 | template <typename OtherLibObjT> |
| 548 | CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept : |
| 549 | _ThisCommonFieldClass {fc} |
| 550 | { |
| 551 | } |
| 552 | |
| 553 | template <typename OtherLibObjT> |
| 554 | CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept |
| 555 | { |
| 556 | _ThisCommonFieldClass::operator=(fc); |
| 557 | return *this; |
| 558 | } |
| 559 | |
| 560 | CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept |
| 561 | { |
| 562 | return CommonIntegerFieldClass<const bt_field_class> {*this}; |
| 563 | } |
| 564 | |
| 565 | void fieldValueRange(const std::uint64_t n) const noexcept |
| 566 | { |
| 567 | static_assert(!std::is_const<LibObjT>::value, |
| 568 | "Not available with `bt2::ConstIntegerFieldClass`."); |
| 569 | |
| 570 | bt_field_class_integer_set_field_value_range(this->libObjPtr(), n); |
| 571 | } |
| 572 | |
| 573 | std::uint64_t fieldValueRange() const noexcept |
| 574 | { |
| 575 | return bt_field_class_integer_get_field_value_range(this->libObjPtr()); |
| 576 | } |
| 577 | |
| 578 | void preferredDisplayBase(const DisplayBase base) const noexcept |
| 579 | { |
| 580 | static_assert(!std::is_const<LibObjT>::value, |
| 581 | "Not available with `bt2::ConstIntegerFieldClass`."); |
| 582 | |
| 583 | bt_field_class_integer_set_preferred_display_base( |
| 584 | this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base)); |
| 585 | } |
| 586 | |
| 587 | DisplayBase preferredDisplayBase() const noexcept |
| 588 | { |
| 589 | return static_cast<DisplayBase>( |
| 590 | bt_field_class_integer_get_preferred_display_base(this->libObjPtr())); |
| 591 | } |
| 592 | |
| 593 | Shared shared() const noexcept |
| 594 | { |
| 595 | return Shared::createWithRef(*this); |
| 596 | } |
| 597 | }; |
| 598 | |
| 599 | using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>; |
| 600 | using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>; |
| 601 | |
| 602 | namespace internal { |
| 603 | |
| 604 | struct IntegerFieldClassTypeDescr |
| 605 | { |
| 606 | using Const = ConstIntegerFieldClass; |
| 607 | using NonConst = IntegerFieldClass; |
| 608 | }; |
| 609 | |
| 610 | template <> |
| 611 | struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr |
| 612 | { |
| 613 | }; |
| 614 | |
| 615 | template <> |
| 616 | struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr |
| 617 | { |
| 618 | }; |
| 619 | |
| 620 | template <typename LibObjT> |
| 621 | struct ConstEnumerationFieldClassMappingSpec; |
| 622 | |
| 623 | /* Functions specific to unsigned enumeration field class mappings */ |
| 624 | template <> |
| 625 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping> |
| 626 | final |
| 627 | { |
| 628 | static const bt_integer_range_set_unsigned * |
| 629 | ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept |
| 630 | { |
| 631 | return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr); |
| 632 | } |
| 633 | |
| 634 | static const char * |
| 635 | label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept |
| 636 | { |
| 637 | return bt_field_class_enumeration_mapping_get_label( |
| 638 | bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr)); |
| 639 | } |
| 640 | }; |
| 641 | |
| 642 | /* Functions specific to signed enumeration field class mappings */ |
| 643 | template <> |
| 644 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final |
| 645 | { |
| 646 | static const bt_integer_range_set_signed * |
| 647 | ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept |
| 648 | { |
| 649 | return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr); |
| 650 | } |
| 651 | |
| 652 | static const char * |
| 653 | label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept |
| 654 | { |
| 655 | return bt_field_class_enumeration_mapping_get_label( |
| 656 | bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr)); |
| 657 | } |
| 658 | }; |
| 659 | |
| 660 | } /* namespace internal */ |
| 661 | |
| 662 | template <typename LibObjT> |
| 663 | class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT> |
| 664 | { |
| 665 | private: |
| 666 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 667 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
| 668 | |
| 669 | public: |
| 670 | using RangeSet = typename std::conditional< |
| 671 | std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value, |
| 672 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; |
| 673 | |
| 674 | explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept : |
| 675 | _ThisBorrowedObject {libObjPtr} |
| 676 | { |
| 677 | } |
| 678 | |
| 679 | ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept : |
| 680 | _ThisBorrowedObject {mapping} |
| 681 | { |
| 682 | } |
| 683 | |
| 684 | ConstEnumerationFieldClassMapping |
| 685 | operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept |
| 686 | { |
| 687 | _ThisBorrowedObject::operator=(mapping); |
| 688 | return *this; |
| 689 | } |
| 690 | |
| 691 | RangeSet ranges() const noexcept |
| 692 | { |
| 693 | return RangeSet { |
| 694 | internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())}; |
| 695 | } |
| 696 | |
| 697 | const char *label() const noexcept |
| 698 | { |
| 699 | return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr()); |
| 700 | } |
| 701 | }; |
| 702 | |
| 703 | using ConstUnsignedEnumerationFieldClassMapping = |
| 704 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>; |
| 705 | |
| 706 | using ConstSignedEnumerationFieldClassMapping = |
| 707 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>; |
| 708 | |
| 709 | namespace internal { |
| 710 | |
| 711 | template <typename MappingT> |
| 712 | struct CommonEnumerationFieldClassSpec; |
| 713 | |
| 714 | /* Functions specific to unsigned enumeration field classes */ |
| 715 | template <> |
| 716 | struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final |
| 717 | { |
| 718 | static const bt_field_class_enumeration_unsigned_mapping * |
| 719 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 720 | { |
| 721 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index); |
| 722 | } |
| 723 | |
| 724 | static const bt_field_class_enumeration_unsigned_mapping * |
| 725 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept |
| 726 | { |
| 727 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label); |
| 728 | } |
| 729 | |
| 730 | static bt_field_class_enumeration_add_mapping_status |
| 731 | addMapping(bt_field_class * const libObjPtr, const char * const label, |
| 732 | const bt_integer_range_set_unsigned * const libRanges) noexcept |
| 733 | { |
| 734 | return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges); |
| 735 | } |
| 736 | }; |
| 737 | |
| 738 | /* Functions specific to signed enumeration field classes */ |
| 739 | template <> |
| 740 | struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final |
| 741 | { |
| 742 | static const bt_field_class_enumeration_signed_mapping * |
| 743 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 744 | { |
| 745 | return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index); |
| 746 | } |
| 747 | |
| 748 | static const bt_field_class_enumeration_signed_mapping * |
| 749 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept |
| 750 | { |
| 751 | return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label); |
| 752 | } |
| 753 | |
| 754 | static bt_field_class_enumeration_add_mapping_status |
| 755 | addMapping(bt_field_class * const libObjPtr, const char * const label, |
| 756 | const bt_integer_range_set_signed * const libRanges) noexcept |
| 757 | { |
| 758 | return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges); |
| 759 | } |
| 760 | }; |
| 761 | |
| 762 | } /* namespace internal */ |
| 763 | |
| 764 | template <typename LibObjT> |
| 765 | class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT> |
| 766 | { |
| 767 | private: |
| 768 | using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass; |
| 769 | |
| 770 | protected: |
| 771 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 772 | using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>; |
| 773 | |
| 774 | public: |
| 775 | using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>; |
| 776 | |
| 777 | explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 778 | _ThisCommonIntegerFieldClass {libObjPtr} |
| 779 | { |
| 780 | BT_ASSERT_DBG(this->isEnumeration()); |
| 781 | } |
| 782 | |
| 783 | template <typename OtherLibObjT> |
| 784 | CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
| 785 | : |
| 786 | _ThisCommonIntegerFieldClass {fc} |
| 787 | { |
| 788 | } |
| 789 | |
| 790 | template <typename OtherLibObjT> |
| 791 | CommonBaseEnumerationFieldClass |
| 792 | operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
| 793 | { |
| 794 | _ThisCommonIntegerFieldClass::operator=(fc); |
| 795 | return *this; |
| 796 | } |
| 797 | |
| 798 | CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept |
| 799 | { |
| 800 | return CommonBaseEnumerationFieldClass<const bt_field_class> {*this}; |
| 801 | } |
| 802 | |
| 803 | std::uint64_t length() const noexcept |
| 804 | { |
| 805 | return bt_field_class_enumeration_get_mapping_count(this->libObjPtr()); |
| 806 | } |
| 807 | |
| 808 | Shared shared() const noexcept |
| 809 | { |
| 810 | return Shared::createWithRef(*this); |
| 811 | } |
| 812 | }; |
| 813 | |
| 814 | template <typename LibObjT, typename MappingT> |
| 815 | class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT> |
| 816 | { |
| 817 | private: |
| 818 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 819 | using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass; |
| 820 | |
| 821 | public: |
| 822 | using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>; |
| 823 | using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>; |
| 824 | using Mapping = MappingT; |
| 825 | |
| 826 | explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 827 | _ThisCommonBaseEnumerationFieldClass {libObjPtr} |
| 828 | { |
| 829 | BT_ASSERT_DBG(this->isEnumeration()); |
| 830 | } |
| 831 | |
| 832 | template <typename OtherLibObjT> |
| 833 | CommonEnumerationFieldClass( |
| 834 | const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept : |
| 835 | CommonEnumerationFieldClass {fc} |
| 836 | { |
| 837 | } |
| 838 | |
| 839 | template <typename OtherLibObjT> |
| 840 | CommonEnumerationFieldClass |
| 841 | operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept |
| 842 | { |
| 843 | CommonEnumerationFieldClass::operator=(fc); |
| 844 | return *this; |
| 845 | } |
| 846 | |
| 847 | Mapping operator[](const std::uint64_t index) const noexcept |
| 848 | { |
| 849 | return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex( |
| 850 | this->libObjPtr(), index)}; |
| 851 | } |
| 852 | |
| 853 | bt2s::optional<Mapping> operator[](const char * const label) const noexcept |
| 854 | { |
| 855 | const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel( |
| 856 | this->libObjPtr(), label); |
| 857 | |
| 858 | if (libObjPtr) { |
| 859 | return Mapping {libObjPtr}; |
| 860 | } |
| 861 | |
| 862 | return bt2s::nullopt; |
| 863 | } |
| 864 | |
| 865 | bt2s::optional<Mapping> operator[](const std::string& label) const noexcept |
| 866 | { |
| 867 | return (*this)[label.data()]; |
| 868 | } |
| 869 | |
| 870 | void addMapping(const char * const label, const typename Mapping::RangeSet ranges) const |
| 871 | { |
| 872 | const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping( |
| 873 | this->libObjPtr(), label, ranges.libObjPtr()); |
| 874 | |
| 875 | if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) { |
| 876 | throw MemoryError {}; |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | void addMapping(const std::string& label, const typename Mapping::RangeSet ranges) const |
| 881 | { |
| 882 | this->addMapping(label.data(), ranges); |
| 883 | } |
| 884 | |
| 885 | Iterator begin() const noexcept |
| 886 | { |
| 887 | return Iterator {*this, 0}; |
| 888 | } |
| 889 | |
| 890 | Iterator end() const noexcept |
| 891 | { |
| 892 | return Iterator {*this, this->length()}; |
| 893 | } |
| 894 | |
| 895 | Shared shared() const noexcept |
| 896 | { |
| 897 | return Shared::createWithRef(*this); |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>; |
| 902 | using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>; |
| 903 | |
| 904 | using UnsignedEnumerationFieldClass = |
| 905 | CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; |
| 906 | |
| 907 | using ConstUnsignedEnumerationFieldClass = |
| 908 | CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; |
| 909 | |
| 910 | using SignedEnumerationFieldClass = |
| 911 | CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>; |
| 912 | |
| 913 | using ConstSignedEnumerationFieldClass = |
| 914 | CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>; |
| 915 | |
| 916 | namespace internal { |
| 917 | |
| 918 | struct UnsignedEnumerationFieldClassTypeDescr |
| 919 | { |
| 920 | using Const = ConstUnsignedEnumerationFieldClass; |
| 921 | using NonConst = UnsignedEnumerationFieldClass; |
| 922 | }; |
| 923 | |
| 924 | template <> |
| 925 | struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr |
| 926 | { |
| 927 | }; |
| 928 | |
| 929 | template <> |
| 930 | struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr |
| 931 | { |
| 932 | }; |
| 933 | |
| 934 | struct SignedEnumerationFieldClassTypeDescr |
| 935 | { |
| 936 | using Const = ConstSignedEnumerationFieldClass; |
| 937 | using NonConst = SignedEnumerationFieldClass; |
| 938 | }; |
| 939 | |
| 940 | template <> |
| 941 | struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr |
| 942 | { |
| 943 | }; |
| 944 | |
| 945 | template <> |
| 946 | struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr |
| 947 | { |
| 948 | }; |
| 949 | |
| 950 | template <typename LibObjT> |
| 951 | struct CommonStructureFieldClassMemberSpec; |
| 952 | |
| 953 | /* Functions specific to mutable structure field class members */ |
| 954 | template <> |
| 955 | struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final |
| 956 | { |
| 957 | static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept |
| 958 | { |
| 959 | return bt_field_class_structure_member_borrow_field_class(libObjPtr); |
| 960 | } |
| 961 | |
| 962 | static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept |
| 963 | { |
| 964 | return bt_field_class_structure_member_borrow_user_attributes(libObjPtr); |
| 965 | } |
| 966 | }; |
| 967 | |
| 968 | /* Functions specific to constant structure field class members */ |
| 969 | template <> |
| 970 | struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final |
| 971 | { |
| 972 | static const bt_field_class * |
| 973 | fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept |
| 974 | { |
| 975 | return bt_field_class_structure_member_borrow_field_class_const(libObjPtr); |
| 976 | } |
| 977 | |
| 978 | static const bt_value * |
| 979 | userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept |
| 980 | { |
| 981 | return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr); |
| 982 | } |
| 983 | }; |
| 984 | |
| 985 | } /* namespace internal */ |
| 986 | |
| 987 | template <typename LibObjT> |
| 988 | class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT> |
| 989 | { |
| 990 | private: |
| 991 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
| 992 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 993 | using _FieldClass = internal::DepFc<LibObjT>; |
| 994 | |
| 995 | public: |
| 996 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 997 | |
| 998 | explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept : |
| 999 | _ThisBorrowedObject {libObjPtr} |
| 1000 | { |
| 1001 | } |
| 1002 | |
| 1003 | template <typename OtherLibObjT> |
| 1004 | CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
| 1005 | : |
| 1006 | _ThisBorrowedObject {fc} |
| 1007 | { |
| 1008 | } |
| 1009 | |
| 1010 | template <typename OtherLibObjT> |
| 1011 | CommonStructureFieldClassMember<LibObjT> |
| 1012 | operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
| 1013 | { |
| 1014 | _ThisBorrowedObject::operator=(fc); |
| 1015 | return *this; |
| 1016 | } |
| 1017 | |
| 1018 | CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept |
| 1019 | { |
| 1020 | return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this}; |
| 1021 | } |
| 1022 | |
| 1023 | const char *name() const noexcept |
| 1024 | { |
| 1025 | return bt_field_class_structure_member_get_name(this->libObjPtr()); |
| 1026 | } |
| 1027 | |
| 1028 | _FieldClass fieldClass() const noexcept |
| 1029 | { |
| 1030 | return _FieldClass { |
| 1031 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1032 | } |
| 1033 | |
| 1034 | template <typename LibValT> |
| 1035 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1036 | { |
| 1037 | static_assert(!std::is_const<LibObjT>::value, |
| 1038 | "Not available with `bt2::ConstStructureFieldClassMember`."); |
| 1039 | |
| 1040 | bt_field_class_structure_member_set_user_attributes(this->libObjPtr(), |
| 1041 | userAttrs.libObjPtr()); |
| 1042 | } |
| 1043 | |
| 1044 | UserAttributes userAttributes() const noexcept |
| 1045 | { |
| 1046 | return UserAttributes { |
| 1047 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes( |
| 1048 | this->libObjPtr())}; |
| 1049 | } |
| 1050 | }; |
| 1051 | |
| 1052 | using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>; |
| 1053 | |
| 1054 | using ConstStructureFieldClassMember = |
| 1055 | CommonStructureFieldClassMember<const bt_field_class_structure_member>; |
| 1056 | |
| 1057 | namespace internal { |
| 1058 | |
| 1059 | struct StructureFieldClassMemberTypeDescr |
| 1060 | { |
| 1061 | using Const = ConstStructureFieldClassMember; |
| 1062 | using NonConst = StructureFieldClassMember; |
| 1063 | }; |
| 1064 | |
| 1065 | template <> |
| 1066 | struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr |
| 1067 | { |
| 1068 | }; |
| 1069 | |
| 1070 | template <> |
| 1071 | struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr |
| 1072 | { |
| 1073 | }; |
| 1074 | |
| 1075 | template <typename LibObjT> |
| 1076 | struct CommonStructureFieldClassSpec; |
| 1077 | |
| 1078 | /* Functions specific to mutable structure field classes */ |
| 1079 | template <> |
| 1080 | struct CommonStructureFieldClassSpec<bt_field_class> final |
| 1081 | { |
| 1082 | static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr, |
| 1083 | const std::uint64_t index) noexcept |
| 1084 | { |
| 1085 | return bt_field_class_structure_borrow_member_by_index(libObjPtr, index); |
| 1086 | } |
| 1087 | |
| 1088 | static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr, |
| 1089 | const char * const name) noexcept |
| 1090 | { |
| 1091 | return bt_field_class_structure_borrow_member_by_name(libObjPtr, name); |
| 1092 | } |
| 1093 | }; |
| 1094 | |
| 1095 | /* Functions specific to constant structure field classes */ |
| 1096 | template <> |
| 1097 | struct CommonStructureFieldClassSpec<const bt_field_class> final |
| 1098 | { |
| 1099 | static const bt_field_class_structure_member * |
| 1100 | memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 1101 | { |
| 1102 | return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index); |
| 1103 | } |
| 1104 | |
| 1105 | static const bt_field_class_structure_member * |
| 1106 | memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 1107 | { |
| 1108 | return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name); |
| 1109 | } |
| 1110 | }; |
| 1111 | |
| 1112 | } /* namespace internal */ |
| 1113 | |
| 1114 | template <typename LibObjT> |
| 1115 | class CommonStructureFieldClass final : public CommonFieldClass<LibObjT> |
| 1116 | { |
| 1117 | private: |
| 1118 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1119 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1120 | |
| 1121 | public: |
| 1122 | using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>; |
| 1123 | using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>; |
| 1124 | |
| 1125 | using Member = |
| 1126 | internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>; |
| 1127 | |
| 1128 | explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1129 | _ThisCommonFieldClass {libObjPtr} |
| 1130 | { |
| 1131 | BT_ASSERT_DBG(this->isStructure()); |
| 1132 | } |
| 1133 | |
| 1134 | template <typename OtherLibObjT> |
| 1135 | CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept : |
| 1136 | _ThisCommonFieldClass {fc} |
| 1137 | { |
| 1138 | } |
| 1139 | |
| 1140 | template <typename OtherLibObjT> |
| 1141 | CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept |
| 1142 | { |
| 1143 | _ThisCommonFieldClass::operator=(fc); |
| 1144 | return *this; |
| 1145 | } |
| 1146 | |
| 1147 | CommonStructureFieldClass<const bt_field_class> asConst() const noexcept |
| 1148 | { |
| 1149 | return CommonStructureFieldClass<const bt_field_class> {*this}; |
| 1150 | } |
| 1151 | |
| 1152 | void appendMember(const char * const name, const FieldClass fc) const |
| 1153 | { |
| 1154 | static_assert(!std::is_const<LibObjT>::value, |
| 1155 | "Not available with `bt2::ConstStructureFieldClass`."); |
| 1156 | |
| 1157 | const auto status = |
| 1158 | bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr()); |
| 1159 | |
| 1160 | if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { |
| 1161 | throw MemoryError {}; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | void appendMember(const std::string& name, const FieldClass fc) const |
| 1166 | { |
| 1167 | this->appendMember(name.data(), fc); |
| 1168 | } |
| 1169 | |
| 1170 | std::uint64_t length() const noexcept |
| 1171 | { |
| 1172 | return bt_field_class_structure_get_member_count(this->libObjPtr()); |
| 1173 | } |
| 1174 | |
| 1175 | Iterator begin() const noexcept |
| 1176 | { |
| 1177 | return Iterator {*this, 0}; |
| 1178 | } |
| 1179 | |
| 1180 | Iterator end() const noexcept |
| 1181 | { |
| 1182 | return Iterator {*this, this->length()}; |
| 1183 | } |
| 1184 | |
| 1185 | Member operator[](const std::uint64_t index) const noexcept |
| 1186 | { |
| 1187 | return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex( |
| 1188 | this->libObjPtr(), index)}; |
| 1189 | } |
| 1190 | |
| 1191 | bt2s::optional<Member> operator[](const char * const name) const noexcept |
| 1192 | { |
| 1193 | const auto libObjPtr = |
| 1194 | internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name); |
| 1195 | |
| 1196 | if (libObjPtr) { |
| 1197 | return Member {libObjPtr}; |
| 1198 | } |
| 1199 | |
| 1200 | return bt2s::nullopt; |
| 1201 | } |
| 1202 | |
| 1203 | bt2s::optional<Member> operator[](const std::string& name) const noexcept |
| 1204 | { |
| 1205 | return (*this)[name.data()]; |
| 1206 | } |
| 1207 | |
| 1208 | Shared shared() const noexcept |
| 1209 | { |
| 1210 | return Shared::createWithRef(*this); |
| 1211 | } |
| 1212 | }; |
| 1213 | |
| 1214 | using StructureFieldClass = CommonStructureFieldClass<bt_field_class>; |
| 1215 | using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>; |
| 1216 | |
| 1217 | namespace internal { |
| 1218 | |
| 1219 | struct StructureFieldClassTypeDescr |
| 1220 | { |
| 1221 | using Const = ConstStructureFieldClass; |
| 1222 | using NonConst = StructureFieldClass; |
| 1223 | }; |
| 1224 | |
| 1225 | template <> |
| 1226 | struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr |
| 1227 | { |
| 1228 | }; |
| 1229 | |
| 1230 | template <> |
| 1231 | struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr |
| 1232 | { |
| 1233 | }; |
| 1234 | |
| 1235 | template <typename LibObjT> |
| 1236 | struct CommonArrayFieldClassSpec; |
| 1237 | |
| 1238 | /* Functions specific to mutable array field classes */ |
| 1239 | template <> |
| 1240 | struct CommonArrayFieldClassSpec<bt_field_class> final |
| 1241 | { |
| 1242 | static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept |
| 1243 | { |
| 1244 | return bt_field_class_array_borrow_element_field_class(libObjPtr); |
| 1245 | } |
| 1246 | }; |
| 1247 | |
| 1248 | /* Functions specific to constant array field classes */ |
| 1249 | template <> |
| 1250 | struct CommonArrayFieldClassSpec<const bt_field_class> final |
| 1251 | { |
| 1252 | static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept |
| 1253 | { |
| 1254 | return bt_field_class_array_borrow_element_field_class_const(libObjPtr); |
| 1255 | } |
| 1256 | }; |
| 1257 | |
| 1258 | } /* namespace internal */ |
| 1259 | |
| 1260 | template <typename LibObjT> |
| 1261 | class CommonArrayFieldClass : public CommonFieldClass<LibObjT> |
| 1262 | { |
| 1263 | private: |
| 1264 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1265 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1266 | |
| 1267 | protected: |
| 1268 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1269 | using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>; |
| 1270 | |
| 1271 | public: |
| 1272 | using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>; |
| 1273 | |
| 1274 | explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1275 | _ThisCommonFieldClass {libObjPtr} |
| 1276 | { |
| 1277 | BT_ASSERT_DBG(this->isArray()); |
| 1278 | } |
| 1279 | |
| 1280 | template <typename OtherLibObjT> |
| 1281 | CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 1282 | _ThisCommonFieldClass {fc} |
| 1283 | { |
| 1284 | } |
| 1285 | |
| 1286 | template <typename OtherLibObjT> |
| 1287 | CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept |
| 1288 | { |
| 1289 | _ThisCommonFieldClass::operator=(fc); |
| 1290 | return *this; |
| 1291 | } |
| 1292 | |
| 1293 | CommonArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 1294 | { |
| 1295 | return CommonArrayFieldClass<const bt_field_class> {*this}; |
| 1296 | } |
| 1297 | |
| 1298 | _FieldClass elementFieldClass() const noexcept |
| 1299 | { |
| 1300 | return _FieldClass { |
| 1301 | internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())}; |
| 1302 | } |
| 1303 | |
| 1304 | Shared shared() const noexcept |
| 1305 | { |
| 1306 | return Shared::createWithRef(*this); |
| 1307 | } |
| 1308 | }; |
| 1309 | |
| 1310 | using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>; |
| 1311 | using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>; |
| 1312 | |
| 1313 | namespace internal { |
| 1314 | |
| 1315 | struct ArrayFieldClassTypeDescr |
| 1316 | { |
| 1317 | using Const = ConstArrayFieldClass; |
| 1318 | using NonConst = ArrayFieldClass; |
| 1319 | }; |
| 1320 | |
| 1321 | template <> |
| 1322 | struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr |
| 1323 | { |
| 1324 | }; |
| 1325 | |
| 1326 | template <> |
| 1327 | struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr |
| 1328 | { |
| 1329 | }; |
| 1330 | |
| 1331 | } /* namespace internal */ |
| 1332 | |
| 1333 | template <typename LibObjT> |
| 1334 | class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT> |
| 1335 | { |
| 1336 | private: |
| 1337 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; |
| 1338 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1339 | |
| 1340 | public: |
| 1341 | using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>; |
| 1342 | |
| 1343 | explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1344 | _ThisCommonArrayFieldClass {libObjPtr} |
| 1345 | { |
| 1346 | BT_ASSERT_DBG(this->isStaticArray()); |
| 1347 | } |
| 1348 | |
| 1349 | template <typename OtherLibObjT> |
| 1350 | CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 1351 | _ThisCommonArrayFieldClass {fc} |
| 1352 | { |
| 1353 | } |
| 1354 | |
| 1355 | template <typename OtherLibObjT> |
| 1356 | CommonStaticArrayFieldClass |
| 1357 | operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept |
| 1358 | { |
| 1359 | _ThisCommonArrayFieldClass::operator=(fc); |
| 1360 | return *this; |
| 1361 | } |
| 1362 | |
| 1363 | CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 1364 | { |
| 1365 | return CommonStaticArrayFieldClass<const bt_field_class> {*this}; |
| 1366 | } |
| 1367 | |
| 1368 | std::uint64_t length() const noexcept |
| 1369 | { |
| 1370 | return bt_field_class_array_static_get_length(this->libObjPtr()); |
| 1371 | } |
| 1372 | |
| 1373 | Shared shared() const noexcept |
| 1374 | { |
| 1375 | return Shared::createWithRef(*this); |
| 1376 | } |
| 1377 | }; |
| 1378 | |
| 1379 | using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>; |
| 1380 | using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>; |
| 1381 | |
| 1382 | namespace internal { |
| 1383 | |
| 1384 | struct StaticArrayFieldClassTypeDescr |
| 1385 | { |
| 1386 | using Const = ConstStaticArrayFieldClass; |
| 1387 | using NonConst = StaticArrayFieldClass; |
| 1388 | }; |
| 1389 | |
| 1390 | template <> |
| 1391 | struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr |
| 1392 | { |
| 1393 | }; |
| 1394 | |
| 1395 | template <> |
| 1396 | struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr |
| 1397 | { |
| 1398 | }; |
| 1399 | |
| 1400 | } /* namespace internal */ |
| 1401 | |
| 1402 | template <typename LibObjT> |
| 1403 | class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT> |
| 1404 | { |
| 1405 | private: |
| 1406 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; |
| 1407 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1408 | |
| 1409 | public: |
| 1410 | using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>; |
| 1411 | |
| 1412 | explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1413 | _ThisCommonArrayFieldClass {libObjPtr} |
| 1414 | { |
| 1415 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); |
| 1416 | } |
| 1417 | |
| 1418 | template <typename OtherLibObjT> |
| 1419 | CommonDynamicArrayWithLengthFieldClass( |
| 1420 | const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept : |
| 1421 | _ThisCommonArrayFieldClass {fc} |
| 1422 | { |
| 1423 | } |
| 1424 | |
| 1425 | template <typename OtherLibObjT> |
| 1426 | CommonDynamicArrayWithLengthFieldClass |
| 1427 | operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept |
| 1428 | { |
| 1429 | _ThisCommonArrayFieldClass::operator=(fc); |
| 1430 | return *this; |
| 1431 | } |
| 1432 | |
| 1433 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept |
| 1434 | { |
| 1435 | return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this}; |
| 1436 | } |
| 1437 | |
| 1438 | ConstFieldPath lengthFieldPath() const noexcept |
| 1439 | { |
| 1440 | return ConstFieldPath { |
| 1441 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
| 1442 | this->libObjPtr())}; |
| 1443 | } |
| 1444 | |
| 1445 | Shared shared() const noexcept |
| 1446 | { |
| 1447 | return Shared::createWithRef(*this); |
| 1448 | } |
| 1449 | }; |
| 1450 | |
| 1451 | using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>; |
| 1452 | |
| 1453 | using ConstDynamicArrayWithLengthFieldClass = |
| 1454 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class>; |
| 1455 | |
| 1456 | namespace internal { |
| 1457 | |
| 1458 | struct DynamicArrayWithLengthFieldClassTypeDescr |
| 1459 | { |
| 1460 | using Const = ConstDynamicArrayWithLengthFieldClass; |
| 1461 | using NonConst = DynamicArrayWithLengthFieldClass; |
| 1462 | }; |
| 1463 | |
| 1464 | template <> |
| 1465 | struct TypeDescr<DynamicArrayWithLengthFieldClass> : |
| 1466 | public DynamicArrayWithLengthFieldClassTypeDescr |
| 1467 | { |
| 1468 | }; |
| 1469 | |
| 1470 | template <> |
| 1471 | struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> : |
| 1472 | public DynamicArrayWithLengthFieldClassTypeDescr |
| 1473 | { |
| 1474 | }; |
| 1475 | |
| 1476 | template <typename LibObjT> |
| 1477 | struct CommonOptionFieldClassSpec; |
| 1478 | |
| 1479 | /* Functions specific to mutable option field classes */ |
| 1480 | template <> |
| 1481 | struct CommonOptionFieldClassSpec<bt_field_class> final |
| 1482 | { |
| 1483 | static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept |
| 1484 | { |
| 1485 | return bt_field_class_option_borrow_field_class(libObjPtr); |
| 1486 | } |
| 1487 | }; |
| 1488 | |
| 1489 | /* Functions specific to constant option field classes */ |
| 1490 | template <> |
| 1491 | struct CommonOptionFieldClassSpec<const bt_field_class> final |
| 1492 | { |
| 1493 | static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept |
| 1494 | { |
| 1495 | return bt_field_class_option_borrow_field_class_const(libObjPtr); |
| 1496 | } |
| 1497 | }; |
| 1498 | |
| 1499 | } /* namespace internal */ |
| 1500 | |
| 1501 | template <typename LibObjT> |
| 1502 | class CommonOptionFieldClass : public CommonFieldClass<LibObjT> |
| 1503 | { |
| 1504 | private: |
| 1505 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1506 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1507 | |
| 1508 | protected: |
| 1509 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1510 | using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>; |
| 1511 | |
| 1512 | public: |
| 1513 | using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>; |
| 1514 | |
| 1515 | explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1516 | _ThisCommonFieldClass {libObjPtr} |
| 1517 | { |
| 1518 | BT_ASSERT_DBG(this->isOption()); |
| 1519 | } |
| 1520 | |
| 1521 | template <typename OtherLibObjT> |
| 1522 | CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept : |
| 1523 | _ThisCommonFieldClass {fc} |
| 1524 | { |
| 1525 | } |
| 1526 | |
| 1527 | template <typename OtherLibObjT> |
| 1528 | CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept |
| 1529 | { |
| 1530 | _ThisCommonFieldClass::operator=(fc); |
| 1531 | return *this; |
| 1532 | } |
| 1533 | |
| 1534 | CommonOptionFieldClass<const bt_field_class> asConst() const noexcept |
| 1535 | { |
| 1536 | return CommonOptionFieldClass<const bt_field_class> {*this}; |
| 1537 | } |
| 1538 | |
| 1539 | _FieldClass fieldClass() const noexcept |
| 1540 | { |
| 1541 | return _FieldClass { |
| 1542 | internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1543 | } |
| 1544 | |
| 1545 | Shared shared() const noexcept |
| 1546 | { |
| 1547 | return Shared::createWithRef(*this); |
| 1548 | } |
| 1549 | }; |
| 1550 | |
| 1551 | using OptionFieldClass = CommonOptionFieldClass<bt_field_class>; |
| 1552 | using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>; |
| 1553 | |
| 1554 | namespace internal { |
| 1555 | |
| 1556 | struct OptionFieldClassTypeDescr |
| 1557 | { |
| 1558 | using Const = ConstOptionFieldClass; |
| 1559 | using NonConst = OptionFieldClass; |
| 1560 | }; |
| 1561 | |
| 1562 | template <> |
| 1563 | struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr |
| 1564 | { |
| 1565 | }; |
| 1566 | |
| 1567 | template <> |
| 1568 | struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr |
| 1569 | { |
| 1570 | }; |
| 1571 | |
| 1572 | } /* namespace internal */ |
| 1573 | |
| 1574 | template <typename LibObjT> |
| 1575 | class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT> |
| 1576 | { |
| 1577 | private: |
| 1578 | using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass; |
| 1579 | |
| 1580 | protected: |
| 1581 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1582 | using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>; |
| 1583 | |
| 1584 | public: |
| 1585 | using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>; |
| 1586 | |
| 1587 | explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1588 | _ThisCommonOptionFieldClass {libObjPtr} |
| 1589 | { |
| 1590 | BT_ASSERT_DBG(this->isOptionWithSelector()); |
| 1591 | } |
| 1592 | |
| 1593 | template <typename OtherLibObjT> |
| 1594 | CommonOptionWithSelectorFieldClass( |
| 1595 | const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 1596 | _ThisCommonOptionFieldClass {fc} |
| 1597 | { |
| 1598 | } |
| 1599 | |
| 1600 | template <typename OtherLibObjT> |
| 1601 | CommonOptionWithSelectorFieldClass |
| 1602 | operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 1603 | { |
| 1604 | _ThisCommonOptionFieldClass::operator=(fc); |
| 1605 | return *this; |
| 1606 | } |
| 1607 | |
| 1608 | CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 1609 | { |
| 1610 | return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this}; |
| 1611 | } |
| 1612 | |
| 1613 | ConstFieldPath selectorFieldPath() const noexcept |
| 1614 | { |
| 1615 | return ConstFieldPath { |
| 1616 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( |
| 1617 | this->libObjPtr())}; |
| 1618 | } |
| 1619 | |
| 1620 | Shared shared() const noexcept |
| 1621 | { |
| 1622 | return Shared::createWithRef(*this); |
| 1623 | } |
| 1624 | }; |
| 1625 | |
| 1626 | using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>; |
| 1627 | using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>; |
| 1628 | |
| 1629 | namespace internal { |
| 1630 | |
| 1631 | struct OptionWithSelectorFieldClassTypeDescr |
| 1632 | { |
| 1633 | using Const = ConstOptionWithSelectorFieldClass; |
| 1634 | using NonConst = OptionWithSelectorFieldClass; |
| 1635 | }; |
| 1636 | |
| 1637 | template <> |
| 1638 | struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr |
| 1639 | { |
| 1640 | }; |
| 1641 | |
| 1642 | template <> |
| 1643 | struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr |
| 1644 | { |
| 1645 | }; |
| 1646 | |
| 1647 | } /* namespace internal */ |
| 1648 | |
| 1649 | template <typename LibObjT> |
| 1650 | class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> |
| 1651 | { |
| 1652 | private: |
| 1653 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1654 | |
| 1655 | using typename CommonOptionWithSelectorFieldClass< |
| 1656 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; |
| 1657 | |
| 1658 | public: |
| 1659 | using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>; |
| 1660 | |
| 1661 | explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1662 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
| 1663 | { |
| 1664 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); |
| 1665 | } |
| 1666 | |
| 1667 | template <typename OtherLibObjT> |
| 1668 | CommonOptionWithBoolSelectorFieldClass( |
| 1669 | const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 1670 | _ThisCommonOptionWithSelectorFieldClass {fc} |
| 1671 | { |
| 1672 | } |
| 1673 | |
| 1674 | template <typename OtherLibObjT> |
| 1675 | CommonOptionWithBoolSelectorFieldClass |
| 1676 | operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 1677 | { |
| 1678 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); |
| 1679 | return *this; |
| 1680 | } |
| 1681 | |
| 1682 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 1683 | { |
| 1684 | return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this}; |
| 1685 | } |
| 1686 | |
| 1687 | bool selectorIsReversed() const noexcept |
| 1688 | { |
| 1689 | return bt_field_class_option_with_selector_field_bool_selector_is_reversed( |
| 1690 | this->libObjPtr()); |
| 1691 | } |
| 1692 | |
| 1693 | Shared shared() const noexcept |
| 1694 | { |
| 1695 | return Shared::createWithRef(*this); |
| 1696 | } |
| 1697 | }; |
| 1698 | |
| 1699 | using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>; |
| 1700 | |
| 1701 | using ConstOptionWithBoolSelectorFieldClass = |
| 1702 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class>; |
| 1703 | |
| 1704 | namespace internal { |
| 1705 | |
| 1706 | struct OptionWithBoolSelectorFieldClassTypeDescr |
| 1707 | { |
| 1708 | using Const = ConstOptionWithBoolSelectorFieldClass; |
| 1709 | using NonConst = OptionWithBoolSelectorFieldClass; |
| 1710 | }; |
| 1711 | |
| 1712 | template <> |
| 1713 | struct TypeDescr<OptionWithBoolSelectorFieldClass> : |
| 1714 | public OptionWithBoolSelectorFieldClassTypeDescr |
| 1715 | { |
| 1716 | }; |
| 1717 | |
| 1718 | template <> |
| 1719 | struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> : |
| 1720 | public OptionWithBoolSelectorFieldClassTypeDescr |
| 1721 | { |
| 1722 | }; |
| 1723 | |
| 1724 | template <typename RangeSetT> |
| 1725 | struct CommonOptionWithIntegerSelectorFieldClassSpec; |
| 1726 | |
| 1727 | /* Functions specific to option field classes with unsigned integer ranges */ |
| 1728 | template <> |
| 1729 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final |
| 1730 | { |
| 1731 | static const bt_integer_range_set_unsigned * |
| 1732 | ranges(const bt_field_class * const libObjPtr) noexcept |
| 1733 | { |
| 1734 | return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( |
| 1735 | libObjPtr); |
| 1736 | } |
| 1737 | }; |
| 1738 | |
| 1739 | /* Functions specific to option field classes with signed ranges */ |
| 1740 | template <> |
| 1741 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final |
| 1742 | { |
| 1743 | static const bt_integer_range_set_signed * |
| 1744 | ranges(const bt_field_class * const libObjPtr) noexcept |
| 1745 | { |
| 1746 | return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( |
| 1747 | libObjPtr); |
| 1748 | } |
| 1749 | }; |
| 1750 | |
| 1751 | } /* namespace internal */ |
| 1752 | |
| 1753 | template <typename LibObjT, typename RangeSetT> |
| 1754 | class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> |
| 1755 | { |
| 1756 | private: |
| 1757 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 1758 | |
| 1759 | using typename CommonOptionWithSelectorFieldClass< |
| 1760 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; |
| 1761 | |
| 1762 | public: |
| 1763 | using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>; |
| 1764 | using RangeSet = RangeSetT; |
| 1765 | |
| 1766 | explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 1767 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
| 1768 | { |
| 1769 | BT_ASSERT_DBG(this->isOptionWithIntegerSelector()); |
| 1770 | } |
| 1771 | |
| 1772 | template <typename OtherLibObjT> |
| 1773 | CommonOptionWithIntegerSelectorFieldClass( |
| 1774 | const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept : |
| 1775 | _ThisCommonOptionWithSelectorFieldClass {fc} |
| 1776 | { |
| 1777 | } |
| 1778 | |
| 1779 | template <typename OtherLibObjT> |
| 1780 | CommonOptionWithIntegerSelectorFieldClass |
| 1781 | operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept |
| 1782 | { |
| 1783 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); |
| 1784 | return *this; |
| 1785 | } |
| 1786 | |
| 1787 | RangeSet ranges() const noexcept |
| 1788 | { |
| 1789 | return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges( |
| 1790 | this->libObjPtr())}; |
| 1791 | } |
| 1792 | |
| 1793 | Shared shared() const noexcept |
| 1794 | { |
| 1795 | return Shared::createWithRef(*this); |
| 1796 | } |
| 1797 | }; |
| 1798 | |
| 1799 | using OptionWithUnsignedIntegerSelectorFieldClass = |
| 1800 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>; |
| 1801 | |
| 1802 | using ConstOptionWithUnsignedIntegerSelectorFieldClass = |
| 1803 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>; |
| 1804 | |
| 1805 | using OptionWithSignedIntegerSelectorFieldClass = |
| 1806 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>; |
| 1807 | |
| 1808 | using ConstOptionWithSignedIntegerSelectorFieldClass = |
| 1809 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>; |
| 1810 | |
| 1811 | namespace internal { |
| 1812 | |
| 1813 | struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1814 | { |
| 1815 | using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass; |
| 1816 | using NonConst = OptionWithUnsignedIntegerSelectorFieldClass; |
| 1817 | }; |
| 1818 | |
| 1819 | template <> |
| 1820 | struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> : |
| 1821 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1822 | { |
| 1823 | }; |
| 1824 | |
| 1825 | template <> |
| 1826 | struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> : |
| 1827 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1828 | { |
| 1829 | }; |
| 1830 | |
| 1831 | struct OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1832 | { |
| 1833 | using Const = ConstOptionWithSignedIntegerSelectorFieldClass; |
| 1834 | using NonConst = OptionWithSignedIntegerSelectorFieldClass; |
| 1835 | }; |
| 1836 | |
| 1837 | template <> |
| 1838 | struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> : |
| 1839 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1840 | { |
| 1841 | }; |
| 1842 | |
| 1843 | template <> |
| 1844 | struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> : |
| 1845 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1846 | { |
| 1847 | }; |
| 1848 | |
| 1849 | template <typename LibObjT> |
| 1850 | struct CommonVariantFieldClassOptionSpec; |
| 1851 | |
| 1852 | /* Functions specific to mutable variant field class options */ |
| 1853 | template <> |
| 1854 | struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final |
| 1855 | { |
| 1856 | static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept |
| 1857 | { |
| 1858 | return bt_field_class_variant_option_borrow_field_class(libObjPtr); |
| 1859 | } |
| 1860 | |
| 1861 | static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept |
| 1862 | { |
| 1863 | return bt_field_class_variant_option_borrow_user_attributes(libObjPtr); |
| 1864 | } |
| 1865 | }; |
| 1866 | |
| 1867 | /* Functions specific to constant variant field class options */ |
| 1868 | template <> |
| 1869 | struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final |
| 1870 | { |
| 1871 | static const bt_field_class * |
| 1872 | fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept |
| 1873 | { |
| 1874 | return bt_field_class_variant_option_borrow_field_class_const(libObjPtr); |
| 1875 | } |
| 1876 | |
| 1877 | static const bt_value * |
| 1878 | userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept |
| 1879 | { |
| 1880 | return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr); |
| 1881 | } |
| 1882 | }; |
| 1883 | |
| 1884 | } /* namespace internal */ |
| 1885 | |
| 1886 | template <typename LibObjT> |
| 1887 | class CommonVariantFieldClassOption : public BorrowedObject<LibObjT> |
| 1888 | { |
| 1889 | private: |
| 1890 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 1891 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
| 1892 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1893 | |
| 1894 | public: |
| 1895 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 1896 | |
| 1897 | explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept : |
| 1898 | _ThisBorrowedObject {libObjPtr} |
| 1899 | { |
| 1900 | } |
| 1901 | |
| 1902 | template <typename OtherLibObjT> |
| 1903 | CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept : |
| 1904 | _ThisBorrowedObject {fc} |
| 1905 | { |
| 1906 | } |
| 1907 | |
| 1908 | template <typename OtherLibObjT> |
| 1909 | CommonVariantFieldClassOption |
| 1910 | operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept |
| 1911 | { |
| 1912 | _ThisBorrowedObject::operator=(fc); |
| 1913 | return *this; |
| 1914 | } |
| 1915 | |
| 1916 | CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept |
| 1917 | { |
| 1918 | return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this}; |
| 1919 | } |
| 1920 | |
| 1921 | const char *name() const noexcept |
| 1922 | { |
| 1923 | return bt_field_class_variant_option_get_name(this->libObjPtr()); |
| 1924 | } |
| 1925 | |
| 1926 | _FieldClass fieldClass() const noexcept |
| 1927 | { |
| 1928 | return _FieldClass { |
| 1929 | internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1930 | } |
| 1931 | |
| 1932 | template <typename LibValT> |
| 1933 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1934 | { |
| 1935 | static_assert(!std::is_const<LibObjT>::value, |
| 1936 | "Not available with `bt2::ConstVariantFieldClassOption`."); |
| 1937 | |
| 1938 | bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 1939 | } |
| 1940 | |
| 1941 | UserAttributes userAttributes() const noexcept |
| 1942 | { |
| 1943 | return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes( |
| 1944 | this->libObjPtr())}; |
| 1945 | } |
| 1946 | }; |
| 1947 | |
| 1948 | using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>; |
| 1949 | |
| 1950 | using ConstVariantFieldClassOption = |
| 1951 | CommonVariantFieldClassOption<const bt_field_class_variant_option>; |
| 1952 | |
| 1953 | namespace internal { |
| 1954 | |
| 1955 | struct VariantFieldClassOptionTypeDescr |
| 1956 | { |
| 1957 | using Const = ConstVariantFieldClassOption; |
| 1958 | using NonConst = VariantFieldClassOption; |
| 1959 | }; |
| 1960 | |
| 1961 | template <> |
| 1962 | struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr |
| 1963 | { |
| 1964 | }; |
| 1965 | |
| 1966 | template <> |
| 1967 | struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr |
| 1968 | { |
| 1969 | }; |
| 1970 | |
| 1971 | template <typename LibObjT> |
| 1972 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; |
| 1973 | |
| 1974 | /* Functions specific to variant field class options with unsigned integer selector */ |
| 1975 | template <> |
| 1976 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< |
| 1977 | const bt_field_class_variant_with_selector_field_integer_unsigned_option> |
| 1978 | final |
| 1979 | { |
| 1980 | static const bt_integer_range_set_unsigned * |
| 1981 | ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option |
| 1982 | * const libObjPtr) noexcept |
| 1983 | { |
| 1984 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( |
| 1985 | libObjPtr); |
| 1986 | } |
| 1987 | |
| 1988 | static const bt_field_class_variant_option * |
| 1989 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option |
| 1990 | * const libObjPtr) noexcept |
| 1991 | { |
| 1992 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const( |
| 1993 | libObjPtr); |
| 1994 | } |
| 1995 | }; |
| 1996 | |
| 1997 | /* Functions specific to variant field class options with signed integer selector */ |
| 1998 | template <> |
| 1999 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< |
| 2000 | const bt_field_class_variant_with_selector_field_integer_signed_option> |
| 2001 | final |
| 2002 | { |
| 2003 | static const bt_integer_range_set_signed * |
| 2004 | ranges(const bt_field_class_variant_with_selector_field_integer_signed_option |
| 2005 | * const libObjPtr) noexcept |
| 2006 | { |
| 2007 | return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( |
| 2008 | libObjPtr); |
| 2009 | } |
| 2010 | |
| 2011 | static const bt_field_class_variant_option * |
| 2012 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option |
| 2013 | * const libObjPtr) noexcept |
| 2014 | { |
| 2015 | return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const( |
| 2016 | libObjPtr); |
| 2017 | } |
| 2018 | }; |
| 2019 | |
| 2020 | } /* namespace internal */ |
| 2021 | |
| 2022 | template <typename LibObjT> |
| 2023 | class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT> |
| 2024 | { |
| 2025 | private: |
| 2026 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 2027 | using typename BorrowedObject<LibObjT>::_LibObjPtr; |
| 2028 | using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>; |
| 2029 | |
| 2030 | public: |
| 2031 | using RangeSet = typename std::conditional< |
| 2032 | std::is_same< |
| 2033 | LibObjT, |
| 2034 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value, |
| 2035 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; |
| 2036 | |
| 2037 | explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept : |
| 2038 | _ThisBorrowedObject {libObjPtr} |
| 2039 | { |
| 2040 | } |
| 2041 | |
| 2042 | template <typename OtherLibObjT> |
| 2043 | ConstVariantWithIntegerSelectorFieldClassOption( |
| 2044 | const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept : |
| 2045 | _ThisBorrowedObject {fc} |
| 2046 | { |
| 2047 | } |
| 2048 | |
| 2049 | template <typename OtherLibObjT> |
| 2050 | ConstVariantWithIntegerSelectorFieldClassOption |
| 2051 | operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept |
| 2052 | { |
| 2053 | _ThisBorrowedObject::operator=(fc); |
| 2054 | return *this; |
| 2055 | } |
| 2056 | |
| 2057 | ConstVariantFieldClassOption asBaseOption() const noexcept |
| 2058 | { |
| 2059 | return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())}; |
| 2060 | } |
| 2061 | |
| 2062 | const char *name() const noexcept |
| 2063 | { |
| 2064 | return this->asBaseOption().name(); |
| 2065 | } |
| 2066 | |
| 2067 | ConstFieldClass fieldClass() const noexcept |
| 2068 | { |
| 2069 | return this->asBaseOption().fieldClass(); |
| 2070 | } |
| 2071 | |
| 2072 | RangeSet ranges() const noexcept |
| 2073 | { |
| 2074 | return RangeSet {_Spec::ranges(this->libObjPtr())}; |
| 2075 | } |
| 2076 | }; |
| 2077 | |
| 2078 | using ConstVariantWithUnsignedIntegerSelectorFieldClassOption = |
| 2079 | ConstVariantWithIntegerSelectorFieldClassOption< |
| 2080 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>; |
| 2081 | |
| 2082 | using ConstVariantWithSignedIntegerSelectorFieldClassOption = |
| 2083 | ConstVariantWithIntegerSelectorFieldClassOption< |
| 2084 | const bt_field_class_variant_with_selector_field_integer_signed_option>; |
| 2085 | |
| 2086 | namespace internal { |
| 2087 | |
| 2088 | template <typename LibObjT> |
| 2089 | struct CommonVariantFieldClassSpec; |
| 2090 | |
| 2091 | /* Functions specific to mutable variant field classes */ |
| 2092 | template <> |
| 2093 | struct CommonVariantFieldClassSpec<bt_field_class> final |
| 2094 | { |
| 2095 | static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr, |
| 2096 | const std::uint64_t index) noexcept |
| 2097 | { |
| 2098 | return bt_field_class_variant_borrow_option_by_index(libObjPtr, index); |
| 2099 | } |
| 2100 | |
| 2101 | static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr, |
| 2102 | const char * const name) noexcept |
| 2103 | { |
| 2104 | return bt_field_class_variant_borrow_option_by_name(libObjPtr, name); |
| 2105 | } |
| 2106 | }; |
| 2107 | |
| 2108 | /* Functions specific to constant variant field classes */ |
| 2109 | template <> |
| 2110 | struct CommonVariantFieldClassSpec<const bt_field_class> final |
| 2111 | { |
| 2112 | static const bt_field_class_variant_option * |
| 2113 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2114 | { |
| 2115 | return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index); |
| 2116 | } |
| 2117 | |
| 2118 | static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr, |
| 2119 | const char * const name) noexcept |
| 2120 | { |
| 2121 | return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name); |
| 2122 | } |
| 2123 | }; |
| 2124 | |
| 2125 | } /* namespace internal */ |
| 2126 | |
| 2127 | template <typename LibObjT> |
| 2128 | class CommonVariantFieldClass : public CommonFieldClass<LibObjT> |
| 2129 | { |
| 2130 | private: |
| 2131 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 2132 | |
| 2133 | protected: |
| 2134 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 2135 | using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>; |
| 2136 | |
| 2137 | public: |
| 2138 | using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>; |
| 2139 | using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>; |
| 2140 | |
| 2141 | using Option = |
| 2142 | internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>; |
| 2143 | |
| 2144 | explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 2145 | _ThisCommonFieldClass {libObjPtr} |
| 2146 | { |
| 2147 | BT_ASSERT_DBG(this->isVariant()); |
| 2148 | } |
| 2149 | |
| 2150 | template <typename OtherLibObjT> |
| 2151 | CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept : |
| 2152 | _ThisCommonFieldClass {fc} |
| 2153 | { |
| 2154 | } |
| 2155 | |
| 2156 | template <typename OtherLibObjT> |
| 2157 | CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept |
| 2158 | { |
| 2159 | _ThisCommonFieldClass::operator=(fc); |
| 2160 | return *this; |
| 2161 | } |
| 2162 | |
| 2163 | CommonVariantFieldClass<const bt_field_class> asConst() const noexcept |
| 2164 | { |
| 2165 | return CommonVariantFieldClass<const bt_field_class> {*this}; |
| 2166 | } |
| 2167 | |
| 2168 | std::uint64_t length() const noexcept |
| 2169 | { |
| 2170 | return bt_field_class_variant_get_option_count(this->libObjPtr()); |
| 2171 | } |
| 2172 | |
| 2173 | Iterator begin() const noexcept |
| 2174 | { |
| 2175 | return Iterator {*this, 0}; |
| 2176 | } |
| 2177 | |
| 2178 | Iterator end() const noexcept |
| 2179 | { |
| 2180 | return Iterator {*this, this->length()}; |
| 2181 | } |
| 2182 | |
| 2183 | Option operator[](const std::uint64_t index) const noexcept |
| 2184 | { |
| 2185 | return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex( |
| 2186 | this->libObjPtr(), index)}; |
| 2187 | } |
| 2188 | |
| 2189 | bt2s::optional<Option> operator[](const char * const name) const noexcept |
| 2190 | { |
| 2191 | const auto libObjPtr = |
| 2192 | internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name); |
| 2193 | |
| 2194 | if (libObjPtr) { |
| 2195 | return Option {libObjPtr}; |
| 2196 | } |
| 2197 | |
| 2198 | return bt2s::nullopt; |
| 2199 | } |
| 2200 | |
| 2201 | bt2s::optional<Option> operator[](const std::string& name) const noexcept |
| 2202 | { |
| 2203 | return (*this)[name.data()]; |
| 2204 | } |
| 2205 | |
| 2206 | Shared shared() const noexcept |
| 2207 | { |
| 2208 | return Shared::createWithRef(*this); |
| 2209 | } |
| 2210 | }; |
| 2211 | |
| 2212 | using VariantFieldClass = CommonVariantFieldClass<bt_field_class>; |
| 2213 | using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>; |
| 2214 | |
| 2215 | namespace internal { |
| 2216 | |
| 2217 | struct VariantFieldClassTypeDescr |
| 2218 | { |
| 2219 | using Const = ConstVariantFieldClass; |
| 2220 | using NonConst = VariantFieldClass; |
| 2221 | }; |
| 2222 | |
| 2223 | template <> |
| 2224 | struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr |
| 2225 | { |
| 2226 | }; |
| 2227 | |
| 2228 | template <> |
| 2229 | struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr |
| 2230 | { |
| 2231 | }; |
| 2232 | |
| 2233 | } /* namespace internal */ |
| 2234 | |
| 2235 | template <typename LibObjT> |
| 2236 | class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT> |
| 2237 | { |
| 2238 | private: |
| 2239 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; |
| 2240 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 2241 | |
| 2242 | public: |
| 2243 | using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>; |
| 2244 | |
| 2245 | explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 2246 | _ThisCommonVariantFieldClass {libObjPtr} |
| 2247 | { |
| 2248 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); |
| 2249 | } |
| 2250 | |
| 2251 | template <typename OtherLibObjT> |
| 2252 | CommonVariantWithoutSelectorFieldClass( |
| 2253 | const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 2254 | _ThisCommonVariantFieldClass {fc} |
| 2255 | { |
| 2256 | } |
| 2257 | |
| 2258 | template <typename OtherLibObjT> |
| 2259 | CommonVariantWithoutSelectorFieldClass |
| 2260 | operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 2261 | { |
| 2262 | _ThisCommonVariantFieldClass::operator=(fc); |
| 2263 | return *this; |
| 2264 | } |
| 2265 | |
| 2266 | CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 2267 | { |
| 2268 | return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this}; |
| 2269 | } |
| 2270 | |
| 2271 | void appendOption(const char * const name, const FieldClass fc) const |
| 2272 | { |
| 2273 | static_assert(!std::is_const<LibObjT>::value, |
| 2274 | "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`."); |
| 2275 | |
| 2276 | const auto status = bt_field_class_variant_without_selector_append_option( |
| 2277 | this->libObjPtr(), name, fc.libObjPtr()); |
| 2278 | |
| 2279 | if (status == |
| 2280 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { |
| 2281 | throw MemoryError {}; |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc) const |
| 2286 | { |
| 2287 | this->appendOption(name ? name->data() : nullptr, fc); |
| 2288 | } |
| 2289 | |
| 2290 | Shared shared() const noexcept |
| 2291 | { |
| 2292 | return Shared::createWithRef(*this); |
| 2293 | } |
| 2294 | }; |
| 2295 | |
| 2296 | using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>; |
| 2297 | using ConstVariantWithoutSelectorFieldClass = |
| 2298 | CommonVariantWithoutSelectorFieldClass<const bt_field_class>; |
| 2299 | |
| 2300 | namespace internal { |
| 2301 | |
| 2302 | struct VariantWithoutSelectorFieldClassTypeDescr |
| 2303 | { |
| 2304 | using Const = ConstVariantWithoutSelectorFieldClass; |
| 2305 | using NonConst = VariantWithoutSelectorFieldClass; |
| 2306 | }; |
| 2307 | |
| 2308 | template <> |
| 2309 | struct TypeDescr<VariantWithoutSelectorFieldClass> : |
| 2310 | public VariantWithoutSelectorFieldClassTypeDescr |
| 2311 | { |
| 2312 | }; |
| 2313 | |
| 2314 | template <> |
| 2315 | struct TypeDescr<ConstVariantWithoutSelectorFieldClass> : |
| 2316 | public VariantWithoutSelectorFieldClassTypeDescr |
| 2317 | { |
| 2318 | }; |
| 2319 | |
| 2320 | template <typename OptionT> |
| 2321 | struct CommonVariantWithIntegerSelectorFieldClassSpec; |
| 2322 | |
| 2323 | /* Functions specific to variant field classes with unsigned integer selector */ |
| 2324 | template <> |
| 2325 | struct CommonVariantWithIntegerSelectorFieldClassSpec< |
| 2326 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> |
| 2327 | final |
| 2328 | { |
| 2329 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * |
| 2330 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2331 | { |
| 2332 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( |
| 2333 | libObjPtr, index); |
| 2334 | } |
| 2335 | |
| 2336 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * |
| 2337 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 2338 | { |
| 2339 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( |
| 2340 | libObjPtr, name); |
| 2341 | } |
| 2342 | |
| 2343 | static bt_field_class_variant_with_selector_field_integer_append_option_status |
| 2344 | appendOption(bt_field_class * const libObjPtr, const char * const name, |
| 2345 | bt_field_class * const libOptFcPtr, |
| 2346 | const bt_integer_range_set_unsigned * const libRangesPtr) |
| 2347 | { |
| 2348 | return bt_field_class_variant_with_selector_field_integer_unsigned_append_option( |
| 2349 | libObjPtr, name, libOptFcPtr, libRangesPtr); |
| 2350 | } |
| 2351 | }; |
| 2352 | |
| 2353 | /* Functions specific to variant field classes with signed integer selector */ |
| 2354 | template <> |
| 2355 | struct CommonVariantWithIntegerSelectorFieldClassSpec< |
| 2356 | ConstVariantWithSignedIntegerSelectorFieldClassOption> |
| 2357 | final |
| 2358 | { |
| 2359 | static const bt_field_class_variant_with_selector_field_integer_signed_option * |
| 2360 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2361 | { |
| 2362 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( |
| 2363 | libObjPtr, index); |
| 2364 | } |
| 2365 | |
| 2366 | static const bt_field_class_variant_with_selector_field_integer_signed_option * |
| 2367 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 2368 | { |
| 2369 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( |
| 2370 | libObjPtr, name); |
| 2371 | } |
| 2372 | |
| 2373 | static bt_field_class_variant_with_selector_field_integer_append_option_status |
| 2374 | appendOption(bt_field_class * const libObjPtr, const char * const name, |
| 2375 | bt_field_class * const libOptFcPtr, |
| 2376 | const bt_integer_range_set_signed * const libRangesPtr) |
| 2377 | { |
| 2378 | return bt_field_class_variant_with_selector_field_integer_signed_append_option( |
| 2379 | libObjPtr, name, libOptFcPtr, libRangesPtr); |
| 2380 | } |
| 2381 | }; |
| 2382 | |
| 2383 | } /* namespace internal */ |
| 2384 | |
| 2385 | template <typename LibObjT> |
| 2386 | class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT> |
| 2387 | { |
| 2388 | private: |
| 2389 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; |
| 2390 | |
| 2391 | protected: |
| 2392 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 2393 | using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>; |
| 2394 | |
| 2395 | public: |
| 2396 | using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>; |
| 2397 | |
| 2398 | explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 2399 | _ThisCommonVariantFieldClass {libObjPtr} |
| 2400 | { |
| 2401 | BT_ASSERT_DBG(this->isVariantWithSelector()); |
| 2402 | } |
| 2403 | |
| 2404 | template <typename OtherLibObjT> |
| 2405 | CommonVariantWithSelectorFieldClass( |
| 2406 | const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 2407 | _ThisCommonVariantFieldClass {fc} |
| 2408 | { |
| 2409 | } |
| 2410 | |
| 2411 | template <typename OtherLibObjT> |
| 2412 | CommonVariantWithSelectorFieldClass |
| 2413 | operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 2414 | { |
| 2415 | _ThisCommonVariantFieldClass::operator=(fc); |
| 2416 | return *this; |
| 2417 | } |
| 2418 | |
| 2419 | CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 2420 | { |
| 2421 | return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this}; |
| 2422 | } |
| 2423 | |
| 2424 | ConstFieldPath selectorFieldPath() const noexcept |
| 2425 | { |
| 2426 | return ConstFieldPath { |
| 2427 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( |
| 2428 | this->libObjPtr())}; |
| 2429 | } |
| 2430 | |
| 2431 | Shared shared() const noexcept |
| 2432 | { |
| 2433 | return Shared::createWithRef(*this); |
| 2434 | } |
| 2435 | }; |
| 2436 | |
| 2437 | using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>; |
| 2438 | using ConstVariantWithSelectorFieldClass = |
| 2439 | CommonVariantWithSelectorFieldClass<const bt_field_class>; |
| 2440 | |
| 2441 | template <typename LibObjT, typename OptionT> |
| 2442 | class CommonVariantWithIntegerSelectorFieldClass : |
| 2443 | public CommonVariantWithSelectorFieldClass<LibObjT> |
| 2444 | { |
| 2445 | private: |
| 2446 | using typename CommonVariantWithSelectorFieldClass< |
| 2447 | LibObjT>::_ThisCommonVariantWithSelectorFieldClass; |
| 2448 | using typename CommonFieldClass<LibObjT>::_LibObjPtr; |
| 2449 | |
| 2450 | using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>; |
| 2451 | |
| 2452 | public: |
| 2453 | using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>; |
| 2454 | using Option = OptionT; |
| 2455 | |
| 2456 | using Iterator = |
| 2457 | BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>; |
| 2458 | |
| 2459 | explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept : |
| 2460 | _ThisCommonVariantWithSelectorFieldClass {libObjPtr} |
| 2461 | { |
| 2462 | BT_ASSERT_DBG(this->isVariant()); |
| 2463 | } |
| 2464 | |
| 2465 | template <typename OtherLibObjT> |
| 2466 | CommonVariantWithIntegerSelectorFieldClass( |
| 2467 | const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept : |
| 2468 | _ThisCommonVariantWithSelectorFieldClass {fc} |
| 2469 | { |
| 2470 | } |
| 2471 | |
| 2472 | template <typename OtherLibObjT> |
| 2473 | CommonVariantWithIntegerSelectorFieldClass |
| 2474 | operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept |
| 2475 | { |
| 2476 | _ThisCommonVariantWithSelectorFieldClass::operator=(fc); |
| 2477 | return *this; |
| 2478 | } |
| 2479 | |
| 2480 | Option operator[](const std::uint64_t index) const noexcept |
| 2481 | { |
| 2482 | return Option {_Spec::optionByIndex(this->libObjPtr(), index)}; |
| 2483 | } |
| 2484 | |
| 2485 | bt2s::optional<Option> operator[](const char * const name) const noexcept |
| 2486 | { |
| 2487 | const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name); |
| 2488 | |
| 2489 | if (libObjPtr) { |
| 2490 | return Option {libObjPtr}; |
| 2491 | } |
| 2492 | |
| 2493 | return bt2s::nullopt; |
| 2494 | } |
| 2495 | |
| 2496 | bt2s::optional<Option> operator[](const std::string& name) const noexcept |
| 2497 | { |
| 2498 | return (*this)[name.data()]; |
| 2499 | } |
| 2500 | |
| 2501 | void appendOption(const char * const name, const FieldClass fc, |
| 2502 | const typename Option::RangeSet ranges) const |
| 2503 | { |
| 2504 | static_assert( |
| 2505 | !std::is_const<LibObjT>::value, |
| 2506 | "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`."); |
| 2507 | |
| 2508 | const auto status = |
| 2509 | _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr()); |
| 2510 | |
| 2511 | if (status == |
| 2512 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { |
| 2513 | throw MemoryError {}; |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc, |
| 2518 | const typename Option::RangeSet ranges) const |
| 2519 | { |
| 2520 | this->appendOption(name ? name->data() : nullptr, fc, ranges); |
| 2521 | } |
| 2522 | |
| 2523 | Iterator begin() const noexcept |
| 2524 | { |
| 2525 | return Iterator {*this, 0}; |
| 2526 | } |
| 2527 | |
| 2528 | Iterator end() const noexcept |
| 2529 | { |
| 2530 | return Iterator {*this, this->length()}; |
| 2531 | } |
| 2532 | |
| 2533 | Shared shared() const noexcept |
| 2534 | { |
| 2535 | return Shared::createWithRef(*this); |
| 2536 | } |
| 2537 | }; |
| 2538 | |
| 2539 | using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2540 | bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; |
| 2541 | |
| 2542 | using ConstVariantWithUnsignedIntegerSelectorFieldClass = |
| 2543 | CommonVariantWithIntegerSelectorFieldClass< |
| 2544 | const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; |
| 2545 | |
| 2546 | using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2547 | bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; |
| 2548 | |
| 2549 | using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2550 | const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; |
| 2551 | |
| 2552 | namespace internal { |
| 2553 | |
| 2554 | struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2555 | { |
| 2556 | using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass; |
| 2557 | using NonConst = VariantWithUnsignedIntegerSelectorFieldClass; |
| 2558 | }; |
| 2559 | |
| 2560 | template <> |
| 2561 | struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> : |
| 2562 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2563 | { |
| 2564 | }; |
| 2565 | |
| 2566 | template <> |
| 2567 | struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> : |
| 2568 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2569 | { |
| 2570 | }; |
| 2571 | |
| 2572 | struct VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2573 | { |
| 2574 | using Const = ConstVariantWithSignedIntegerSelectorFieldClass; |
| 2575 | using NonConst = VariantWithSignedIntegerSelectorFieldClass; |
| 2576 | }; |
| 2577 | |
| 2578 | template <> |
| 2579 | struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> : |
| 2580 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2581 | { |
| 2582 | }; |
| 2583 | |
| 2584 | template <> |
| 2585 | struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> : |
| 2586 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2587 | { |
| 2588 | }; |
| 2589 | |
| 2590 | } /* namespace internal */ |
| 2591 | |
| 2592 | template <typename LibObjT> |
| 2593 | CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept |
| 2594 | { |
| 2595 | BT_ASSERT_DBG(this->isBitArray()); |
| 2596 | return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2597 | } |
| 2598 | |
| 2599 | template <typename LibObjT> |
| 2600 | CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept |
| 2601 | { |
| 2602 | BT_ASSERT_DBG(this->isInteger()); |
| 2603 | return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()}; |
| 2604 | } |
| 2605 | |
| 2606 | template <typename LibObjT> |
| 2607 | CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept |
| 2608 | { |
| 2609 | BT_ASSERT_DBG(this->isEnumeration()); |
| 2610 | return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()}; |
| 2611 | } |
| 2612 | |
| 2613 | template <typename LibObjT> |
| 2614 | CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> |
| 2615 | CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept |
| 2616 | { |
| 2617 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); |
| 2618 | return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> { |
| 2619 | this->libObjPtr()}; |
| 2620 | } |
| 2621 | |
| 2622 | template <typename LibObjT> |
| 2623 | CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> |
| 2624 | CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept |
| 2625 | { |
| 2626 | BT_ASSERT_DBG(this->isSignedEnumeration()); |
| 2627 | return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> { |
| 2628 | this->libObjPtr()}; |
| 2629 | } |
| 2630 | |
| 2631 | template <typename LibObjT> |
| 2632 | CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept |
| 2633 | { |
| 2634 | BT_ASSERT_DBG(this->isStructure()); |
| 2635 | return CommonStructureFieldClass<LibObjT> {this->libObjPtr()}; |
| 2636 | } |
| 2637 | |
| 2638 | template <typename LibObjT> |
| 2639 | CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept |
| 2640 | { |
| 2641 | BT_ASSERT_DBG(this->isArray()); |
| 2642 | return CommonArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2643 | } |
| 2644 | |
| 2645 | template <typename LibObjT> |
| 2646 | CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept |
| 2647 | { |
| 2648 | BT_ASSERT_DBG(this->isStaticArray()); |
| 2649 | return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2650 | } |
| 2651 | |
| 2652 | template <typename LibObjT> |
| 2653 | CommonDynamicArrayWithLengthFieldClass<LibObjT> |
| 2654 | CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept |
| 2655 | { |
| 2656 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); |
| 2657 | return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()}; |
| 2658 | } |
| 2659 | |
| 2660 | template <typename LibObjT> |
| 2661 | CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept |
| 2662 | { |
| 2663 | BT_ASSERT_DBG(this->isOption()); |
| 2664 | return CommonOptionFieldClass<LibObjT> {this->libObjPtr()}; |
| 2665 | } |
| 2666 | |
| 2667 | template <typename LibObjT> |
| 2668 | CommonOptionWithSelectorFieldClass<LibObjT> |
| 2669 | CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept |
| 2670 | { |
| 2671 | BT_ASSERT_DBG(this->isOptionWithSelector()); |
| 2672 | return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2673 | } |
| 2674 | |
| 2675 | template <typename LibObjT> |
| 2676 | CommonOptionWithBoolSelectorFieldClass<LibObjT> |
| 2677 | CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept |
| 2678 | { |
| 2679 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); |
| 2680 | return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2681 | } |
| 2682 | |
| 2683 | template <typename LibObjT> |
| 2684 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> |
| 2685 | CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept |
| 2686 | { |
| 2687 | BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector()); |
| 2688 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> { |
| 2689 | this->libObjPtr()}; |
| 2690 | } |
| 2691 | |
| 2692 | template <typename LibObjT> |
| 2693 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> |
| 2694 | CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept |
| 2695 | { |
| 2696 | BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector()); |
| 2697 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> { |
| 2698 | this->libObjPtr()}; |
| 2699 | } |
| 2700 | |
| 2701 | template <typename LibObjT> |
| 2702 | CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept |
| 2703 | { |
| 2704 | BT_ASSERT_DBG(this->isVariant()); |
| 2705 | return CommonVariantFieldClass<LibObjT> {this->libObjPtr()}; |
| 2706 | } |
| 2707 | |
| 2708 | template <typename LibObjT> |
| 2709 | CommonVariantWithoutSelectorFieldClass<LibObjT> |
| 2710 | CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept |
| 2711 | { |
| 2712 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); |
| 2713 | return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2714 | } |
| 2715 | |
| 2716 | template <typename LibObjT> |
| 2717 | CommonVariantWithSelectorFieldClass<LibObjT> |
| 2718 | CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept |
| 2719 | { |
| 2720 | BT_ASSERT_DBG(this->isVariantWithSelector()); |
| 2721 | return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2722 | } |
| 2723 | |
| 2724 | template <typename LibObjT> |
| 2725 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
| 2726 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> |
| 2727 | CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept |
| 2728 | { |
| 2729 | BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector()); |
| 2730 | return CommonVariantWithIntegerSelectorFieldClass< |
| 2731 | LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
| 2732 | } |
| 2733 | |
| 2734 | template <typename LibObjT> |
| 2735 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
| 2736 | ConstVariantWithSignedIntegerSelectorFieldClassOption> |
| 2737 | CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept |
| 2738 | { |
| 2739 | BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector()); |
| 2740 | return CommonVariantWithIntegerSelectorFieldClass< |
| 2741 | LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
| 2742 | } |
| 2743 | |
| 2744 | } /* namespace bt2 */ |
| 2745 | |
| 2746 | #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */ |