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